Created
October 27, 2009 17:58
-
-
Save juvenn/219786 to your computer and use it in GitHub Desktop.
mustache compile_partial hacking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git diff --cached mustache/template.rb | |
diff --git a/vendor/mustache/mustache/template.rb b/vendor/mustache/mustache/template.rb | |
index 365e421..5b98d29 100644 | |
--- a/vendor/mustache/mustache/template.rb | |
+++ b/vendor/mustache/mustache/template.rb | |
@@ -131,12 +131,18 @@ class Mustache | |
# Partials are basically a way to render views from inside other views. | |
def compile_partial(name) | |
- klass = Mustache.classify(name) | |
- if Object.const_defined?(klass) | |
- ev("#{klass}.render") | |
- else | |
+ klass = Mustache.view_class(name) | |
+ if Mustache == klass | |
+ # Partial's view `name` not defined, | |
+ # just render partial template in parent view | |
src = File.read("#{@template_path}/#{name}.#{@template_extension}") | |
compile(src)[1..-2] | |
+ else | |
+ # Partial' view defined somewhere, | |
+ # so we should render template in partial view's context, | |
+ # though, instance variable not available to partial's view | |
+ klass.template_path = @template_path | |
+ ev("#{klass}.render") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment