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")
|
|
|
|
"#{content_type_handler}.content_type ||= Mime::XML\n" +
|
2008-01-21 20:46:34 -05:00
|
|
|
"xml = ::Builder::XmlMarkup.new(:indent => 2)\n" +
|
2008-04-24 11:58:09 -04:00
|
|
|
template.source +
|
2007-12-09 17:11:11 -05:00
|
|
|
"\nxml.target!\n"
|
|
|
|
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
|