Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module Dryml
# quacks like a Rails3 ActionView::Template
class MissingTemplate
attr_reader :details
def identifier
"#{@prefix}/#{@name}"
end
def mime_type
details[:mime_type]
end
def initialize(name, details, prefix, partial)
@name = name
@details = details
@prefix = prefix
@partial = partial
end
def render(view, locals, &block)
renderer = Dryml.empty_page_renderer(view)
renderer.render_tag("#{@name}-page", locals)
end
end
class FallbackResolver < ActionView::Resolver
def find_templates(*args)
[Dryml::MissingTemplate.new(*args)]
end
end
end
ActionView::Template.register_template_handler(:dryml, Dryml::TemplateHandler)
ActionController::Base.view_paths << Dryml::FallbackResolver.new
module Dryml
class TemplateHandler < ActionView::Template::Handler
def self.call(template)
"renderer = Dryml.page_renderer(self, local_assigns.keys, '#{template.details[:virtual_path]}', '#{template.identifier}')
this = self.controller.send(:dryml_context) || local_assigns[:this]
@this ||= this
s = renderer.render_page(@this, local_assigns)
# Important to strip whitespace, or the browser hangs around for ages (FF2)
s.strip"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.