Class: JekyllImport::Importers::WordpressDotCom::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-import/importers/wordpressdotcom.rb

Instance Method Summary collapse

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_nameObject



105
106
107
108
109
110
111
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 105

def directory_name
  @directory_name ||= if !published? && post_type == "post"
                        "_drafts"
                      else
                        "_#{post_type}s"
                      end
end

#excerptObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 117

def excerpt
  @excerpt ||= begin
    text = Hpricot(text_for("excerpt:encoded")).inner_text
    if text.empty?
      nil
    else
      text
    end
  end
end

#file_nameObject



97
98
99
100
101
102
103
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 97

def file_name
  @file_name ||= if published?
                   "#{published_at.strftime("%Y-%m-%d")}-#{permalink_title}.html"
                 else
                   "#{permalink_title}.html"
                 end
end

#parent_idObject



93
94
95
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 93

def parent_id
  @parent_id ||= text_for("wp:post_parent")
end


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_passwordObject



85
86
87
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 85

def post_password
  @post_password ||= text_for("wp:post_password")
end

#post_typeObject



89
90
91
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 89

def post_type
  @post_type ||= text_for("wp:post_type")
end

#published?Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 113

def published?
  @published ||= (status == "publish")
end

#published_atObject



77
78
79
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 77

def published_at
  @published_at ||= Time.parse(text_for("wp:post_date")) if published?
end

#statusObject



81
82
83
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 81

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

#titleObject



63
64
65
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 63

def title
  @title ||= text_for(:title).strip
end