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



15
16
17
# File 'lib/stache/mustache/view.rb', line 15

def method_missing(method, *args, &block)
  view.send(method, *args, &block)
end

Instance Attribute Details

#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



61
62
63
# File 'lib/stache/mustache/view.rb', line 61

def helpers
  Stache::ViewContext.current
end

Instance Method Details

#contextObject



10
11
12
13
# File 'lib/stache/mustache/view.rb', line 10

def context
  # Use the faster context instead of the original mustache one
  @context ||= FasterContext.new(self)
end

#hObject



58
59
60
# File 'lib/stache/mustache/view.rb', line 58

def helpers
  self.class.helpers
end

#helpersObject



55
56
57
# File 'lib/stache/mustache/view.rb', line 55

def helpers
  self.class.helpers
end

#partial(name) ⇒ Object

Redefine where Stache::View templates locate their partials



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/stache/mustache/view.rb', line 34

def partial(name)
  cache_key = :"#{virtual_path}/#{name}"

  # Try to resolve template from cache
  template_cached = ::Stache.template_cache.read(cache_key, :namespace => :partials, :raw => true)
  curr_template   = template_cached || Stache::Mustache::CachedTemplate.new(
    begin # Try to resolve the partial template
      template_finder(name, true)
    rescue ActionView::MissingTemplate
      template_finder(name, false)
    end.source
  )

  # Store the template
  unless template_cached
    ::Stache.template_cache.write(cache_key, curr_template, :namespace => :partials, :raw => true)
  end

  curr_template
end

#respond_to?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/stache/mustache/view.rb', line 19

def respond_to?(method, include_private=false)
  super(method, include_private) || view.respond_to?(method, include_private)
end