Class: Sawsge::Post

Inherits:
Page show all
Defined in:
lib/post.rb

Overview

A blogpost style HTML page

Instance Attribute Summary collapse

Attributes inherited from Page

#title

Attributes inherited from Resource

#path

Instance Method Summary collapse

Methods inherited from Page

#build

Methods inherited from Resource

#build

Constructor Details

#initialize(path) ⇒ Post

Returns a new instance of Post.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/post.rb', line 8

def initialize(path)
  super(path)

  # There's got to be a more idiomatic way to do this! The
  # current implementation is disguisting.
  # Also doesn't work if POSTS_DIRNAME is more than 2
  # directories
  parts = Pathname.new(@path).each_filename.to_a[1..]
  parts.delete(POSTS_DIRNAME)
  @date = "#{parts[0]}-#{parts[1]}-#{parts[2]}"
  @body.css('h1').first.add_next_sibling "<date>#{@date}</date>"

  # Look what's in <summary></summary>
  @summary = @document.css('summary').first.content
end

Instance Attribute Details

#dateObject (readonly)

Returns the value of attribute date.



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

def date
  @date
end

#summaryObject (readonly)

Returns the value of attribute summary.



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

def summary
  @summary
end