Class: WP2Middleman::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/wp2middleman/post.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nokogiri_post_doc) ⇒ Post

Returns a new instance of Post.



7
8
9
# File 'lib/wp2middleman/post.rb', line 7

def initialize(nokogiri_post_doc)
  @post = nokogiri_post_doc
end

Instance Attribute Details

#postObject

Returns the value of attribute post.



5
6
7
# File 'lib/wp2middleman/post.rb', line 5

def post
  @post
end

Instance Method Details

#contentObject



45
46
47
# File 'lib/wp2middleman/post.rb', line 45

def content
  post.at_xpath(".//content:encoded").inner_text
end

#date_publishedObject



29
30
31
# File 'lib/wp2middleman/post.rb', line 29

def date_published
  Date.parse().to_s
end

#filenameObject



21
22
23
# File 'lib/wp2middleman/post.rb', line 21

def filename
  "#{date_published}-#{title_for_filename}"
end

#markdown_contentObject



49
50
51
52
53
54
55
56
57
58
# File 'lib/wp2middleman/post.rb', line 49

def markdown_content
  html = HTMLPage.new :contents => content
  html.comment do |node,_|
    "#{node}"
  end
  html.iframe do |node,_|
    "#{node}"
  end
  html.markdown
end

#post_dateObject



25
26
27
# File 'lib/wp2middleman/post.rb', line 25

def 
  post.xpath("wp:post_date").first.inner_text
end

#published?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/wp2middleman/post.rb', line 41

def published?
  status == 'publish'
end

#statusObject



33
34
35
# File 'lib/wp2middleman/post.rb', line 33

def status
  post.xpath("wp:status").first.inner_text
end

#tagsObject



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/wp2middleman/post.rb', line 60

def tags
  tags = []
  categories = post.xpath("category")

  categories.each do |category|
    tag_name = category.css("@nicename").text

    tags.push tag_name unless tag_name == 'uncategorized'
  end

  tags
end

#titleObject



11
12
13
# File 'lib/wp2middleman/post.rb', line 11

def title
  post.css('title').text
end

#title_for_filenameObject



15
16
17
18
19
# File 'lib/wp2middleman/post.rb', line 15

def title_for_filename
  title.gsub(/[^\w\s_-]+/, '')
  .gsub(/(^|\b\s)\s+($|\s?\b)/, '\\1\\2')
  .gsub(/\s+/, '-')
end

#typeObject



37
38
39
# File 'lib/wp2middleman/post.rb', line 37

def type
  post.xpath("wp:post_type").first.inner_text
end