Class: Refinery::WordPress::Page
- Inherits:
-
Object
- Object
- Refinery::WordPress::Page
- Includes:
- ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
- Defined in:
- lib/wordpress/page.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #content ⇒ Object
- #content_formatted ⇒ Object
- #creator ⇒ Object
- #draft? ⇒ Boolean
-
#initialize(node) ⇒ Page
constructor
A new instance of Page.
- #inspect ⇒ Object
- #parent_id ⇒ Object
- #post_date ⇒ Object
- #post_id ⇒ Object
- #published? ⇒ Boolean
- #status ⇒ Object
- #title ⇒ Object
- #to_refinery ⇒ Object
Constructor Details
#initialize(node) ⇒ Page
Returns a new instance of Page.
9 10 11 |
# File 'lib/wordpress/page.rb', line 9 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
7 8 9 |
# File 'lib/wordpress/page.rb', line 7 def node @node end |
Instance Method Details
#==(other) ⇒ Object
66 67 68 |
# File 'lib/wordpress/page.rb', line 66 def ==(other) post_id == other.post_id end |
#content ⇒ Object
21 22 23 |
# File 'lib/wordpress/page.rb', line 21 def content node.xpath("content:encoded").text end |
#content_formatted ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/wordpress/page.rb', line 25 def content_formatted formatted = format_syntax_highlighter(format_paragraphs(content)) # remove all tags inside <pre> that simple_format created # TODO: replace format_paragraphs with a method, that ignores pre-tags formatted.gsub!(/(<pre.*?>)(.+?)(<\/pre>)/m) do |match| "#{$1}#{($2)}#{$3}" end formatted end |
#creator ⇒ Object
37 38 39 |
# File 'lib/wordpress/page.rb', line 37 def creator node.xpath("dc:creator").text end |
#draft? ⇒ Boolean
58 59 60 |
# File 'lib/wordpress/page.rb', line 58 def draft? status != 'publish' end |
#inspect ⇒ Object
13 14 15 |
# File 'lib/wordpress/page.rb', line 13 def inspect "WordPress::Page(#{post_id}): #{title}" end |
#parent_id ⇒ Object
49 50 51 52 |
# File 'lib/wordpress/page.rb', line 49 def parent_id dump_id = node.xpath("wp:post_parent").text.to_i dump_id == 0 ? nil : dump_id end |
#post_date ⇒ Object
41 42 43 |
# File 'lib/wordpress/page.rb', line 41 def post_date DateTime.parse node.xpath("wp:post_date").text end |
#post_id ⇒ Object
45 46 47 |
# File 'lib/wordpress/page.rb', line 45 def post_id node.xpath("wp:post_id").text.to_i end |
#published? ⇒ Boolean
62 63 64 |
# File 'lib/wordpress/page.rb', line 62 def published? ! draft? end |
#status ⇒ Object
54 55 56 |
# File 'lib/wordpress/page.rb', line 54 def status node.xpath("wp:status").text end |
#title ⇒ Object
17 18 19 |
# File 'lib/wordpress/page.rb', line 17 def title node.xpath("title").text end |
#to_refinery ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/wordpress/page.rb', line 70 def to_refinery page = ::Page.create!(:id => post_id, :title => title, :created_at => post_date, :draft => draft?) page.parts.create(:title => 'Body', :body => content_formatted) page end |