Comparing version 0.3.7 to 0.3.8
{ | ||
"name": "combyne", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"main": "dist/combyne.js", | ||
"devDependencies": { | ||
"mocha": "~1.18.2", | ||
"mocha": "~1.20.1", | ||
"requirejs": "~2.1.10", | ||
@@ -8,0 +8,0 @@ "assert": "~0.1.0", |
@@ -186,3 +186,3 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.combyne=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
'partials[\'' + node.value + '\'].render(', | ||
node.args.length ? normalizeIdentifier(node.args[0]) : 'null', | ||
node.args.length ? normalizeIdentifier(node.args[0]) : node.data, | ||
')', | ||
@@ -327,3 +327,3 @@ ')' | ||
}; | ||
Combyne.VERSION = '0.3.7'; | ||
Combyne.VERSION = '0.3.8'; | ||
module.exports = Combyne; | ||
@@ -550,2 +550,3 @@ },{"./compiler":1,"./grammar":2,"./shared/register_filter":6,"./shared/register_partial":7,"./tokenizer":8,"./tree":9,"./utils/defaults":11,"./utils/type":13}],4:[function(_dereq_,module,exports){ | ||
root.type = 'PartialExpression'; | ||
root.data = 'null'; | ||
delete root.nodes; | ||
@@ -560,2 +561,6 @@ var input = ''; | ||
} | ||
case 'MAGIC': { | ||
root.data = 'data'; | ||
break; | ||
} | ||
default: { | ||
@@ -612,2 +617,3 @@ input += node.capture[0]; | ||
root.conditions = []; | ||
var isLeftSide = true; | ||
LOOP: | ||
@@ -617,5 +623,6 @@ while (this.stack.length) { | ||
switch (node.name) { | ||
case 'OTHER': { | ||
case 'ASSIGN': { | ||
isLeftSide = false; | ||
root.conditions.push({ | ||
type: 'Identifier', | ||
type: 'Assignment', | ||
value: node.capture[0].trim() | ||
@@ -625,5 +632,15 @@ }); | ||
} | ||
case 'ASSIGN': { | ||
case 'END_EXPR': { | ||
break LOOP; | ||
} | ||
case 'WHITESPACE': { | ||
break; | ||
} | ||
default: { | ||
if (isLeftSide && root.conditions.length) { | ||
root.conditions[0].value += node.capture[0].trim(); | ||
break; | ||
} | ||
root.conditions.push({ | ||
type: 'Assignment', | ||
type: 'Identifier', | ||
value: node.capture[0].trim() | ||
@@ -633,5 +650,2 @@ }); | ||
} | ||
case 'END_EXPR': { | ||
break LOOP; | ||
} | ||
} | ||
@@ -638,0 +652,0 @@ } |
@@ -186,3 +186,3 @@ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.combyne=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ | ||
'partials[\'' + node.value + '\'].render(', | ||
node.args.length ? normalizeIdentifier(node.args[0]) : 'null', | ||
node.args.length ? normalizeIdentifier(node.args[0]) : node.data, | ||
')', | ||
@@ -327,3 +327,3 @@ ')' | ||
}; | ||
Combyne.VERSION = '0.3.7'; | ||
Combyne.VERSION = '0.3.8'; | ||
module.exports = Combyne; | ||
@@ -637,2 +637,3 @@ },{"./compiler":1,"./grammar":2,"./shared/register_filter":6,"./shared/register_partial":7,"./tokenizer":13,"./tree":14,"./utils/defaults":16,"./utils/type":18}],4:[function(_dereq_,module,exports){ | ||
root.type = 'PartialExpression'; | ||
root.data = 'null'; | ||
delete root.nodes; | ||
@@ -647,2 +648,6 @@ var input = ''; | ||
} | ||
case 'MAGIC': { | ||
root.data = 'data'; | ||
break; | ||
} | ||
default: { | ||
@@ -699,2 +704,3 @@ input += node.capture[0]; | ||
root.conditions = []; | ||
var isLeftSide = true; | ||
LOOP: | ||
@@ -704,5 +710,6 @@ while (this.stack.length) { | ||
switch (node.name) { | ||
case 'OTHER': { | ||
case 'ASSIGN': { | ||
isLeftSide = false; | ||
root.conditions.push({ | ||
type: 'Identifier', | ||
type: 'Assignment', | ||
value: node.capture[0].trim() | ||
@@ -712,5 +719,15 @@ }); | ||
} | ||
case 'ASSIGN': { | ||
case 'END_EXPR': { | ||
break LOOP; | ||
} | ||
case 'WHITESPACE': { | ||
break; | ||
} | ||
default: { | ||
if (isLeftSide && root.conditions.length) { | ||
root.conditions[0].value += node.capture[0].trim(); | ||
break; | ||
} | ||
root.conditions.push({ | ||
type: 'Assignment', | ||
type: 'Identifier', | ||
value: node.capture[0].trim() | ||
@@ -720,5 +737,2 @@ }); | ||
} | ||
case 'END_EXPR': { | ||
break LOOP; | ||
} | ||
} | ||
@@ -725,0 +739,0 @@ } |
@@ -319,3 +319,3 @@ /** | ||
"partials['" + node.value + "'].render(", | ||
node.args.length ? normalizeIdentifier(node.args[0]) : "null", | ||
node.args.length ? normalizeIdentifier(node.args[0]) : node.data, | ||
")", | ||
@@ -322,0 +322,0 @@ ")" |
@@ -139,5 +139,5 @@ /** | ||
*/ | ||
Combyne.VERSION = "0.3.7"; | ||
Combyne.VERSION = "0.3.8"; | ||
module.exports = Combyne; | ||
}); |
@@ -215,2 +215,5 @@ /** | ||
// By default isolate the partial from the parent's data. | ||
root.data = "null"; | ||
// No node in a partial expression? | ||
@@ -231,2 +234,8 @@ delete root.nodes; | ||
case "MAGIC": { | ||
// If requested, pass the parent's data to the partial. | ||
root.data = "data"; | ||
break; | ||
} | ||
default: { | ||
@@ -329,2 +338,5 @@ // Accumulate all values into the input variable, will split later. | ||
// Find the left side identifier. | ||
var isLeftSide = true; | ||
LOOP: | ||
@@ -335,5 +347,7 @@ while (this.stack.length) { | ||
switch (node.name) { | ||
case "OTHER": { | ||
case "ASSIGN": { | ||
isLeftSide = false; | ||
root.conditions.push({ | ||
type: "Identifier", | ||
type: "Assignment", | ||
value: node.capture[0].trim() | ||
@@ -345,5 +359,21 @@ }); | ||
case "ASSIGN": { | ||
case "END_EXPR": { | ||
break LOOP; | ||
} | ||
case "WHITESPACE": { | ||
break; | ||
} | ||
default: { | ||
// If we're on the left hand side and there are already conditions, | ||
// this is the only time we're aren't pushing a value descriptor. | ||
if (isLeftSide && root.conditions.length) { | ||
root.conditions[0].value += node.capture[0].trim(); | ||
break; | ||
} | ||
root.conditions.push({ | ||
type: "Assignment", | ||
type: "Identifier", | ||
value: node.capture[0].trim() | ||
@@ -354,6 +384,2 @@ }); | ||
} | ||
case "END_EXPR": { | ||
break LOOP; | ||
} | ||
} | ||
@@ -491,2 +517,3 @@ } | ||
previous.value += value; | ||
break; | ||
@@ -499,2 +526,3 @@ } | ||
}); | ||
break; | ||
@@ -501,0 +529,0 @@ } |
{ | ||
"name": "combyne", | ||
"description": "A template engine that works the way you expect.", | ||
"version": "0.3.7", | ||
"version": "0.3.8", | ||
"author": "Tim Branyen (@tbranyen)", | ||
@@ -9,3 +9,3 @@ "main": "dist/combyne.js", | ||
"amdefine": "~0.1.0", | ||
"browserify": "~4.1.6", | ||
"browserify": "~4.1.10", | ||
"deamdify": "~0.1.1", | ||
@@ -19,3 +19,3 @@ "grunt": "~0.4.5", | ||
"grunt-simple-mocha": "~0.4.0", | ||
"jsdoc": "~3.3.0-alpha5", | ||
"jsdoc": "~3.3.0-alpha8", | ||
"karma-coverage": "~0.2.4", | ||
@@ -22,0 +22,0 @@ "karma-mocha": "~0.1.3", |
<img align="left" src="http://dl.dropboxusercontent.com/u/79007/combyne.png"> | ||
**Stable: 0.3.7** | ||
**Stable: 0.3.8** | ||
@@ -346,2 +346,20 @@ [](https://travis-ci.org/tbranyen/combyne) | ||
#### Pass template data to partial. #### | ||
If you need to pass the template's data to the partial, simply use the magic | ||
operator `.`. | ||
``` javascript | ||
var template = "{{foo}} {%partial bar .%}"; | ||
var context = { foo: "hello", name: "carl" }; | ||
var tmpl = combyne(template); | ||
tmpl.registerPartial("bar", combyne("{{name}}")); | ||
var output = tmpl.render(context); | ||
/// output == "hello carl" | ||
``` | ||
#### Render and inject a partial. #### | ||
@@ -348,0 +366,0 @@ |
345854
3801
456