Class: RSpec::ActionView::ERBTemplateEngine
- Inherits:
-
Object
- Object
- RSpec::ActionView::ERBTemplateEngine
- Defined in:
- lib/rspec-action_view/erb_template_inline.rb
Defined Under Namespace
Modules: Locals
Constant Summary collapse
- ERBHandler =
::ActionView::Template::Handlers::ERB
- EXCLUDE_IVARS =
%w{ @_assertion_wrapped @_result @controller @layouts @locals @method_name @output_buffer @partials @rendered @request @routes @templates @test_passed @view @view_context_class }
Instance Attribute Summary collapse
-
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
-
#rendered ⇒ Object
Returns the value of attribute rendered.
Instance Method Summary collapse
- #_assigns ⇒ Object
- #_get_view ⇒ Object
- #_instance_variables ⇒ Object
-
#initialize ⇒ ERBTemplateEngine
constructor
A new instance of ERBTemplateEngine.
- #locals ⇒ Object
- #render(options = {}, local_assigns = {}, &block) ⇒ Object
- #run_template(options = {}, local_assigns = {}, &block) ⇒ Object
- #run_template_locals(locals = {}, local_assigns = {}, &block) ⇒ Object
- #view ⇒ Object (also: #_view)
Constructor Details
#initialize ⇒ ERBTemplateEngine
Returns a new instance of ERBTemplateEngine.
12 13 14 15 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 12 def initialize @output_buffer = ActiveSupport::SafeBuffer.new @rendered = '' end |
Instance Attribute Details
#output_buffer ⇒ Object
Returns the value of attribute output_buffer.
10 11 12 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 10 def output_buffer @output_buffer end |
#rendered ⇒ Object
Returns the value of attribute rendered.
10 11 12 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 10 def rendered @rendered end |
Instance Method Details
#_assigns ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 72 def _assigns _instance_variables.inject({}) do |hash, var| name = var[1..-1].to_sym hash[name] = instance_variable_get(var) hash end end |
#_get_view ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 32 def _get_view view = ::ActionView::Base.new # ??? # view.singleton_class.send :include, _helpers view.extend(Locals) view.locals = self.locals view.send :"output_buffer=", self.output_buffer view end |
#_instance_variables ⇒ Object
68 69 70 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 68 def _instance_variables instance_variables.map(&:to_s) - EXCLUDE_IVARS end |
#locals ⇒ Object
28 29 30 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 28 def locals @locals ||= {} end |
#render(options = {}, local_assigns = {}, &block) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 17 def render( = {}, local_assigns = {}, &block) view.assign(_assigns) output = view.render(, local_assigns, &block) @rendered << output output end |
#run_template(options = {}, local_assigns = {}, &block) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 86 def run_template = {}, local_assigns = {}, &block raise ArgumentError, "Must take template as a block argument" if !block .merge!(:inline => block.call) render , local_assigns end |
#run_template_locals(locals = {}, local_assigns = {}, &block) ⇒ Object
80 81 82 83 84 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 80 def run_template_locals locals = {}, local_assigns = {}, &block raise ArgumentError, "Must take template as a block argument" if !block = {:inline => block.call}.merge(:locals => locals) render , local_assigns end |
#view ⇒ Object Also known as: _view
44 45 46 |
# File 'lib/rspec-action_view/erb_template_inline.rb', line 44 def view @view ||= _get_view end |