Skip to content

Instantly share code, notes, and snippets.

@bryanlarsen
Created February 28, 2010 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanlarsen/317186 to your computer and use it in GitHub Desktop.
Save bryanlarsen/317186 to your computer and use it in GitHub Desktop.
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