Skip to content

Commit

Permalink
[#2375] No longer use template path in ckan_extends tag
Browse files Browse the repository at this point in the history
  • Loading branch information
tobes committed Aug 10, 2012
1 parent 3384ad9 commit 3d78e31
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions ckan/lib/jinja_extensions.py
@@ -1,4 +1,5 @@
from os import path
import logging

from jinja2 import nodes
from jinja2 import loaders
Expand All @@ -11,6 +12,8 @@
import ckan.lib.base as base
import ckan.lib.helpers as h


log = logging.getLogger(__name__)
### Filters

def empty_and_escape(value):
Expand Down Expand Up @@ -47,23 +50,33 @@ def __init__(self, environment):

def parse(self, parser):
lineno = next(parser.stream).lineno
node = nodes.Extends(lineno)
template_path = parser.filename
# find where in the search path this template is from
index = 0
for searchpath in self.searchpath:
if template_path.startswith(searchpath):
break
index += 1
# parse the file to extend or assume same name

# get filename from full path
filename = template_path[len(searchpath) + 1:]

# Providing template path violently deprecated
if parser.stream.current.type != 'block_end':
node = nodes.Extends(lineno)
node.template = parser.parse_expression()
else:
node = nodes.Extends(lineno)
node.template = nodes.Const(parser.filename[len(searchpath) + 1:])
provided_template = parser.parse_expression().value
if provided_template != filename:
raise Exception('ckan_extends tag wrong path %s in %s'
% (provided_template, template_path))
else:
log.critical('Remove path from ckan_extend tag in %s'
% template_path)

# provide our magic format
# format is *<search path parent index>*<template name>
node.template.value = '*' + str(index) + '*' + node.template.value
magic_filename = '*' + str(index) + '*' + filename
# set template
node.template = nodes.Const(magic_filename)
return node


Expand Down

0 comments on commit 3d78e31

Please sign in to comment.