Skip to content

Commit

Permalink
Merge pull request #9 from gnufied/master
Browse files Browse the repository at this point in the history
Fixup mustache_rails3 for rails 3.1.1
  • Loading branch information
goodmike committed Apr 8, 2014
2 parents dde6c7f + 764be3c commit 74013fe
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/mustache_rails.rb
Expand Up @@ -64,36 +64,35 @@ def self.shared_path=(value)
end
end

class TemplateHandler < ActionView::Template::Handler

include ActionView::Template::Handlers::Compilable
class TemplateHandler

class_attribute :default_format
self.default_format = :mustache

# @return [String] its evaled in the context of the action view
# hence the hack below
#
# @param [ActionView::Template]
def compile(template)
def call(template)
mustache_class = mustache_class_from_template(template)
mustache_class.template_file = mustache_template_file(template)


<<-MUSTACHE
::#{mustache_class}.template_file = "#{Config.template_base_path}/#{template.virtual_path}.#{Config.template_extension}"
mustache = ::#{mustache_class}.new
mustache.view = self
mustache[:yield] = content_for(:layout)
mustache.context.update(local_assigns)
variables = controller.instance_variable_names
variables -= %w[@template]
if controller.respond_to?(:protected_instance_variables)
variables -= controller.protected_instance_variables
end
variables.each do |name|
mustache.instance_variable_set(name, controller.instance_variable_get(name))
end
# Declaring an +attr_reader+ for each instance variable in the
# Mustache::Rails subclass makes them available to your templates.
mustache.class.class_eval do
Expand All @@ -120,4 +119,5 @@ def mustache_template_file(template)
end

::ActiveSupport::Dependencies.autoload_paths << Rails.root.join("app", "views")
::ActionView::Template.register_template_handler(:rb, Mustache::Rails::TemplateHandler)
::ActionView::Template.register_template_handler(:rb, Mustache::Rails::TemplateHandler.new())

0 comments on commit 74013fe

Please sign in to comment.