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.
- #permalink_title ⇒ 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.
54 55 56 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 54 def initialize(node) @node = node end |
Instance Method Details
#directory_name ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 98 def directory_name @directory_name ||= if !published? && post_type == 'post' '_drafts' else "_#{post_type}s" end end |
#excerpt ⇒ Object
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 110 def excerpt @excerpt ||= begin text = Hpricot(text_for('excerpt:encoded')).inner_text if text.empty? nil else text end end end |
#file_name ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 90 def file_name @file_name ||= if published? "#{published_at.strftime('%Y-%m-%d')}-#{permalink_title}.html" else "#{permalink_title}.html" end end |
#permalink_title ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 66 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_type ⇒ Object
86 87 88 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 86 def post_type @post_type ||= text_for('wp:post_type') end |
#published? ⇒ Boolean
106 107 108 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 106 def published? @published ||= (status == 'publish') end |
#published_at ⇒ Object
76 77 78 79 80 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 76 def published_at if published? @published_at ||= Time.parse(text_for('wp:post_date')) end end |
#status ⇒ Object
82 83 84 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 82 def status @status ||= text_for('wp:status') end |
#text_for(path) ⇒ Object
58 59 60 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 58 def text_for(path) @node.at(path).inner_text end |
#title ⇒ Object
62 63 64 |
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 62 def title @title ||= text_for(:title).strip end |