Skip to content

Commit

Permalink
2375 better detection of genshi/jinja2 templates
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed May 30, 2012
1 parent ec0f081 commit 271c6a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
11 changes: 6 additions & 5 deletions ckan/lib/extract.py
Expand Up @@ -6,15 +6,16 @@ def extract_ckan(fileobj, *args, **kw):
''' Determine the type of file (Genshi or Jinja2) and then call the
correct extractor function.
Basically we just look for a jinja2 {{ or {% tag. '''
Basically we just look for genshi.edgewall.org which all genshi XML
templates should contain. '''

source = fileobj.read()
if re.search('\{\{|\{\%', source):
# jinja2
extractor_function = extract_jinja2
else:
if re.search('genshi\.edgewall\.org', source):
# genshi
extractor_function = extract_genshi
else:
# jinja2
extractor_function = extract_jinja2
# we've eaten the file so we need to get back to the start
fileobj.seek(0)
return extractor_function(fileobj, *args, **kw)
Expand Down
6 changes: 3 additions & 3 deletions ckan/lib/render.py
Expand Up @@ -20,9 +20,9 @@ def template_type(template_path):
return 'genshi-text'
f = open(template_path, 'r')
source = f.read()
if re.search('\{\{|\{\%', source):
return 'jinja2'
return 'genshi'
if re.search('genshi\.edgewall\.org', source):
return 'genshi'
return 'jinja2'

def template_info(template_name):
''' Returns the path and type for a template '''
Expand Down

0 comments on commit 271c6a2

Please sign in to comment.