We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Jinja breaks on syntax error without reporting where the error occured
I tried to create a project from [here](https://github.com/thedrow/cookiecutter-pypackage/) and I got the following traceback:

```
cookiecutter https://github.com/thedrow/cookiecutter-pypackage.git
You've cloned cookiecutter-pypackage before. Is it okay to delete and re-clone it? [Y/n] y
Cloning into 'cookiecutter-pypackage'...
remote: Counting objects: 249, done.
remote: Compressing objects: 100% (131/131), done.
remote: Total 249 (delta 108), reused 230 (delta 96)
Receiving objects: 100% (249/249), 39.41 KiB, done.
Resolving deltas: 100% (108/108), done.
full_name (default is "Omer Katz")? 
email (default is "omer.drow@gmail.com")? 
github_username (default is "thedrow")? testsuite
project_name (default is "Python Boilerplate")? testsuite
repo_name (default is "boilerplate")? testsuite
project_short_description (default is "Python Boilerplate contains all the boilerplate you need to create a Python package.")? Testsuite is a set of plugins & extensions to nose2 that aims to assist you to write better tests.
release_date (default is "2013-08-25")? 
year (default is "2013")? 
version (default is "0.1.0")? 
Traceback (most recent call last):
  File "/usr/local/bin/cookiecutter", line 9, in <module>
    load_entry_point('cookiecutter==0.6.4', 'console_scripts', 'cookiecutter')()
  File "/usr/local/lib/python3.3/dist-packages/cookiecutter/main.py", line 90, in main
    cookiecutter(args.input_dir)
  File "/usr/local/lib/python3.3/dist-packages/cookiecutter/main.py", line 61, in cookiecutter
    context=context
  File "/usr/local/lib/python3.3/dist-packages/cookiecutter/generate.py", line 135, in generate_files
    generate_file(infile, context, env)
  File "/usr/local/lib/python3.3/dist-packages/cookiecutter/generate.py", line 85, in generate_file
    tmpl = env.get_template(infile_fwd_slashes)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 791, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 765, in _load_template
    template = self.loader.load(self, name, globals)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/loaders.py", line 125, in load
    code = environment.compile(source, name, filename)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 554, in compile
    self.handle_exception(exc_info, source_hint=source)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/_compat.py", line 36, in reraise
    raise value.with_traceback(tb)
  File "./cookiecutter-pypackage/{{cookiecutter.repo_name}}/LICENSE", line 13, in <module>
    * Neither the name of {{ cookiecutter.project_name } nor the names of its contributors
  File "/usr/local/lib/python3.3/dist-packages/jinja2/environment.py", line 459, in _parse
    return Parser(self, source, name, encode_filename(filename)).parse()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 893, in parse
    result = nodes.Template(self.subparse(), lineno=1)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 867, in subparse
    add_data(self.parse_tuple(with_condexpr=True))
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 612, in parse_tuple
    args.append(parse())
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 386, in parse_expression
    return self.parse_condexpr()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 391, in parse_condexpr
    expr1 = self.parse_or()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 404, in parse_or
    left = self.parse_and()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 413, in parse_and
    left = self.parse_not()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 424, in parse_not
    return self.parse_compare()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 428, in parse_compare
    expr = self.parse_add()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 450, in parse_add
    left = self.parse_sub()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 460, in parse_sub
    left = self.parse_concat()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 470, in parse_concat
    args = [self.parse_mul()]
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 480, in parse_mul
    left = self.parse_div()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 490, in parse_div
    left = self.parse_floordiv()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 500, in parse_floordiv
    left = self.parse_mod()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 510, in parse_mod
    left = self.parse_pow()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 520, in parse_pow
    left = self.parse_unary()
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 539, in parse_unary
    node = self.parse_postfix(node)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 664, in parse_postfix
    node = self.parse_subscript(node)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/parser.py", line 692, in parse_subscript
    next(self.stream)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py", line 349, in __next__
    self.current = next(self._iter)
  File "/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py", line 552, in wrap
    for lineno, token, value in stream:
  File "/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py", line 677, in tokeniter
    filename)
jinja2.exceptions.TemplateSyntaxError: unexpected '}'
```

I'm using Python 3.3 on Ubuntu 13.04.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `cookiecutter/generate.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 
4 """
5 cookiecutter.generate
6 ---------------------
7 
8 Functions for generating a project from a project template.
9 """
10 from __future__ import unicode_literals
11 import logging
12 import os
13 import shutil
14 import sys
15 
16 from jinja2 import FileSystemLoader, Template
17 from jinja2.environment import Environment
18 from binaryornot.check import is_binary
19 
20 from .exceptions import NonTemplatedInputDirException
21 from .utils import make_sure_path_exists, unicode_open
22 
23 
24 if sys.version_info[:2] < (2, 7):
25     import simplejson as json
26     from ordereddict import OrderedDict
27 else:
28     import json
29     from collections import OrderedDict
30 
31 
32 def generate_context(config_file='cookiecutter.json'):
33     """
34     Generates the context for a Cookiecutter project template.
35     Loads the JSON file as a Python object, with key being the JSON filename.
36 
37     :param config_file: JSON file containing project config values.
38     :paramtype config_file: filename
39     """
40 
41     context = {}
42 
43     file_handle = open(config_file)
44     obj = json.load(file_handle, encoding='utf-8', object_pairs_hook=OrderedDict)
45 
46     # Add the Python object to the context dictionary
47     file_name = os.path.split(config_file)[1]
48     file_stem = file_name.split('.')[0]
49     context[file_stem] = obj
50 
51     logging.debug('Context generated is {0}'.format(context))
52     return context
53 
54 
55 def generate_file(infile, context, env):
56     """
57     1. Render the contents of infile.
58     2. Render the filename of infile as the name of outfile.
59     3. Write the rendered infile to outfile.
60     :param infile: Input file to generate the file from.
61     """
62     logging.debug("Generating file {0}".format(infile))
63 
64     # Render the path to the output file (but don't include the filename)
65     outdir_tmpl = Template(os.path.dirname(os.path.abspath(infile)))
66     outdir = outdir_tmpl.render(**context)
67     fname = os.path.basename(os.path.abspath(infile))  # input/output filename
68     # Write it to the corresponding place in output_dir
69     outfile = os.path.join(outdir, fname)
70     logging.debug("outfile is {0}".format(outfile))
71 
72     # Just copy over binary files. Don't render.
73     logging.debug("Check {0} to see if it's a binary".format(infile))
74     if is_binary(infile):
75         logging.debug("Copying binary {0} to {1} without rendering"
76                       .format(infile, outfile))
77         shutil.copyfile(infile, outfile)
78 
79     else:
80         # Force fwd slashes on Windows for get_template
81         # This is a by-design Jinja issue
82         infile_fwd_slashes = infile.replace(os.path.sep, '/')
83 
84         # Render the file
85         tmpl = env.get_template(infile_fwd_slashes)
86         rendered_file = tmpl.render(**context)
87 
88         # Render the output filename before writing
89         name_tmpl = Template(outfile)
90         rendered_name = name_tmpl.render(**context)
91         logging.debug("Writing {0}".format(rendered_name))
92 
93         with unicode_open(rendered_name, 'w') as fh:
94             fh.write(rendered_file)
95 
96 def generate_files(template_dir, context=None):
97     """
98     Renders the templates and saves them to files.
99     :param input_dir: Project template input directory.
100     :paramtype input_dir: directory
101     """
102 
103     # Always use utf-8
104     template_dir = template_dir
105 
106     logging.debug('Generating project from {0}...'.format(template_dir))
107 
108     context = context or {}
109     env = Environment()
110     env.loader = FileSystemLoader('.')
111 
112     # Render dirname before writing
113     name_tmpl = Template(template_dir)
114     output_dir = name_tmpl.render(**context)
115     if output_dir == template_dir:
116         raise NonTemplatedInputDirException
117 
118     logging.debug("output_dir is {0}".format(output_dir))
119     make_sure_path_exists(output_dir)
120 
121     for root, dirs, files in os.walk(template_dir):
122         for d in dirs:
123             indir = os.path.join(root, d)
124             outdir = indir.replace(template_dir, output_dir, 1)
125 
126             # Render dirname before writing
127             name_tmpl = Template(outdir)
128             rendered_dirname = name_tmpl.render(**context)
129 
130             make_sure_path_exists(rendered_dirname)
131 
132         for f in files:
133             logging.debug("f is {0}".format(f))
134             infile = os.path.join(root, f)
135             generate_file(infile, context, env)
136
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/cookiecutter/generate.py b/cookiecutter/generate.py
--- a/cookiecutter/generate.py
+++ b/cookiecutter/generate.py
@@ -15,6 +15,7 @@
 
 from jinja2 import FileSystemLoader, Template
 from jinja2.environment import Environment
+from jinja2.exceptions import TemplateSyntaxError
 from binaryornot.check import is_binary
 
 from .exceptions import NonTemplatedInputDirException
@@ -82,7 +83,13 @@
         infile_fwd_slashes = infile.replace(os.path.sep, '/')
 
         # Render the file
-        tmpl = env.get_template(infile_fwd_slashes)
+        try:
+            tmpl = env.get_template(infile_fwd_slashes)
+        except TemplateSyntaxError as exception:
+            # Disable translated so that printed exception contains verbose
+            # information about syntax error location
+            exception.translated = False
+            raise
         rendered_file = tmpl.render(**context)
 
         # Render the output filename before writing

{"golden_diff": "diff --git a/cookiecutter/generate.py b/cookiecutter/generate.py\n--- a/cookiecutter/generate.py\n+++ b/cookiecutter/generate.py\n@@ -15,6 +15,7 @@\n \n from jinja2 import FileSystemLoader, Template\n from jinja2.environment import Environment\n+from jinja2.exceptions import TemplateSyntaxError\n from binaryornot.check import is_binary\n \n from .exceptions import NonTemplatedInputDirException\n@@ -82,7 +83,13 @@\n         infile_fwd_slashes = infile.replace(os.path.sep, '/')\n \n         # Render the file\n-        tmpl = env.get_template(infile_fwd_slashes)\n+        try:\n+            tmpl = env.get_template(infile_fwd_slashes)\n+        except TemplateSyntaxError as exception:\n+            # Disable translated so that printed exception contains verbose\n+            # information about syntax error location\n+            exception.translated = False\n+            raise\n         rendered_file = tmpl.render(**context)\n \n         # Render the output filename before writing\n", "issue": "Jinja breaks on syntax error without reporting where the error occured\nI tried to create a project from [here](https://github.com/thedrow/cookiecutter-pypackage/) and I got the following traceback:\n\n```\ncookiecutter https://github.com/thedrow/cookiecutter-pypackage.git\nYou've cloned cookiecutter-pypackage before. Is it okay to delete and re-clone it? [Y/n] y\nCloning into 'cookiecutter-pypackage'...\nremote: Counting objects: 249, done.\nremote: Compressing objects: 100% (131/131), done.\nremote: Total 249 (delta 108), reused 230 (delta 96)\nReceiving objects: 100% (249/249), 39.41 KiB, done.\nResolving deltas: 100% (108/108), done.\nfull_name (default is \"Omer Katz\")? \nemail (default is \"omer.drow@gmail.com\")? \ngithub_username (default is \"thedrow\")? testsuite\nproject_name (default is \"Python Boilerplate\")? testsuite\nrepo_name (default is \"boilerplate\")? testsuite\nproject_short_description (default is \"Python Boilerplate contains all the boilerplate you need to create a Python package.\")? Testsuite is a set of plugins & extensions to nose2 that aims to assist you to write better tests.\nrelease_date (default is \"2013-08-25\")? \nyear (default is \"2013\")? \nversion (default is \"0.1.0\")? \nTraceback (most recent call last):\n  File \"/usr/local/bin/cookiecutter\", line 9, in <module>\n    load_entry_point('cookiecutter==0.6.4', 'console_scripts', 'cookiecutter')()\n  File \"/usr/local/lib/python3.3/dist-packages/cookiecutter/main.py\", line 90, in main\n    cookiecutter(args.input_dir)\n  File \"/usr/local/lib/python3.3/dist-packages/cookiecutter/main.py\", line 61, in cookiecutter\n    context=context\n  File \"/usr/local/lib/python3.3/dist-packages/cookiecutter/generate.py\", line 135, in generate_files\n    generate_file(infile, context, env)\n  File \"/usr/local/lib/python3.3/dist-packages/cookiecutter/generate.py\", line 85, in generate_file\n    tmpl = env.get_template(infile_fwd_slashes)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/environment.py\", line 791, in get_template\n    return self._load_template(name, self.make_globals(globals))\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/environment.py\", line 765, in _load_template\n    template = self.loader.load(self, name, globals)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/loaders.py\", line 125, in load\n    code = environment.compile(source, name, filename)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/environment.py\", line 554, in compile\n    self.handle_exception(exc_info, source_hint=source)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/environment.py\", line 742, in handle_exception\n    reraise(exc_type, exc_value, tb)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/_compat.py\", line 36, in reraise\n    raise value.with_traceback(tb)\n  File \"./cookiecutter-pypackage/{{cookiecutter.repo_name}}/LICENSE\", line 13, in <module>\n    * Neither the name of {{ cookiecutter.project_name } nor the names of its contributors\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/environment.py\", line 459, in _parse\n    return Parser(self, source, name, encode_filename(filename)).parse()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 893, in parse\n    result = nodes.Template(self.subparse(), lineno=1)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 867, in subparse\n    add_data(self.parse_tuple(with_condexpr=True))\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 612, in parse_tuple\n    args.append(parse())\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 386, in parse_expression\n    return self.parse_condexpr()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 391, in parse_condexpr\n    expr1 = self.parse_or()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 404, in parse_or\n    left = self.parse_and()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 413, in parse_and\n    left = self.parse_not()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 424, in parse_not\n    return self.parse_compare()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 428, in parse_compare\n    expr = self.parse_add()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 450, in parse_add\n    left = self.parse_sub()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 460, in parse_sub\n    left = self.parse_concat()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 470, in parse_concat\n    args = [self.parse_mul()]\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 480, in parse_mul\n    left = self.parse_div()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 490, in parse_div\n    left = self.parse_floordiv()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 500, in parse_floordiv\n    left = self.parse_mod()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 510, in parse_mod\n    left = self.parse_pow()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 520, in parse_pow\n    left = self.parse_unary()\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 539, in parse_unary\n    node = self.parse_postfix(node)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 664, in parse_postfix\n    node = self.parse_subscript(node)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/parser.py\", line 692, in parse_subscript\n    next(self.stream)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py\", line 349, in __next__\n    self.current = next(self._iter)\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py\", line 552, in wrap\n    for lineno, token, value in stream:\n  File \"/usr/local/lib/python3.3/dist-packages/jinja2/lexer.py\", line 677, in tokeniter\n    filename)\njinja2.exceptions.TemplateSyntaxError: unexpected '}'\n```\n\nI'm using Python 3.3 on Ubuntu 13.04.\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\"\"\"\ncookiecutter.generate\n---------------------\n\nFunctions for generating a project from a project template.\n\"\"\"\nfrom __future__ import unicode_literals\nimport logging\nimport os\nimport shutil\nimport sys\n\nfrom jinja2 import FileSystemLoader, Template\nfrom jinja2.environment import Environment\nfrom binaryornot.check import is_binary\n\nfrom .exceptions import NonTemplatedInputDirException\nfrom .utils import make_sure_path_exists, unicode_open\n\n\nif sys.version_info[:2] < (2, 7):\n    import simplejson as json\n    from ordereddict import OrderedDict\nelse:\n    import json\n    from collections import OrderedDict\n\n\ndef generate_context(config_file='cookiecutter.json'):\n    \"\"\"\n    Generates the context for a Cookiecutter project template.\n    Loads the JSON file as a Python object, with key being the JSON filename.\n\n    :param config_file: JSON file containing project config values.\n    :paramtype config_file: filename\n    \"\"\"\n\n    context = {}\n\n    file_handle = open(config_file)\n    obj = json.load(file_handle, encoding='utf-8', object_pairs_hook=OrderedDict)\n\n    # Add the Python object to the context dictionary\n    file_name = os.path.split(config_file)[1]\n    file_stem = file_name.split('.')[0]\n    context[file_stem] = obj\n\n    logging.debug('Context generated is {0}'.format(context))\n    return context\n\n\ndef generate_file(infile, context, env):\n    \"\"\"\n    1. Render the contents of infile.\n    2. Render the filename of infile as the name of outfile.\n    3. Write the rendered infile to outfile.\n    :param infile: Input file to generate the file from.\n    \"\"\"\n    logging.debug(\"Generating file {0}\".format(infile))\n\n    # Render the path to the output file (but don't include the filename)\n    outdir_tmpl = Template(os.path.dirname(os.path.abspath(infile)))\n    outdir = outdir_tmpl.render(**context)\n    fname = os.path.basename(os.path.abspath(infile))  # input/output filename\n    # Write it to the corresponding place in output_dir\n    outfile = os.path.join(outdir, fname)\n    logging.debug(\"outfile is {0}\".format(outfile))\n\n    # Just copy over binary files. Don't render.\n    logging.debug(\"Check {0} to see if it's a binary\".format(infile))\n    if is_binary(infile):\n        logging.debug(\"Copying binary {0} to {1} without rendering\"\n                      .format(infile, outfile))\n        shutil.copyfile(infile, outfile)\n\n    else:\n        # Force fwd slashes on Windows for get_template\n        # This is a by-design Jinja issue\n        infile_fwd_slashes = infile.replace(os.path.sep, '/')\n\n        # Render the file\n        tmpl = env.get_template(infile_fwd_slashes)\n        rendered_file = tmpl.render(**context)\n\n        # Render the output filename before writing\n        name_tmpl = Template(outfile)\n        rendered_name = name_tmpl.render(**context)\n        logging.debug(\"Writing {0}\".format(rendered_name))\n\n        with unicode_open(rendered_name, 'w') as fh:\n            fh.write(rendered_file)\n\ndef generate_files(template_dir, context=None):\n    \"\"\"\n    Renders the templates and saves them to files.\n    :param input_dir: Project template input directory.\n    :paramtype input_dir: directory\n    \"\"\"\n\n    # Always use utf-8\n    template_dir = template_dir\n\n    logging.debug('Generating project from {0}...'.format(template_dir))\n\n    context = context or {}\n    env = Environment()\n    env.loader = FileSystemLoader('.')\n\n    # Render dirname before writing\n    name_tmpl = Template(template_dir)\n    output_dir = name_tmpl.render(**context)\n    if output_dir == template_dir:\n        raise NonTemplatedInputDirException\n\n    logging.debug(\"output_dir is {0}\".format(output_dir))\n    make_sure_path_exists(output_dir)\n\n    for root, dirs, files in os.walk(template_dir):\n        for d in dirs:\n            indir = os.path.join(root, d)\n            outdir = indir.replace(template_dir, output_dir, 1)\n\n            # Render dirname before writing\n            name_tmpl = Template(outdir)\n            rendered_dirname = name_tmpl.render(**context)\n\n            make_sure_path_exists(rendered_dirname)\n\n        for f in files:\n            logging.debug(\"f is {0}\".format(f))\n            infile = os.path.join(root, f)\n            generate_file(infile, context, env)\n", "path": "cookiecutter/generate.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\n\n\"\"\"\ncookiecutter.generate\n---------------------\n\nFunctions for generating a project from a project template.\n\"\"\"\nfrom __future__ import unicode_literals\nimport logging\nimport os\nimport shutil\nimport sys\n\nfrom jinja2 import FileSystemLoader, Template\nfrom jinja2.environment import Environment\nfrom jinja2.exceptions import TemplateSyntaxError\nfrom binaryornot.check import is_binary\n\nfrom .exceptions import NonTemplatedInputDirException\nfrom .utils import make_sure_path_exists, unicode_open\n\n\nif sys.version_info[:2] < (2, 7):\n    import simplejson as json\n    from ordereddict import OrderedDict\nelse:\n    import json\n    from collections import OrderedDict\n\n\ndef generate_context(config_file='cookiecutter.json'):\n    \"\"\"\n    Generates the context for a Cookiecutter project template.\n    Loads the JSON file as a Python object, with key being the JSON filename.\n\n    :param config_file: JSON file containing project config values.\n    :paramtype config_file: filename\n    \"\"\"\n\n    context = {}\n\n    file_handle = open(config_file)\n    obj = json.load(file_handle, encoding='utf-8', object_pairs_hook=OrderedDict)\n\n    # Add the Python object to the context dictionary\n    file_name = os.path.split(config_file)[1]\n    file_stem = file_name.split('.')[0]\n    context[file_stem] = obj\n\n    logging.debug('Context generated is {0}'.format(context))\n    return context\n\n\ndef generate_file(infile, context, env):\n    \"\"\"\n    1. Render the contents of infile.\n    2. Render the filename of infile as the name of outfile.\n    3. Write the rendered infile to outfile.\n    :param infile: Input file to generate the file from.\n    \"\"\"\n    logging.debug(\"Generating file {0}\".format(infile))\n\n    # Render the path to the output file (but don't include the filename)\n    outdir_tmpl = Template(os.path.dirname(os.path.abspath(infile)))\n    outdir = outdir_tmpl.render(**context)\n    fname = os.path.basename(os.path.abspath(infile))  # input/output filename\n    # Write it to the corresponding place in output_dir\n    outfile = os.path.join(outdir, fname)\n    logging.debug(\"outfile is {0}\".format(outfile))\n\n    # Just copy over binary files. Don't render.\n    logging.debug(\"Check {0} to see if it's a binary\".format(infile))\n    if is_binary(infile):\n        logging.debug(\"Copying binary {0} to {1} without rendering\"\n                      .format(infile, outfile))\n        shutil.copyfile(infile, outfile)\n\n    else:\n        # Force fwd slashes on Windows for get_template\n        # This is a by-design Jinja issue\n        infile_fwd_slashes = infile.replace(os.path.sep, '/')\n\n        # Render the file\n        try:\n            tmpl = env.get_template(infile_fwd_slashes)\n        except TemplateSyntaxError as exception:\n            # Disable translated so that printed exception contains verbose\n            # information about syntax error location\n            exception.translated = False\n            raise\n        rendered_file = tmpl.render(**context)\n\n        # Render the output filename before writing\n        name_tmpl = Template(outfile)\n        rendered_name = name_tmpl.render(**context)\n        logging.debug(\"Writing {0}\".format(rendered_name))\n\n        with unicode_open(rendered_name, 'w') as fh:\n            fh.write(rendered_file)\n\ndef generate_files(template_dir, context=None):\n    \"\"\"\n    Renders the templates and saves them to files.\n    :param input_dir: Project template input directory.\n    :paramtype input_dir: directory\n    \"\"\"\n\n    # Always use utf-8\n    template_dir = template_dir\n\n    logging.debug('Generating project from {0}...'.format(template_dir))\n\n    context = context or {}\n    env = Environment()\n    env.loader = FileSystemLoader('.')\n\n    # Render dirname before writing\n    name_tmpl = Template(template_dir)\n    output_dir = name_tmpl.render(**context)\n    if output_dir == template_dir:\n        raise NonTemplatedInputDirException\n\n    logging.debug(\"output_dir is {0}\".format(output_dir))\n    make_sure_path_exists(output_dir)\n\n    for root, dirs, files in os.walk(template_dir):\n        for d in dirs:\n            indir = os.path.join(root, d)\n            outdir = indir.replace(template_dir, output_dir, 1)\n\n            # Render dirname before writing\n            name_tmpl = Template(outdir)\n            rendered_dirname = name_tmpl.render(**context)\n\n            make_sure_path_exists(rendered_dirname)\n\n        for f in files:\n            logging.debug(\"f is {0}\".format(f))\n            infile = os.path.join(root, f)\n            generate_file(infile, context, env)\n", "path": "cookiecutter/generate.py"}]}