Skip to content

Commit

Permalink
FIxed variables replacement bug in Zen snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeche committed Nov 2, 2009
1 parent 273cade commit bccb62f
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Support/Library/zencoding/zen_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def replace_variables(text, vars=zen_settings['variables']):
@param text: str
@return: str
"""
return re.sub(r'\$\{([\w\-]+)\}', lambda s, p1: p1 in zen_settings['variables'] and zen_settings['variables'][p1] or s, text)
return re.sub(r'\$\{([\w\-]+)\}', lambda m: m.group(1) in vars and vars[m.group(1)] or m.group(0), text)

def get_abbreviation(res_type, abbr):
"""
Expand Down Expand Up @@ -274,7 +274,6 @@ def parse_into_tree(abbr, doc_type='html'):
@return: Tag
"""
root = Tag('', 1, doc_type)
multiply_elem = None
token = re.compile(r'([\+>])?([a-z@\!][a-z0-9:\-]*)(#[\w\-\$]+)?((?:\.[\w\-\$]+)*)(\*(\d*))?', re.IGNORECASE)

if not abbr:
Expand Down Expand Up @@ -402,9 +401,6 @@ def wrap_with_abbreviation(abbr, text, doc_type='html', profile='plain'):
return None

def update_settings(settings):
"""
Updates global zen settings
"""
globals()['zen_settings'] = settings

class Tag(object):
Expand Down Expand Up @@ -727,6 +723,11 @@ def to_string(self, profile_name):
begin = replace_variables(begin, self.attributes)
end = replace_variables(end, self.attributes)

# fix indentation
indent = zen_settings['variables']['indentation']
begin = begin.replace('\\t', indent)
end = end.replace('\\t', indent)

if self.get_content():
content = pad_string(self.get_content(), 1) + content

Expand Down

0 comments on commit bccb62f

Please sign in to comment.