2011-06-02 12:41:31 +00:00
|
|
|
module Refinery
|
|
|
|
module WordPress
|
|
|
|
class Dump
|
|
|
|
attr_reader :doc
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
def initialize(file_name)
|
|
|
|
file_name = File.absolute_path(file_name)
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
raise "Given file '#{file_name}' no file or not readable." \
|
|
|
|
unless File.file?(file_name) && File.readable?(file_name)
|
|
|
|
|
|
|
|
file = File.open(file_name)
|
|
|
|
@doc = Nokogiri::XML(file)
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
def authors
|
|
|
|
doc.xpath("//wp:author").collect do |author|
|
|
|
|
Author.new(author)
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-03 16:50:27 +00:00
|
|
|
def pages(only_published=false)
|
|
|
|
pages = doc.xpath("//item[wp:post_type = 'page']").collect do |page|
|
2011-06-02 12:41:31 +00:00
|
|
|
Page.new(page)
|
|
|
|
end
|
2011-06-03 16:50:27 +00:00
|
|
|
|
|
|
|
pages = pages.select(&:published?) if only_published
|
|
|
|
pages
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-03 09:35:11 +00:00
|
|
|
def posts(only_published=false)
|
|
|
|
posts = doc.xpath("//item[wp:post_type = 'post']").collect do |post|
|
2011-06-02 12:41:31 +00:00
|
|
|
Post.new(post)
|
|
|
|
end
|
2011-06-03 09:35:11 +00:00
|
|
|
posts = posts.select(&:published?) if only_published
|
|
|
|
posts
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
def tags
|
|
|
|
doc.xpath("//wp:tag/wp:tag_slug").collect do |tag|
|
|
|
|
Tag.new(tag.text)
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
def categories
|
|
|
|
doc.xpath("//wp:category/wp:cat_name").collect do |category|
|
|
|
|
Category.new(category.text)
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
2011-06-05 15:43:30 +00:00
|
|
|
|
|
|
|
def attachments
|
|
|
|
doc.xpath("//item[wp:post_type = 'attachment']").collect do |attachment|
|
|
|
|
Attachment.new(attachment)
|
|
|
|
end
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|