Skip to content

Commit

Permalink
Simplify Mustache template. Tests all pass but requires Mustache 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
defunkt committed Oct 27, 2009
1 parent 953ca51 commit 39d137a
Showing 1 changed file with 3 additions and 23 deletions.
26 changes: 3 additions & 23 deletions lib/tilt.rb
Expand Up @@ -354,23 +354,16 @@ 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
Mustache.view_class(name)
end

# set options on the view class
Expand Down Expand Up @@ -402,19 +395,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 39d137a

Please sign in to comment.