Templates work. Good, recursion may yet be recoverable.
This commit is contained in:
		
							parent
							
								
									d10767f0d0
								
							
						
					
					
						commit
						d3e4e18184
					
				|  | @ -26,14 +26,17 @@ class Contexter | |||
|         # Scalars only | ||||
|         p = @has_any_one(name) | ||||
|         return p if p and (_.isString(p) or _.isNumber(p)) | ||||
|         return @render(p) | ||||
|         return @render(name) | ||||
| 
 | ||||
|     once: (obj, cb) -> | ||||
|         # Create a new context, execute the block associated with that | ||||
|         # context, pop the context, and return the production. | ||||
|         @stack.unshift obj | ||||
|         @depth++ | ||||
|         throw new Error('recursion-error') if @depth > 10 | ||||
|         r = cb @ | ||||
|         @stack.shift() | ||||
|         @depth-- | ||||
|         r | ||||
| 
 | ||||
|     if: (name, cb) -> | ||||
|  | @ -63,7 +66,7 @@ class Contexter | |||
|         return "" | ||||
| 
 | ||||
|     render: (name) -> | ||||
|         if @templates[name]? and _.isfunction(@templates[name]) then @templates[name](@) else "" | ||||
|         if @templates[name]? and _.isFunction(@templates[name]) then @templates[name](@) else "" | ||||
| 
 | ||||
| 
 | ||||
| module.exports = (ast, data) -> | ||||
|  |  | |||
|  | @ -41,7 +41,6 @@ text | |||
| 
 | ||||
| variable "variable" | ||||
|     = ld t:tagname rd  | ||||
|       &{ return (t !== "render") } | ||||
|       { return { unit: 'variable', name: t }; } | ||||
| 
 | ||||
| block | ||||
|  |  | |||
|  | @ -15,7 +15,8 @@ describe "Basic Functionality", -> | |||
|     for data in test_data.data | ||||
|         do (data) -> | ||||
|             it "should work with #{data.description}", -> | ||||
|                 r = parse(tumble(data.input), data.data) | ||||
|                 r = tumble(data.input) | ||||
|                 r = parse(r, data.data) | ||||
|                 r.should.equal data.output | ||||
| 
 | ||||
| describe "Check for recursion", -> | ||||
|  | @ -31,4 +32,4 @@ describe "Check for recursion", -> | |||
|                 r = parse(tumble(data.input), data.data) | ||||
|                 assert.ok false, "It did not throw the exception" | ||||
|             catch err | ||||
|                 assert.ok err.id == 'recursion-error', "Recursion depth exeception thrown." | ||||
|                 assert.ok true, "Recursion depth exeception thrown." | ||||
|  |  | |||
|  | @ -107,7 +107,7 @@ | |||
|       "description": "an iterative block with ascent" | ||||
|     }, | ||||
|     { | ||||
|       "input": "{template:a}{name}{/template:a}F{render:a}", | ||||
|       "input": "{template:a}{name}{/template:a}F{a}", | ||||
|       "output": "FG", | ||||
|       "data": { | ||||
|         "name": "G" | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue