Created
October 8, 2012 21:44
-
-
Save loopj/3855205 to your computer and use it in GitHub Desktop.
Batman.js controller which adds rails-style layouts to controllers
This file contains hidden or 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 Batman.LayoutController extends Batman.Controller | |
render: (options = {}) -> | |
layout = options.layout ? @layout ? Batman.helpers.underscore(@get('routingKey')) | |
if layout | |
# Prefetch the action's view in parallel | |
source = options.source || Batman.helpers.underscore(@get('routingKey') + '/' + @get('action')) | |
Batman.View.store.prefetch source | |
# Fetch the layout's view and apply context | |
layoutView = @renderCache.viewForOptions | |
viewClass: Batman.View | |
context: @get('_renderContext') | |
source: Batman.helpers.underscore('layouts/' + @get('routingKey')) | |
# Render the layout's view into the DOM, the action into the layout | |
layoutView.on 'ready', => | |
Batman.DOM.Yield.withName(options.into || @defaultRenderYield).replace layoutView.get('node') | |
options.into = 'content' # TODO: Make customizable somehow | |
super(options) | |
else | |
super(options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment