Created
March 30, 2012 13:21
-
-
Save yusugomori/2251506 to your computer and use it in GitHub Desktop.
Tower.js toggle @layout
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
# | |
# applicationController.coffee | |
# | |
class App.ApplicationController extends Tower.Controller | |
# @layout "application" # ここに@layoutを置くと、上書きできない。 | |
constructor: -> | |
@layout = "application" # @layoutはcontructorの中に。 | |
@userAgent = "" | |
# renderメソッドをオーバーライドする。 | |
render: (path, options={})-> | |
if typeof path isnt 'string' # e.g. @render text: "This is text", status: 200 | |
options = path | |
path = "" | |
@setUserAgent() # User-Agentをセット。 | |
if @userAgent.match /mobile/ | |
@layout = "application-mobile" | |
path = "mobile/#{path}" | |
unless options.layout? # @render "welcome/index", layout: false などに対応。 | |
options.layout = @layout | |
super path, options | |
setUserAgent: () -> | |
@userAgent = @getUserAgent().join(" ") | |
getUserAgent: () -> | |
arr = [] | |
ua = @request.headers['user-agent'].toLowerCase() | |
# iPhone | |
if ua.match /iphone/ | |
arr.push "iphone", "mobile" | |
# Androidは省略 | |
return arr | |
# | |
# welcomesController.coffee (Just an example) | |
# | |
class App.WelcomeController extends App.ApplicationController | |
index: -> | |
@render text: "This is welcome#index" | |
about: -> | |
@render "welcome/about", layout: false | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment