Permalink
Browse files

support mustache's view_path setting

  • Loading branch information...
1 parent 3f69cb4 commit 8f16b506e0819310116d132e14d19de10eddf22a @rtomayko committed Feb 22, 2010
Showing with 20 additions and 1 deletion.
  1. +2 −1 lib/tilt.rb
  2. +9 −0 test/tilt_mustache_views/external.rb
  3. +9 −0 test/tilt_mustachetemplate_test.rb
View
@@ -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
@@ -0,0 +1,9 @@
+require 'mustache'
+
+module Views
+ class External < Mustache
+ def hello
+ "Stached"
+ end
+ end
+end
@@ -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

0 comments on commit 8f16b50

Please sign in to comment.