app/assets/javascripts/joosy/core/modules/renderer.js.coffee in joosy-0.1.0.RC2 vs app/assets/javascripts/joosy/core/modules/renderer.js.coffee in joosy-0.1.0.RC3

- old
+ new

@@ -1,15 +1,30 @@ #= require_tree ../templaters #= require metamorph +# +# Core DOM rendering mechanics +# +# @module +# @todo Describe this scary thing o_O +# Joosy.Modules.Renderer = + # + # Default behavior for non-set renderer (empty template?) + # __renderer: -> throw new Error "#{Joosy.Module.__className @constructor} does not have an attached template" __helpers: null + # + # Defines class-level helpers: @view and @helpers + # + # View (@view): Sets the curent template by specifying its name or lambda + # Helpers (@helpers): Lists set of helpers' namespaces to include + # included: -> @view = (template, options={}) -> if Object.isFunction template @::__renderer = template else @@ -75,10 +90,11 @@ __render: (dynamic, template, locals={}, parentStackPointer=false) -> 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 Object.isString template @@ -89,24 +105,24 @@ 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) && !isResource && !isCollection throw new Error "#{Joosy.Module.__className @}> locals (maybe @data?) not in: dumb hash, Resource, Collection" - - if isResource - stack.locals = locals.e - else - stack.locals = locals renderers = render: (template, locals={}) => @render template, locals, stack renderDynamic: (template, locals={}) => @renderDynamic template, locals, stack context = => data = {} - Joosy.Module.merge data, stack.locals + + if isResource + Joosy.Module.merge data, stack.locals.e + else + Joosy.Module.merge data, stack.locals + Joosy.Module.merge data, @__instantiateHelpers(), false Joosy.Module.merge data, renderers data if dynamic