jbrunton / frappuccino-core

2 stars 3 forks source link

create gem with default Knockout Renderer and TemplateEngine classes #20

Open jbrunton opened 11 years ago

jbrunton commented 11 years ago

create a frappuccino-knockout gem with the coffeescript classes below.

update frappuccino-demo to use these (by changing the classes the bootstrapper configures the application with).

possible implementation of KoRenderer:

class core.ko.FrappuccinoRenderer extends core.Renderer

    # TODO: pretty sure this method is redundant now, so remove if so
    _registerTemplate: (name, content) ->
        content.attr( "id", name )
        $('body').append( content )

    render_template: ( template, data, target ) ->
        target.html $( "<div></div>" ).attr 'data-bind',
                "template: 'template:#{template}'"

        ko.applyBindings( data || {}, target[0] )

possible implementation of KoRenderingEngine:

class core.ko.FrappuccinoEngine extends ko.nativeTemplateEngine

    constructor: (@app) ->
        @allowTemplateRewriting = false

    bind_helpers: ( binding_context ) ->
        @app.bind_helper( "application", binding_context )

        controller_helper_name = app.request.active_controller.name
        @app.bind_helper( controller_helper_name, binding_context )

    renderTemplateSource: (templateSource, bindingContext, options) ->
        @bind_helpers( bindingContext )           
        super(templateSource, bindingContext, options)