Module: ActionController::Layout
- Defined in:
- lib/action_controller/layout.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#active_layout(passed_layout = nil) ⇒ Object
Returns the name of the active layout.
-
#render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/action_controller/layout.rb', line 3 def self.included(base) base.extend(ClassMethods) base.class_eval do alias_method :render_with_no_layout, :render alias_method :render, :render_with_a_layout class << self alias_method :inherited_without_layout, :inherited alias_method :inherited, :inherited_with_layout end end end |
Instance Method Details
#active_layout(passed_layout = nil) ⇒ Object
Returns the name of the active layout. If the layout was specified as a method reference (through a symbol), this method is called and the return value is used. Likewise if the layout was specified as an inline method (through a proc or method object). If the layout was defined without a directory, layouts is assumed. So layout "weblog/standard"
will return weblog/standard, but layout "standard"
will return layouts/standard.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/action_controller/layout.rb', line 211 def active_layout(passed_layout = nil) layout = passed_layout || self.class.default_layout active_layout = case layout when String then layout when Symbol then send(layout) when Proc then layout.call(self) end # Explicitly passed layout names with slashes are looked up relative to the template root, # but auto-discovered layouts derived from a nested controller will contain a slash, though be relative # to the 'layouts' directory so we have to check the file system to infer which case the layout name came from. if active_layout if active_layout.include?('/') && ! layout_directory?(active_layout) active_layout else "layouts/#{active_layout}" end end end |
#render_with_a_layout(options = nil, deprecated_status = nil, deprecated_layout = nil, &block) ⇒ Object
:nodoc:
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/action_controller/layout.rb', line 232 def render_with_a_layout( = nil, deprecated_status = nil, deprecated_layout = nil, &block) #:nodoc: = .is_a?(Hash) if apply_layout?(, ) && (layout = pick_layout(, , deprecated_layout)) = .merge :layout => false if logger.info("Rendering #{} within #{layout}") if logger if content_for_layout = render_with_no_layout(, &block) deprecated_status = [:status] || deprecated_status else content_for_layout = render_with_no_layout(, deprecated_status, &block) end erase_render_results add_variables_to_assigns @template.instance_variable_set("@content_for_layout", content_for_layout) render_text(@template.render_file(layout, true), deprecated_status) else render_with_no_layout(, deprecated_status, &block) end end |