Created
February 28, 2010 04:14
-
-
Save bryanlarsen/317186 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActionView::Template.register_template_handler(:dryml, Dryml::TemplateHandler) | |
ActionController::Base.view_paths << Dryml::FallbackResolver.new |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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