Class: WP2Middleman::Post
- Inherits:
-
Object
- Object
- WP2Middleman::Post
- Defined in:
- lib/wp2middleman/post.rb
Instance Attribute Summary collapse
-
#post ⇒ Object
Returns the value of attribute post.
Instance Method Summary collapse
- #content ⇒ Object
- #date_published ⇒ Object
- #filename ⇒ Object
-
#initialize(nokogiri_post_doc) ⇒ Post
constructor
A new instance of Post.
- #markdown_content ⇒ Object
- #post_date ⇒ Object
- #published? ⇒ Boolean
- #status ⇒ Object
- #tags ⇒ Object
- #title ⇒ Object
- #title_for_filename ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(nokogiri_post_doc) ⇒ Post
Returns a new instance of Post.
7 8 9 |
# File 'lib/wp2middleman/post.rb', line 7 def initialize(nokogiri_post_doc) @post = nokogiri_post_doc end |
Instance Attribute Details
#post ⇒ Object
Returns the value of attribute post.
5 6 7 |
# File 'lib/wp2middleman/post.rb', line 5 def post @post end |
Instance Method Details
#content ⇒ Object
45 46 47 |
# File 'lib/wp2middleman/post.rb', line 45 def content post.at_xpath(".//content:encoded").inner_text end |
#date_published ⇒ Object
29 30 31 |
# File 'lib/wp2middleman/post.rb', line 29 def date_published Date.parse(post_date).to_s end |
#filename ⇒ Object
21 22 23 |
# File 'lib/wp2middleman/post.rb', line 21 def filename "#{date_published}-#{title_for_filename}" end |
#markdown_content ⇒ Object
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/wp2middleman/post.rb', line 49 def markdown_content html = HTMLPage.new :contents => content html.comment do |node,_| "#{node}" end html.iframe do |node,_| "#{node}" end html.markdown end |
#post_date ⇒ Object
25 26 27 |
# File 'lib/wp2middleman/post.rb', line 25 def post_date post.xpath("wp:post_date").first.inner_text end |
#published? ⇒ Boolean
41 42 43 |
# File 'lib/wp2middleman/post.rb', line 41 def published? status == 'publish' end |
#status ⇒ Object
33 34 35 |
# File 'lib/wp2middleman/post.rb', line 33 def status post.xpath("wp:status").first.inner_text end |
#tags ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/wp2middleman/post.rb', line 60 def = [] categories = post.xpath("category") categories.each do |category| tag_name = category.css("@nicename").text .push tag_name unless tag_name == 'uncategorized' end end |
#title ⇒ Object
11 12 13 |
# File 'lib/wp2middleman/post.rb', line 11 def title post.css('title').text end |
#title_for_filename ⇒ Object
15 16 17 18 19 |
# File 'lib/wp2middleman/post.rb', line 15 def title_for_filename title.gsub(/[^\w\s_-]+/, '') .gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2') .gsub(/\s+/, '-') end |
#type ⇒ Object
37 38 39 |
# File 'lib/wp2middleman/post.rb', line 37 def type post.xpath("wp:post_type").first.inner_text end |