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.



56
57
58
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 56

def initialize(node)
  @node = node
end

Instance Method Details

#directory_nameObject



108
109
110
111
112
113
114
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 108

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

#excerptObject



120
121
122
123
124
125
126
127
128
129
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 120

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

#file_nameObject



100
101
102
103
104
105
106
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 100

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

#parent_idObject



96
97
98
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 96

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

#passwordObject



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

def password
  @post_password ||= text_for('wp:post_password')
end


68
69
70
71
72
73
74
75
76
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 68

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_typeObject



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

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

#published?Boolean

Returns:

  • (Boolean)


116
117
118
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 116

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

#published_atObject



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

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

#statusObject



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

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

#text_for(path) ⇒ Object



60
61
62
# File 'lib/jekyll-import/importers/wordpressdotcom.rb', line 60

def text_for(path)
  @node.at(path).inner_text
end

#titleObject



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

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