Permalink
Browse files

fixes for dotted tags

  • Loading branch information...
1 parent 73f9819 commit fb7a2d85e4ecfbe8ea0e052ceaada3267ecc762c @amccollum committed Oct 4, 2011
Showing with 14 additions and 19 deletions.
  1. +6 −9 lib/wings.js
  2. +1 −1 package.json
  3. +2 −2 src/test/wings-test.coffee
  4. +5 −7 src/wings/wings.coffee
View
@@ -33,8 +33,8 @@
};
parse_re = /\s*\{([?:!]+)\s*([^}]*?)\s*\}([\S\s]+?)\s*\{\/\s*\2\s*\}|\{(\#)\s*[\S\s]+?\s*\#\}|\{([@&]?)\s*([^}]*?)\s*\}/mg;
return renderRawTemplate = function(template, data, links) {
- return template.replace(parse_re, function(match, section_op, section_name, section_content, comment_op, tag_op, tag_name) {
- var content, i, link, name, op, part, parts, v, value, _len, _ref2;
+ return template.replace(parse_re, function(all, section_op, section_name, section_content, comment_op, tag_op, tag_name) {
+ var content, i, link, name, op, part, parts, rest, v, value, _len, _ref2;
op = section_op || comment_op || tag_op;
name = section_name || tag_name;
content = section_content;
@@ -101,13 +101,10 @@
case '&':
case '':
value = data;
- while (value && name) {
- _ref2 = name.match(/^([^.]*)\.?(.*)$/).slice(1), part = _ref2[0], name = _ref2[1];
- if (part in value) {
- value = value[part];
- } else {
- value = null;
- }
+ rest = name;
+ while (value && rest) {
+ _ref2 = rest.match(/^([^.]*)\.?(.*)$/), all = _ref2[0], part = _ref2[1], rest = _ref2[2];
+ value = value[part];
}
if (!(value != null)) {
throw "Invalid value: " + (JSON.stringify(data)) + ": " + name;
View
@@ -1,6 +1,6 @@
{
"name": "wings",
- "version": "0.5.2",
+ "version": "0.5.3",
"description": "Templating library that works on the server and client closely modeled on Mustache",
"keywords": ["ender", "template", "mustache", "html"],
"author": "Andrew McCollum <amccollum@gmail.com>",
@@ -40,15 +40,15 @@ vows.add 'templates'
'a template with multiple tags':
topic: t('The {adj1}, {adj2} fox {verb1} over the {adj3} dogs.',
- {adj1:'quick', adj2:'brown', adj3:'lazy', verb1:'jumped'})
+ {adj1:'quick', adj2:'brown', adj3:'lazy', verb1:'jumped'})
'should replace all the tags': (topic) ->
equal topic, 'The quick, brown fox jumped over the lazy dogs.'
'a template with dotted tags':
topic: t('The {adjs.adj1}, {adjs.adj2} fox {verbs.verb1} over the {adjs.adj3} dogs.',
- {adjs: {adj1:'quick', adj2:'brown', adj3:'lazy'}, verbs: {verb1:'jumped'}})
+ {adjs: {adj1:'quick', adj2:'brown', adj3:'lazy'}, verbs: {verb1:'jumped'}})
'should replace the tags with the object properties': (topic) ->
equal topic, 'The quick, brown fox jumped over the lazy dogs.'
View
@@ -28,7 +28,7 @@
///mg
renderRawTemplate = (template, data, links) ->
- template.replace parse_re, (match, section_op, section_name, section_content, comment_op, tag_op, tag_name) ->
+ template.replace parse_re, (all, section_op, section_name, section_content, comment_op, tag_op, tag_name) ->
op = section_op or comment_op or tag_op
name = section_name or tag_name
content = section_content
@@ -99,12 +99,10 @@
when '&', '' # value tag
value = data
- while value and name
- [part, name] = name.match(/^([^.]*)\.?(.*)$/)[1..]
- if part of value
- value = value[part]
- else
- value = null
+ rest = name
+ while value and rest
+ [all, part, rest] = rest.match(/^([^.]*)\.?(.*)$/)
+ value = value[part]
if not value?
throw "Invalid value: #{JSON.stringify(data)}: #{name}"

0 comments on commit fb7a2d8

Please sign in to comment.