Class: MustacheRails

Inherits:
Mustache
  • Object
show all
Defined in:
lib/question_chain/mustache_rails.rb

Direct Known Subclasses

Answers::QuestionView, Answers::UiObjectView

Instance Method Summary collapse

Constructor Details

#initialize(view_context, template_source) ⇒ MustacheRails

Returns a new instance of MustacheRails.



4
5
6
7
8
# File 'lib/question_chain/mustache_rails.rb', line 4

def initialize(view_context, template_source)
  @view_context = view_context    
  self.template = template_source
  assign_variables!
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/question_chain/mustache_rails.rb', line 18

def method_missing(method_name, *args, &block)
  if self.respond_to?(method_name.to_sym)
    @view_context.send(method_name,*args, &block)
  else
    super
  end
end

Instance Method Details

#render(data = template, ctx = {}) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/question_chain/mustache_rails.rb', line 31

def render(data = template, ctx = {})
  if self[:_raw] == true
    @raw_template
  else
    templateify(data).render(context.update(ctx))
  end
end

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

Returns:

  • (Boolean)


10
11
12
13
14
15
16
# File 'lib/question_chain/mustache_rails.rb', line 10

def respond_to?(method_sym, include_private = false)
  if @view_context.respond_to?(method_sym) 
    true
  else
    super
  end
end

#template=(template) ⇒ Object



26
27
28
29
# File 'lib/question_chain/mustache_rails.rb', line 26

def template=(template)
  @raw_template = template
  @template = templateify(template)
end