2011-06-02 12:41:31 +00:00
|
|
|
module Refinery
|
|
|
|
module WordPress
|
|
|
|
class Post < Page
|
|
|
|
def tags
|
|
|
|
node.xpath("category[@domain='post_tag']").collect do |tag_node|
|
|
|
|
Tag.new(tag_node.text)
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
def tag_list
|
|
|
|
tags.collect(&:name).join(',')
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
def categories
|
|
|
|
node.xpath("category[@domain='category']").collect do |cat|
|
|
|
|
Category.new(cat.text)
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
def comments
|
|
|
|
node.xpath("wp:comment").collect do |comment_node|
|
|
|
|
Comment.new(comment_node)
|
|
|
|
end
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
def to_refinery
|
|
|
|
user = ::User.find_by_username creator
|
|
|
|
raise "Referenced User doesn't exist! Make sure the authors are imported first." \
|
|
|
|
unless user
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
post = BlogPost.new
|
2011-06-01 19:11:57 +00:00
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
|
2011-06-02 14:22:50 +00:00
|
|
|
post = ::BlogPost.create! :title => title, :body => content_formatted, :draft => draft?,
|
2011-06-02 12:41:31 +00:00
|
|
|
:published_at => post_date, :created_at => post_date, :author => user,
|
|
|
|
:tag_list => tag_list
|
|
|
|
|
|
|
|
::BlogPost.transaction do
|
|
|
|
categories.each do |category|
|
|
|
|
post.categories << category.to_refinery
|
|
|
|
end
|
|
|
|
|
|
|
|
comments.each do |comment|
|
|
|
|
comment = comment.to_refinery
|
|
|
|
comment.post = post
|
|
|
|
comment.save
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
|
2011-06-02 12:41:31 +00:00
|
|
|
post
|
|
|
|
end
|
2011-06-01 19:11:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|