Class: Refinery::WordPress::Page

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
Defined in:
lib/wordpress/page.rb

Direct Known Subclasses

Post

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nodeObject (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

#contentObject



21
22
23
# File 'lib/wordpress/page.rb', line 21

def content
  node.xpath("content:encoded").text
end

#content_formattedObject



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}#{strip_tags($2)}#{$3}"
  end
    
  formatted
end

#creatorObject



37
38
39
# File 'lib/wordpress/page.rb', line 37

def creator
  node.xpath("dc:creator").text
end

#draft?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/wordpress/page.rb', line 58

def draft?
  status != 'publish'
end

#inspectObject



13
14
15
# File 'lib/wordpress/page.rb', line 13

def inspect
  "WordPress::Page(#{post_id}): #{title}"     
end

#parent_idObject



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_dateObject



41
42
43
# File 'lib/wordpress/page.rb', line 41

def 
  DateTime.parse node.xpath("wp:post_date").text
end

#post_idObject



45
46
47
# File 'lib/wordpress/page.rb', line 45

def post_id
  node.xpath("wp:post_id").text.to_i
end

#published?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/wordpress/page.rb', line 62

def published?
  ! draft?
end

#statusObject



54
55
56
# File 'lib/wordpress/page.rb', line 54

def status
  node.xpath("wp:status").text
end

#titleObject



17
18
19
# File 'lib/wordpress/page.rb', line 17

def title
  node.xpath("title").text
end

#to_refineryObject



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 => , :draft => draft?)

  page.parts.create(:title => 'Body', :body => content_formatted)
  page
end