Class: Stachio::Template

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection
Defined in:
app/models/stachio/template.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#presentsObject

Returns the value of attribute presents.



11
12
13
# File 'app/models/stachio/template.rb', line 11

def presents
  @presents
end

#renderedObject

Returns the value of attribute rendered.



11
12
13
# File 'app/models/stachio/template.rb', line 11

def rendered
  @rendered
end

Instance Method Details

#describe(n = 32) ⇒ Object



32
33
34
# File 'app/models/stachio/template.rb', line 32

def describe(n=32)
  (description && description.size > n) ? description[0..n] + ' [...]' : description
end

#present(values = nil, options = {}) ⇒ Object



26
27
28
29
30
# File 'app/models/stachio/template.rb', line 26

def present(values=nil, options={})
  return render if values.nil?
  self.presents = values
  render options.merge(:force => true)
end

#render(options = {}) ⇒ Object Also known as: assemble, composite, compose



17
18
19
20
21
# File 'app/models/stachio/template.rb', line 17

def render(options={})
  options = options.with_indifferent_access
  reset if !!(options[:force] or options[:reset])
  self.rendered ||= Mustache.render(content, presents) unless presents.nil?
end

#resetObject



13
14
15
# File 'app/models/stachio/template.rb', line 13

def reset
  self.rendered = nil
end