Module: Arbre::Rails::Rendering
- Defined in:
- lib/arbre/rails/rendering.rb
Overview
Template rendering strategies for Arbre.
Partials
Simply use the method #partial instead of render :partial => ‘…’.
*edit.html.arb
:*
fieldset do
partial 'fieldset'
end
*_fieldset.html.arb
:*
# Note: `self' is the same `self' as in the template above!
label :something
text_field :something
To pass another context than self
:
*edit.html.arb
:*
form do |form|
fieldset do
partial 'fieldset', context: form
end
end
*_fieldset.html.arb
:*
# Note: `self' is now the form defined in the template above.
label :something
text_field :something
Instance Method Summary collapse
-
#partial(name, context: self, **locals) ⇒ Object
Inserts a partial into the current flow.
-
#render(*args, locals: {}, **options) ⇒ Object
Uses the given arguments to perform an ActionView render.
Instance Method Details
#partial(name, context: self, **locals) ⇒ Object
Inserts a partial into the current flow.
48 49 50 |
# File 'lib/arbre/rails/rendering.rb', line 48 def partial(name, context: self, **locals) render :partial => name, :locals => locals.merge(:arbre_context => context) end |
#render(*args, locals: {}, **options) ⇒ Object
Uses the given arguments to perform an ActionView render. If the result is an Arbre context, instead of treating it as a string, its children are added to the current element.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/arbre/rails/rendering.rb', line 55 def render(*args, locals: {}, **) locals = locals.merge(:arbre_output_context => true) result = helpers.render(*args, locals: locals, **) case result when Arbre::Context # Append all the context's children to the current element. However, watch out as # the children collection is modified during this operation. We'll first create # a copy. current_element.children.concat result.children.to_a when Arbre::Element current_element.children << result else current_element.children << TextNode.from_string(result) if result.length > 0 end result end |