Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

support mustache's view_path setting

  • Loading branch information...
commit 8f16b506e0819310116d132e14d19de10eddf22a 1 parent 3f69cb4
@rtomayko authored
View
3  lib/tilt.rb
@@ -481,9 +481,10 @@ def initialize_engine
def compile!
Mustache.view_namespace = options[:namespace]
+ Mustache.view_path = options[:view_path] || options[:mustaches]
@engine = options[:view] || Mustache.view_class(name)
options.each do |key, value|
- next if %w[view namespace mustaches].include?(key.to_s)
+ next if %w[view view_path namespace mustaches].include?(key.to_s)
@engine.send("#{key}=", value) if @engine.respond_to? "#{key}="
end
end
View
9 test/tilt_mustache_views/external.rb
@@ -0,0 +1,9 @@
+require 'mustache'
+
+module Views
+ class External < Mustache
+ def hello
+ "Stached"
+ end
+ end
+end
View
9 test/tilt_mustachetemplate_test.rb
@@ -51,6 +51,15 @@ class Bizzle < Mustache
assert_equal "<p>Hello World!</p>", template.render
end
+ test "locating views in files" do
+ view_path = File.expand_path('../tilt_mustache_views', __FILE__)
+ template = Tilt::MustacheTemplate.new('external.mustache', :view_path => view_path) { "<p>{{hello}}!</p>" }
+ template.compile
+ assert defined?(Views::External), "external.rb should have been required"
+ assert_equal Views::External, template.engine
+ assert_equal "<p>Stached!</p>", template.render
+ end
+
test "copying instance variables from scope object" do
template = Tilt::MustacheTemplate.new('foo.mustache') { "<p>Hey {{foo}}!</p>" }
scope = Object.new
Please sign in to comment.
Something went wrong with that request. Please try again.