Class: Talktome::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/talktome/message.rb

Defined Under Namespace

Classes: Template

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @path = path
  @options = options
  compile
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



11
12
13
# File 'lib/talktome/message.rb', line 11

def data
  @data
end

#metadataObject

Returns the value of attribute metadata.



10
11
12
# File 'lib/talktome/message.rb', line 10

def 
  @metadata
end

#pathObject

Returns the value of attribute path.



9
10
11
# File 'lib/talktome/message.rb', line 9

def path
  @path
end

#template_contentObject

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

Yields:

  • (d)


26
27
28
29
30
# File 'lib/talktome/message.rb', line 26

def dup
  d = super
  yield(d) if block_given?
  d
end

#extensionObject



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_htmlObject



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_textObject



36
37
38
# File 'lib/talktome/message.rb', line 36

def to_text
  template_it(self.template_content, :text)
end