class WP2Middleman::MiddlemanPost

Attributes

body_to_markdown[R]
include_fields[R]
wp_post[R]

Public Class Methods

new(wp_post, body_to_markdown: false, include_fields: []) click to toggle source
# 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

Public Instance Methods

content() click to toggle source
# File lib/wp2middleman/middleman_post.rb, line 48
def content
  wp_post.content
end
date_published() click to toggle source
# File lib/wp2middleman/middleman_post.rb, line 23
def date_published
  wp_post.date_published
end
file_content() click to toggle source
# File lib/wp2middleman/middleman_post.rb, line 31
    def file_content
      <<-EOS.gsub(/^ {8}/, '')
        #{frontmatter.to_yaml}
        ---

        #{formatted_post_content}
      EOS
    end
filename() click to toggle source
# File lib/wp2middleman/middleman_post.rb, line 19
def filename
  "#{date_published}-#{title_for_filename}"
end
formatted_post_content() click to toggle source
# 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) click to toggle source
# File lib/wp2middleman/middleman_post.rb, line 27
def full_filename output_path
  "#{output_path}#{filename}.html.markdown"
end
markdown_content() click to toggle source
# 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
title() click to toggle source
# File lib/wp2middleman/middleman_post.rb, line 9
def title
  wp_post.title
end
title_for_filename() click to toggle source
# 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

Private Instance Methods

frontmatter() click to toggle source
# File lib/wp2middleman/middleman_post.rb, line 67
def frontmatter
  @frontmatter ||= Frontmatter.new(wp_post, include_fields: include_fields)
end