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
78 79 80 |
# File 'lib/wordpress/page.rb', line 78 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 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/wordpress/page.rb', line 25 def content_formatted # WordPress doesn't export <p>-Tags, so let's run a simple_format over # the content. As we trust ourselves, no sanatize. formatted = simple_format(content, {}, { :sanitize => false }) # Support for SyntaxHighlighter (http://alexgorbatchev.com/SyntaxHighlighter/): # In WordPress you can (via a plugin) enclose code in [lang][/lang] # blocks, which are converted to a <pre>-tag with a class corresponding # to the language. # # Example: # [ruby]p "Hello World"[/ruby] # -> <pre class="brush: ruby">p "Hello world"</pre> formatted.gsub!(/\[(\w+)\]/, '<pre class="brush: \1">') formatted.gsub!(/\[\/\w+\]/, '</pre>') # remove all tags inside <pre> that simple_format created # TODO: replace simple_format with a method, that ignores pre-tags formatted.gsub!(/(<pre.*?>)(.+?)(<\/pre>)/m) do |match| "#{$1}#{($2)}#{$3}" end formatted end |
#creator ⇒ Object
50 51 52 |
# File 'lib/wordpress/page.rb', line 50 def creator node.xpath("dc:creator").text end |
#draft? ⇒ Boolean
70 71 72 |
# File 'lib/wordpress/page.rb', line 70 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
62 63 64 |
# File 'lib/wordpress/page.rb', line 62 def parent_id node.xpath("wp:post_parent").text.to_i end |
#post_date ⇒ Object
54 55 56 |
# File 'lib/wordpress/page.rb', line 54 def post_date DateTime.parse node.xpath("wp:post_date").text end |
#post_id ⇒ Object
58 59 60 |
# File 'lib/wordpress/page.rb', line 58 def post_id node.xpath("wp:post_id").text.to_i end |
#published? ⇒ Boolean
74 75 76 |
# File 'lib/wordpress/page.rb', line 74 def published? ! draft? end |
#status ⇒ Object
66 67 68 |
# File 'lib/wordpress/page.rb', line 66 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
82 83 84 85 86 87 88 |
# File 'lib/wordpress/page.rb', line 82 def to_refinery page = ::Page.create!(:title => title, :created_at => post_date, :draft => draft?, :parent_id => parent_id) page.parts.create(:title => 'Body', :body => content_formatted) page end |