2007-12-09 17:11:11 -05:00
|
|
|
require 'builder'
|
|
|
|
|
|
|
|
module ActionView
|
|
|
|
module TemplateHandlers
|
|
|
|
class Builder < TemplateHandler
|
2008-01-21 20:46:34 -05:00
|
|
|
include Compilable
|
|
|
|
|
2007-12-10 18:14:47 -05:00
|
|
|
def self.line_offset
|
|
|
|
2
|
|
|
|
end
|
|
|
|
|
2007-12-09 17:11:11 -05:00
|
|
|
def compile(template)
|
|
|
|
content_type_handler = (@view.send!(:controller).respond_to?(:response) ? "controller.response" : "controller")
|
2008-06-02 16:32:58 -04:00
|
|
|
|
2007-12-09 17:11:11 -05:00
|
|
|
"#{content_type_handler}.content_type ||= Mime::XML\n" +
|
2008-06-02 16:32:58 -04:00
|
|
|
"xml = ::Builder::XmlMarkup.new(:indent => 2)\n" +
|
|
|
|
template.source +
|
|
|
|
"\nxml.target!\n"
|
2007-12-09 17:11:11 -05:00
|
|
|
end
|
2008-01-09 22:17:20 -05:00
|
|
|
|
|
|
|
def cache_fragment(block, name = {}, options = nil)
|
|
|
|
@view.fragment_for(block, name, options) do
|
|
|
|
eval('xml.target!', block.binding)
|
|
|
|
end
|
|
|
|
end
|
2007-12-09 17:11:11 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|