Class: Effigy::Rails::View
Overview
Provides Rails-specific methods to Effigy views. Rather than instantiating this class directly, it is recommended that you create view and template files and allow TemplateHandler to discover and compile views.
Instance variables from controller actions will be copied to the view.
Instance Attribute Summary collapse
-
#action_view ⇒ Object
readonly
- ActionView::Base
-
the instance that is rendering this view.
Instance Method Summary collapse
-
#content_for(capture) ⇒ String
Returns the captured content of the given name.
-
#initialize(action_view, assigns, &layout_block) ⇒ View
constructor
The passed block will be called to access content captured by content_for, such as layout contents.
-
#partial(name, options = {}) ⇒ String
Renders the given partial and returns the generated markup.
Methods inherited from View
#add_class, #attr, #find, #html, #remove, #remove_class, #render, #replace_each, #replace_with, #text, #transform
Constructor Details
#initialize(action_view, assigns, &layout_block) ⇒ View
The passed block will be called to access content captured by content_for, such as layout contents.
23 24 25 26 27 28 29 30 |
# File 'lib/effigy/rails/view.rb', line 23 def initialize(action_view, assigns, &layout_block) @action_view = action_view assigns.each do |name, value| instance_variable_set(name, value) end @layout_block = layout_block end |
Instance Attribute Details
#action_view ⇒ Object (readonly)
- ActionView::Base
-
the instance that is rendering this view. This
instance is used to render partials and access other information about
the action being rendered.
14 15 16 |
# File 'lib/effigy/rails/view.rb', line 14 def action_view @action_view end |
Instance Method Details
#content_for(capture) ⇒ String
Returns the captured content of the given name. Use “layout” as a name to access the contents for the layout.
50 51 52 |
# File 'lib/effigy/rails/view.rb', line 50 def content_for(capture) @layout_block.call(capture) end |
#partial(name, options = {}) ⇒ String
Renders the given partial and returns the generated markup.
40 41 42 43 |
# File 'lib/effigy/rails/view.rb', line 40 def partial(name, = {}) [:partial] = name action_view.render() end |