Class: Immigrada::MarkdownEntry
- Inherits:
-
Object
- Object
- Immigrada::MarkdownEntry
- Defined in:
- lib/immigrada/markdown_entry.rb
Overview
Class for generation markdown file with post from entry object.
Instance Method Summary collapse
-
#combine_filename ⇒ Object
Returns string with filename combined from date and slug.
-
#combine_post(params = {}) ⇒ Object
Returns string with post: frontmatter and content.
-
#initialize(b_entry, out_dir) ⇒ MarkdownEntry
constructor
A new instance of MarkdownEntry.
-
#save ⇒ Object
Saves post contents to file.
Constructor Details
#initialize(b_entry, out_dir) ⇒ MarkdownEntry
Returns a new instance of MarkdownEntry.
5 6 7 8 9 |
# File 'lib/immigrada/markdown_entry.rb', line 5 def initialize(b_entry, out_dir) @b_entry = b_entry @out_dir = out_dir @content = @b_entry.content end |
Instance Method Details
#combine_filename ⇒ Object
Returns string with filename combined from date and slug.
32 33 34 |
# File 'lib/immigrada/markdown_entry.rb', line 32 def combine_filename "#{@b_entry.published}-#{@b_entry.slug}.markdown" end |
#combine_post(params = {}) ⇒ Object
Returns string with post: frontmatter and content.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/immigrada/markdown_entry.rb', line 20 def combine_post(params={}) <<-EOF.gsub(/^\s+/, '') --- title: #{@b_entry.title} date: #{@b_entry.published} tags: #{@b_entry..join(',')} --- #{ReverseMarkdown.convert(@content)} EOF end |
#save ⇒ Object
Saves post contents to file.
12 13 14 15 16 17 |
# File 'lib/immigrada/markdown_entry.rb', line 12 def save filename = combine_filename path = File.join(@out_dir, filename) File.open(path, 'w') { |f| f.write(combine_post) } puts "Post '#{@b_entry.title}' saved to: #{filename}" end |