Class: Mustache::Rails

Inherits:
Mustache show all
Defined in:
lib/generators/mustache/install/templates/lib/mustache_rails.rb

Overview

Remember to use {{yield}} (3 mustaches) to skip escaping HTML Using {{tag}} will skip escaping HTML so if your mustache methods return HTML, be sure to interpolate them using 3 mustaches.

Defined Under Namespace

Modules: Config Classes: TemplateHandler

Instance Attribute 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



14
15
16
# File 'lib/generators/mustache/install/templates/lib/mustache_rails.rb', line 14

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

Instance Attribute Details

#viewObject

Returns the value of attribute view.



12
13
14
# File 'lib/generators/mustache/install/templates/lib/mustache_rails.rb', line 12

def view
  @view
end

Instance Method Details

#partial(name) ⇒ Object

Redefine where Mustache::Rails templates locate their partials:

(1) in the same directory as the current template file. (2) in the shared templates path (can be configured via Config.shared_path=(value))



27
28
29
30
31
32
33
34
35
# File 'lib/generators/mustache/install/templates/lib/mustache_rails.rb', line 27

def partial(name)
  partial_name = "_#{name}.#{Config.template_extension}"
  template_dir = Pathname.new(self.class.template_file).dirname
  partial_path = File.expand_path("#{template_dir}/#{partial_name}")
  unless File.file?(partial_path)
    partial_path = "#{Config.shared_path}/#{partial_name}"
  end
  File.read(partial_path)
end

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

Returns:

  • (Boolean)


18
19
20
# File 'lib/generators/mustache/install/templates/lib/mustache_rails.rb', line 18

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