Class: Refinery::WordPress::Post
- Inherits:
-
Page
- Object
- Page
- Refinery::WordPress::Post
show all
- Defined in:
- lib/wordpress/post.rb
Instance Attribute Summary
Attributes inherited from Page
#node
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Page
#==, #content, #content_formatted, #creator, #draft?, #initialize, #inspect, #parent_id, #post_date, #post_id, #published?, #status, #title
Class Method Details
.create_blog_page_if_necessary ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/wordpress/post.rb', line 65
def self.create_blog_page_if_necessary
unless ::Page.where("link_url = ?", '/blog').exists?
page = ::Page.create(
:title => "Blog",
:link_url => "/blog",
:deletable => false,
:position => ((::Page.maximum(:position, :conditions => {:parent_id => nil}) || -1)+1),
:menu_match => "^/blogs?(\/|\/.+?|)$"
)
::Page.default_parts.each do |default_page_part|
page.parts.create(:title => default_page_part, :body => nil)
end
end
end
|
Instance Method Details
#categories ⇒ Object
21
22
23
24
25
|
# File 'lib/wordpress/post.rb', line 21
def categories
node.xpath("category[@domain='category']").collect do |cat|
Category.new(cat.text)
end
end
|
27
28
29
30
31
|
# File 'lib/wordpress/post.rb', line 27
def
node.xpath("wp:comment").collect do ||
Comment.new()
end
end
|
#tag_list ⇒ Object
17
18
19
|
# File 'lib/wordpress/post.rb', line 17
def tag_list
tags.collect(&:name).join(',')
end
|
4
5
6
7
8
9
10
11
12
13
14
15
|
# File 'lib/wordpress/post.rb', line 4
def tags
path = if node.xpath("category[@domain='post_tag']").count > 0
"category[@domain='post_tag']"
else
"category[@domain='tag']"
end
node.xpath(path).collect do |tag_node|
Tag.new(tag_node.text)
end
end
|
#to_refinery ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/wordpress/post.rb', line 33
def to_refinery
user = ::User.find_by_username(creator) || ::User.first
raise "Referenced User doesn't exist! Make sure the authors are imported first." \
unless user
begin
post = ::BlogPost.new :title => title, :body => content_formatted,
:draft => draft?, :published_at => post_date, :created_at => post_date,
:author => user, :tag_list => tag_list
post.save!
::BlogPost.transaction do
categories.each do |category|
post.categories << category.to_refinery
end
.each do ||
= .to_refinery
.post = post
.save
end
end
rescue ActiveRecord::RecordInvalid
post.title = "#{title}-#{post_id}"
post.save
end
post
end
|