From: noah morrison Date: Sat, 22 Nov 2014 18:49:27 +0000 (-0500) Subject: Renamed chevron.py to main.py X-Git-Url: https://git.devinivas.org/?a=commitdiff_plain;h=eb1f041ff382a55359d24342cfac583122ac3922;p=chevron.git Renamed chevron.py to main.py and updated the chevron/__init__.py --- diff --git a/chevron/__init__.py b/chevron/__init__.py index 5ac41ff..14c6ea8 100644 --- a/chevron/__init__.py +++ b/chevron/__init__.py @@ -1,3 +1,5 @@ -from .chevron import main, render, UnclosedSection, cli_main +from .main import main, cli_main +from .renderer import render +from .tokenizer import UnclosedSection __all__ = ['main', 'render', 'UnclosedSection', 'cli_main'] diff --git a/chevron/chevron.py b/chevron/chevron.py deleted file mode 100755 index 3862334..0000000 --- a/chevron/chevron.py +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/python - -import json - -from sys import argv - -from chevron.tokenizer import tokenize -from chevron.renderer import render - - -def main(template, data={}, **kwargs): - with open(template, 'r') as template_file: - if data != {}: - data_file = open(data, 'r') - data = json.load(data_file) - data_file.close() - - args = { - 'template': template_file, - 'data': data - } - - args.update(kwargs) - return render(**args) - - -def cli_main(): - """Render mustache templates using json files""" - import argparse - import os - - def is_file(arg): - if not os.path.isfile(arg): - parser.error('The file {0} does not exist!'.format(arg)) - else: - return arg - - def is_dir(arg): - if not os.path.isdir(arg): - parser.error('The directory {0} does not exist!'.format(arg)) - else: - return arg - - parser = argparse.ArgumentParser(description=__doc__) - - parser.add_argument('template', help='The mustache file', - type=is_file) - - parser.add_argument('-d', '--data', dest='data', - help='The json data file', - type=is_file, default={}) - - parser.add_argument('-p', '--path', dest='partials_path', - help='The directory where your partials reside', - type=is_dir, default='.') - - parser.add_argument('-e', '--ext', dest='partials_ext', - help='The extension for your mustache\ - partials, \'mustache\' by default', - default='mustache') - - parser.add_argument('-l', '--left-delimiter', dest='def_ldel', - help='The default left delimiter, "{{" by default.', - default='{{') - - parser.add_argument('-r', '--right-delimiter', dest='def_rdel', - help='The default right delimiter, "}}" by default.', - default='}}') - - args = vars(parser.parse_args()) - - print(main(**args)) - -if __name__ == '__main__': - cli_main() diff --git a/chevron/main.py b/chevron/main.py new file mode 100755 index 0000000..3862334 --- /dev/null +++ b/chevron/main.py @@ -0,0 +1,75 @@ +#!/usr/bin/python + +import json + +from sys import argv + +from chevron.tokenizer import tokenize +from chevron.renderer import render + + +def main(template, data={}, **kwargs): + with open(template, 'r') as template_file: + if data != {}: + data_file = open(data, 'r') + data = json.load(data_file) + data_file.close() + + args = { + 'template': template_file, + 'data': data + } + + args.update(kwargs) + return render(**args) + + +def cli_main(): + """Render mustache templates using json files""" + import argparse + import os + + def is_file(arg): + if not os.path.isfile(arg): + parser.error('The file {0} does not exist!'.format(arg)) + else: + return arg + + def is_dir(arg): + if not os.path.isdir(arg): + parser.error('The directory {0} does not exist!'.format(arg)) + else: + return arg + + parser = argparse.ArgumentParser(description=__doc__) + + parser.add_argument('template', help='The mustache file', + type=is_file) + + parser.add_argument('-d', '--data', dest='data', + help='The json data file', + type=is_file, default={}) + + parser.add_argument('-p', '--path', dest='partials_path', + help='The directory where your partials reside', + type=is_dir, default='.') + + parser.add_argument('-e', '--ext', dest='partials_ext', + help='The extension for your mustache\ + partials, \'mustache\' by default', + default='mustache') + + parser.add_argument('-l', '--left-delimiter', dest='def_ldel', + help='The default left delimiter, "{{" by default.', + default='{{') + + parser.add_argument('-r', '--right-delimiter', dest='def_rdel', + help='The default right delimiter, "}}" by default.', + default='}}') + + args = vars(parser.parse_args()) + + print(main(**args)) + +if __name__ == '__main__': + cli_main()