Class: ActionView::TemplateHandlers::Builder

Inherits:
ActionView::TemplateHandler show all
Includes:
Compilable
Defined in:
lib/action_view/template_handlers/builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Compilable

#compile_template, included, #render

Methods inherited from ActionView::TemplateHandler

compilable?, #compilable?, #initialize, #line_offset, #render

Constructor Details

This class inherits a constructor from ActionView::TemplateHandler

Class Method Details

.line_offsetObject



8
9
10
# File 'lib/action_view/template_handlers/builder.rb', line 8

def self.line_offset
  2
end

Instance Method Details

#cache_fragment(block, name = {}, options = nil) ⇒ Object



20
21
22
23
24
# File 'lib/action_view/template_handlers/builder.rb', line 20

def cache_fragment(block, name = {}, options = nil)
  @view.fragment_for(block, name, options) do
    eval('xml.target!', block.binding)
  end
end

#compile(template) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/action_view/template_handlers/builder.rb', line 12

def compile(template)
  content_type_handler = (@view.send!(:controller).respond_to?(:response) ? "controller.response" : "controller")
  "#{content_type_handler}.content_type ||= Mime::XML\n" +
  "xml = ::Builder::XmlMarkup.new(:indent => 2)\n" +
  template.source +
  "\nxml.target!\n"
end