Class: Stache::Mustache::View
- Inherits:
-
Mustache
- Object
- Mustache
- Stache::Mustache::View
- Defined in:
- lib/stache/mustache/view.rb
Overview
A Convienent Base Class for the views. Subclass this for autoloading magic with your templates.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#template ⇒ Object
Returns the value of attribute template.
-
#view ⇒ Object
Returns the value of attribute view.
-
#virtual_path ⇒ Object
Returns the value of attribute virtual_path.
Class Method Summary collapse
- .helpers ⇒ Object (also: h)
Instance Method Summary collapse
- #h ⇒ Object
- #helpers ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
-
#partial(name) ⇒ Object
Redefine where Stache::View templates locate their partials.
- #respond_to?(method, include_private = false) ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
10 11 12 |
# File 'lib/stache/mustache/view.rb', line 10 def method_missing(method, *args, &block) view.send(method, *args, &block) end |
Instance Attribute Details
#template ⇒ Object
Returns the value of attribute template.
8 9 10 |
# File 'lib/stache/mustache/view.rb', line 8 def template @template end |
#view ⇒ Object
Returns the value of attribute view.
8 9 10 |
# File 'lib/stache/mustache/view.rb', line 8 def view @view end |
#virtual_path ⇒ Object
Returns the value of attribute virtual_path.
8 9 10 |
# File 'lib/stache/mustache/view.rb', line 8 def virtual_path @virtual_path end |
Class Method Details
.helpers ⇒ Object Also known as: h
41 42 43 |
# File 'lib/stache/mustache/view.rb', line 41 def helpers Stache::ViewContext.current end |
Instance Method Details
#h ⇒ Object
38 39 40 |
# File 'lib/stache/mustache/view.rb', line 38 def helpers self.class.helpers end |
#helpers ⇒ Object
35 36 37 |
# File 'lib/stache/mustache/view.rb', line 35 def helpers self.class.helpers end |
#partial(name) ⇒ Object
Redefine where Stache::View templates locate their partials
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/stache/mustache/view.rb', line 19 def partial(name) current_dir = Stache.template_base_path.join( self.virtual_path.split("/")[0..-2].join("/") ) lookup_context.view_paths += [current_dir] template_finder = lambda do |partial| if ActionPack::VERSION::MAJOR == 3 && ActionPack::VERSION::MINOR < 2 lookup_context.find(name, [], partial) else # Rails 3.2 and higher lookup_context.find(name, [], partial, [], { formats: [:html], handlers: [:mustache] }) end end template = template_finder.call(true) rescue template_finder.call(false) template.source end |
#respond_to?(method, include_private = false) ⇒ Boolean
14 15 16 |
# File 'lib/stache/mustache/view.rb', line 14 def respond_to?(method, include_private=false) super(method, include_private) || view.respond_to?(method, include_private) end |