Class: Talktome::Message
- Inherits:
-
Object
- Object
- Talktome::Message
- Defined in:
- lib/talktome/message.rb
Defined Under Namespace
Classes: Template
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#template_content ⇒ Object
readonly
Returns the value of attribute template_content.
Instance Method Summary collapse
- #dup {|d| ... } ⇒ Object
- #extension ⇒ Object
-
#initialize(path, options = {}) ⇒ Message
constructor
A new instance of Message.
- #instantiate(tpldata) ⇒ Object
- #to_html ⇒ Object
- #to_text ⇒ Object
Constructor Details
#initialize(path, options = {}) ⇒ Message
Returns a new instance of Message.
4 5 6 7 8 |
# File 'lib/talktome/message.rb', line 4 def initialize(path, = {}) @path = path @options = compile end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
11 12 13 |
# File 'lib/talktome/message.rb', line 11 def data @data end |
#metadata ⇒ Object
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/talktome/message.rb', line 10 def @metadata end |
#path ⇒ Object
Returns the value of attribute path.
9 10 11 |
# File 'lib/talktome/message.rb', line 9 def path @path end |
#template_content ⇒ Object
Returns the value of attribute template_content.
12 13 14 |
# File 'lib/talktome/message.rb', line 12 def template_content @template_content end |
Instance Method Details
#dup {|d| ... } ⇒ Object
26 27 28 29 30 |
# File 'lib/talktome/message.rb', line 26 def dup d = super yield(d) if block_given? d end |
#extension ⇒ Object
32 33 34 |
# File 'lib/talktome/message.rb', line 32 def extension path.ext.to_s.gsub(/^\./,"") end |
#instantiate(tpldata) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/talktome/message.rb', line 15 def instantiate(tpldata) self.dup do |m| m. = {} self..each_pair do |k, v| m.[k] = i(v, tpldata) end m.template_content = i(m.template_content, tpldata.merge(metadata: m.)) m.data = tpldata end end |
#to_html ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/talktome/message.rb', line 40 def to_html case extension when 'md' template_it(Talktome.redcarpet.render(self.template_content), :html) else template_it(self.template_content, :html) end end |
#to_text ⇒ Object
36 37 38 |
# File 'lib/talktome/message.rb', line 36 def to_text template_it(self.template_content, :text) end |