Class: JekyllImport::Importers::WordpressDotCom::Item
- Inherits:
-
Object
- Object
- JekyllImport::Importers::WordpressDotCom::Item
- Defined in:
- lib/jekyll-import/importers/wordpressdotcom.rb
Instance Method Summary collapse
- #directory_name ⇒ Object
- #excerpt ⇒ Object
- #file_name ⇒ Object
-
#initialize(node) ⇒ Item
constructor
A new instance of Item.
- #parent_id ⇒ Object
- #permalink ⇒ Object
- #permalink_title ⇒ Object
- #post_password ⇒ Object
- #post_type ⇒ Object
- #published? ⇒ Boolean
- #published_at ⇒ Object
- #status ⇒ Object
- #text_for(path) ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(node) ⇒ Item
Returns a new instance of Item.
55 56 57 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 55 def initialize(node) @node = node end |
Instance Method Details
#directory_name ⇒ Object
115 116 117 118 119 120 121 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 115 def directory_name @directory_name ||= if !published? && post_type == "post" "_drafts" else "_#{post_type}s" end end |
#excerpt ⇒ Object
127 128 129 130 131 132 133 134 135 136 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 127 def excerpt @excerpt ||= begin text = Hpricot(text_for("excerpt:encoded")).inner_text if text.empty? nil else text end end end |
#file_name ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 107 def file_name @file_name ||= if published? "#{published_at.strftime("%Y-%m-%d")}-#{permalink_title}.html" else "#{permalink_title}.html" end end |
#parent_id ⇒ Object
103 104 105 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 103 def parent_id @parent_id ||= text_for("wp:post_parent") end |
#permalink ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 77 def permalink # Hpricot thinks "link" is a self closing tag so it puts the text of the link after the tag # but sometimes it works right! I think it's the xml declaration @permalink ||= begin uri = text_for("link") uri = @node.at("link").following[0] if uri.empty? URI(uri.to_s).path end end |
#permalink_title ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 67 def permalink_title post_name = text_for("wp:post_name") # Fallback to "prettified" title if post_name is empty (can happen) @permalink_title ||= if post_name.empty? WordpressDotCom.sluggify(title) else post_name end end |
#post_password ⇒ Object
95 96 97 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 95 def post_password @post_password ||= text_for("wp:post_password") end |
#post_type ⇒ Object
99 100 101 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 99 def post_type @post_type ||= text_for("wp:post_type") end |
#published? ⇒ Boolean
123 124 125 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 123 def published? @published ||= (status == "publish") end |
#published_at ⇒ Object
87 88 89 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 87 def published_at @published_at ||= Time.parse(text_for("wp:post_date")) if published? end |
#status ⇒ Object
91 92 93 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 91 def status @status ||= text_for("wp:status") end |
#text_for(path) ⇒ Object
59 60 61 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 59 def text_for(path) @node.at(path).inner_text end |
#title ⇒ Object
63 64 65 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 63 def title @title ||= text_for(:title).strip end |