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.
56 57 58 59 60 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 56 def initialize(node) raise "Node is nil" if node.nil? @node = node end |
Instance Method Details
#directory_name ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 117 def directory_name @directory_name ||= if !published? && post_type == "post" "_drafts" else "_#{post_type}s" end end |
#excerpt ⇒ Object
129 130 131 132 133 134 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 129 def excerpt @excerpt ||= begin text = Nokogiri::HTML(text_for("excerpt:encoded")).text text.empty? ? nil : text end end |
#file_name ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 109 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
105 106 107 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 105 def parent_id @parent_id ||= text_for("wp:post_parent") end |
#permalink ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 81 def permalink @permalink ||= begin uri = text_for("link") uri = @node.at("link").next_sibling.text if uri.empty? URI(uri.to_s.strip).path end end |
#permalink_title ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 71 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
97 98 99 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 97 def post_password @post_password ||= text_for("wp:post_password") end |
#post_type ⇒ Object
101 102 103 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 101 def post_type @post_type ||= text_for("wp:post_type") end |
#published? ⇒ Boolean
125 126 127 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 125 def published? @published ||= (status == "publish") end |
#published_at ⇒ Object
89 90 91 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 89 def published_at @published_at ||= Time.parse(text_for("wp:post_date")) if published? end |
#status ⇒ Object
93 94 95 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 93 def status @status ||= text_for("wp:status") end |
#text_for(path) ⇒ Object
62 63 64 65 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 62 def text_for(path) subnode = @node.at_xpath("./#{path}") || @node.at(path) || @node.children.find { |child| child.name == path } subnode.text end |
#title ⇒ Object
67 68 69 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 67 def title @title ||= text_for("title").strip end |