Class: WP2Middleman::MiddlemanPost
- Inherits:
-
Object
- Object
- WP2Middleman::MiddlemanPost
- Defined in:
- lib/wp2middleman/middleman_post.rb
Instance Method Summary collapse
- #content ⇒ Object
- #date_published ⇒ Object
- #file_content ⇒ Object
- #filename ⇒ Object
- #formatted_post_content ⇒ Object
- #full_filename(output_path) ⇒ Object
-
#initialize(wp_post, body_to_markdown: false, include_fields: []) ⇒ MiddlemanPost
constructor
A new instance of MiddlemanPost.
- #markdown_content ⇒ Object
- #title ⇒ Object
- #title_for_filename ⇒ Object
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
#content ⇒ Object
48 49 50 |
# File 'lib/wp2middleman/middleman_post.rb', line 48 def content wp_post.content end |
#date_published ⇒ Object
23 24 25 |
# File 'lib/wp2middleman/middleman_post.rb', line 23 def date_published wp_post.date_published end |
#file_content ⇒ Object
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 |
#filename ⇒ Object
19 20 21 |
# File 'lib/wp2middleman/middleman_post.rb', line 19 def filename "#{date_published}-#{title_for_filename}" end |
#formatted_post_content ⇒ Object
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_content ⇒ Object
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 |
#title ⇒ Object
9 10 11 |
# File 'lib/wp2middleman/middleman_post.rb', line 9 def title wp_post.title end |
#title_for_filename ⇒ Object
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 |