Class: WP2Middleman::MiddlemanPost

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

Instance Method Summary collapse

Constructor Details

#initialize(wp_post, body_to_markdown: false, include_fields: []) ⇒ MiddlemanPost

Returns a new instance of MiddlemanPost.



3
4
5
6
7
# File 'lib/wp2middleman/middleman_post.rb', line 3

def initialize(wp_post, body_to_markdown: false, include_fields: [])
  @wp_post = wp_post
  @body_to_markdown = body_to_markdown
  @include_fields = include_fields
end

Instance Method Details

#contentObject



48
49
50
# File 'lib/wp2middleman/middleman_post.rb', line 48

def content
  wp_post.content
end

#date_publishedObject



23
24
25
# File 'lib/wp2middleman/middleman_post.rb', line 23

def date_published
  wp_post.date_published
end

#file_contentObject



31
32
33
34
35
36
37
38
# File 'lib/wp2middleman/middleman_post.rb', line 31

def file_content
  <<-EOS.gsub(/^ {8}/, '')
    #{frontmatter.to_yaml}
    ---

    #{formatted_post_content}
  EOS
end

#filenameObject



19
20
21
# File 'lib/wp2middleman/middleman_post.rb', line 19

def filename
  "#{date_published}-#{title_for_filename}"
end

#formatted_post_contentObject



40
41
42
43
44
45
46
# File 'lib/wp2middleman/middleman_post.rb', line 40

def formatted_post_content
  if body_to_markdown
    markdown_content
  else
    content
  end
end

#full_filename(output_path) ⇒ Object



27
28
29
# File 'lib/wp2middleman/middleman_post.rb', line 27

def full_filename output_path
  "#{output_path}#{filename}.html.markdown"
end

#markdown_contentObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/wp2middleman/middleman_post.rb', line 52

def markdown_content
  html = HTMLPage.new :contents => content
  html.comment do |node,_|
    "#{node}"
  end
  html.iframe do |node,_|
    "#{node}"
  end
  html.markdown
end

#titleObject



9
10
11
# File 'lib/wp2middleman/middleman_post.rb', line 9

def title
  wp_post.title
end

#title_for_filenameObject



13
14
15
16
17
# File 'lib/wp2middleman/middleman_post.rb', line 13

def title_for_filename
  title.gsub(/[^\w\s_-]+/, '')
    .gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
    .gsub(/\s+/, '-')
end