Class: Stache::Mustache::View

Inherits:
Mustache
  • Object
show all
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

Layout

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#templateObject

Returns the value of attribute template.



8
9
10
# File 'lib/stache/mustache/view.rb', line 8

def template
  @template
end

#viewObject

Returns the value of attribute view.



8
9
10
# File 'lib/stache/mustache/view.rb', line 8

def view
  @view
end

#virtual_pathObject

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

.helpersObject Also known as: h



41
42
43
# File 'lib/stache/mustache/view.rb', line 41

def helpers
  Stache::ViewContext.current
end

Instance Method Details

#hObject



38
39
40
# File 'lib/stache/mustache/view.rb', line 38

def helpers
  self.class.helpers
end

#helpersObject



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

Returns:

  • (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