Created
March 8, 2013 19:52
-
-
Save ktusznio/5119318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseView extends Backbone.View | |
template: "" | |
# Render hooks. | |
beforeFirstRender: -> | |
beforeRender: -> | |
afterRender: -> | |
afterFirstRender: -> | |
render: => | |
if !@rendered and @beforeFirstRender() is false | |
return | |
if @beforeRender() is false | |
return | |
if @template | |
html = @renderTemplate(@template, @model) | |
@$el.html html | |
@$el.show() | |
unless @rendered | |
@afterFirstRender() | |
@rendered = true | |
@afterRender() | |
@ | |
renderTemplate: (template, model = null) -> | |
context = | |
model: model | |
context.helpers = @namespace.ViewHelpers?.exports or {} | |
context.helpers.template = @renderPartial | |
if model | |
_.extend context, model.toJSON() | |
@renderPartial template, context | |
renderPartial: (template, context) => | |
JST["#{@templatesRoot}templates/#{template}"](context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment