Module: Arbre::Rails::Layouts::ContextMethods
- Defined in:
- lib/arbre/rails/layouts.rb
Overview
ContextMethods
Instance Method Summary collapse
-
#document(klass = nil, *build_arguments, &content_block) ⇒ Object
Obtains and/or sets the current content document.
-
#layout(&layout_block) ⇒ Arbre::Html::Document
Provides a layout block to the current view and appends the current document to the current arbre element.
Instance Method Details
#document ⇒ Object #document(klass, *build_arguments, &content_block) ⇒ Object
Obtains and/or sets the current content document.
85 86 87 |
# File 'lib/arbre/rails/layouts.rb', line 85 def document(klass = nil, *build_arguments, &content_block) controller.send :arbre_document, klass, *build_arguments, &content_block end |
#layout(&layout_block) ⇒ Arbre::Html::Document
Provides a layout block to the current view and appends the current document to the current arbre element.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/arbre/rails/layouts.rb', line 93 def layout(&layout_block) doc = if document && document.content_block # Use the specified document with the specified content block. # Detect whether the block is called. block_called = false content_block = document.content_block doc = append(document.klass, *document.build_arguments) do |*args| block_called = true instance_exec *args, &content_block end # Call the block anyway if it hasn't been called yet. doc.instance_exec &document.content_block unless block_called doc elsif document # Use the specified document. append document.klass, *document.build_arguments else # Append an empty document. append Arbre::Rails.legacy_document end # Run the layout block unless this is an AJAX request. doc.instance_exec &layout_block if layout_block && !request.xhr? doc end |