Class: Mail2FrontMatter::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/mail2frontmatter/writer.rb

Class Method Summary collapse

Class Method Details

.write(metadata, body) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mail2frontmatter/writer.rb', line 15

def self.write(, body)

  # TODO FIXME!
  # 
  # this is supposed to be configurable!
  # get this value from a module variable!
  # 
  data_directory = File.join(Dir.pwd, 'source', 'blog')

  # MAPPINGS!
  # 
  # Play nice with programs which will read this data
  # And set sensible defaults as fall throughs

  # if there is no title set, borrow the subject lines
  [:title] ||= [:subject]

  # make a sensible standard blog filename unless one is given
  [:filename] ||= [[:received].strftime("%Y-%m-%d"), '-', [:subject].parameterize, '.html.erb'].join

  data = .to_yaml + "---\n" + body

  File.write(File.join(data_directory, [:filename]), data)
end