app/assets/javascripts/joosy/core/modules/renderer.js.coffee in joosy-1.0.0.RC3 vs app/assets/javascripts/joosy/core/modules/renderer.js.coffee in joosy-1.0.0.RC4

- old
+ new

@@ -83,18 +83,24 @@ stack = @__renderingStackChildFor parentStackPointer stack.template = template stack.locals = locals - isResource = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Generic - isCollection = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Collection + # If template was given as a lambda, parameters should + # be passed as a context, not as a argument + assignContext = false + isResource = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Generic + isCollection = Joosy.Module.hasAncestor locals.constructor, Joosy.Resource.Collection + if Object.isString template if @__renderSection? template = Joosy.Application.templater.resolveTemplate @__renderSection(), template, this template = Joosy.Application.templater.buildView template + else if Object.isFunction template + assignContext = true else if !Object.isFunction template throw new Error "#{Joosy.Module.__className @}> template (maybe @view) does not look like a string or lambda" if !Object.isObject(locals) && Object.extended().constructor != locals.constructor && !isResource && !isCollection throw new Error "#{Joosy.Module.__className @}> locals (maybe @data?) not in: dumb hash, Resource, Collection" @@ -102,10 +108,12 @@ renderers = render: (template, locals={}) => @render template, locals, stack renderDynamic: (template, locals={}) => @renderDynamic template, locals, stack + renderInline: (locals={}, template) => + @renderDynamic template, locals, stack context = => data = {} if isResource @@ -115,10 +123,14 @@ Joosy.Module.merge data, @__instantiateHelpers(), false Joosy.Module.merge data, renderers data - result = -> template(context()) + result = -> + if assignContext + template.call(context()) + else + template(context()) if dynamic morph = Metamorph result() update = => if morph.isRemoved()