Class: WP2Middleman::Frontmatter

Inherits:
Object
  • Object
show all
Defined in:
lib/wp2middleman/frontmatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(post, include_fields: []) ⇒ Frontmatter

Returns a new instance of Frontmatter.



5
6
7
8
# File 'lib/wp2middleman/frontmatter.rb', line 5

def initialize(post, include_fields: [])
  @post = post
  @include_fields = include_fields
end

Instance Method Details

#post_dataObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/wp2middleman/frontmatter.rb', line 10

def post_data
  data = {
    'title' => post.title,
    'date' => post.date_time_published,
    'tags' => post.tags
  }

  data['published'] = false if !post.published?

  include_fields.each do |field|
    data[field] = post.field(field)
  end

  data
end

#to_yamlObject



26
27
28
# File 'lib/wp2middleman/frontmatter.rb', line 26

def to_yaml
  post_data.to_yaml.strip
end