Skip to content

Commit

Permalink
Merge defunkt/simpler_mustache_loading
Browse files Browse the repository at this point in the history
  • Loading branch information
rtomayko committed Oct 29, 2009
2 parents e9782ef + a19c10f commit 7dd0b01
Showing 1 changed file with 3 additions and 29 deletions.
32 changes: 3 additions & 29 deletions lib/tilt.rb
Expand Up @@ -354,24 +354,11 @@ class MustacheTemplate < Template
def compile!
require_template_library 'mustache' unless defined?(::Mustache)

@view_name = Mustache.classify(name.to_s)
@namespace = options[:namespace] || Object
# Set the Mustache view namespace if we can
Mustache.view_namespace = options[:namespace]

# Figure out which Mustache class to use.
@engine =
if options[:view]
@view_name = options[:view].name
options[:view]
elsif @namespace.const_defined?(:Views) &&
@namespace::Views.const_defined?(@view_name)
@namespace::Views.const_get(@view_name)
elsif load_mustache_view
engine = @namespace::Views.const_get(@view_name)
engine.template = data
engine
else
Mustache
end
@engine = options[:view] || Mustache.view_class(name)

# set options on the view class
options.each do |key, value|
Expand Down Expand Up @@ -402,19 +389,6 @@ def evaluate(scope=nil, locals={}, &block)

instance.to_html
end

# Require the mustache view lib if it exists.
def load_mustache_view
return if name.nil?
path = "#{options[:mustaches]}/#{name}.rb"
if options[:mustaches] && File.exist?(path)
require path.chomp('.rb')
path
elsif File.exist?(path = file.sub(/\.[^\/]+$/, '.rb'))
require path.chomp('.rb')
path
end
end
end
register 'mustache', MustacheTemplate
end

0 comments on commit 7dd0b01

Please sign in to comment.