Class: Woody::Post

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

Overview

Represents a post

Direct Known Subclasses

Episode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, filename, title, subtitle, raw_body, date, tags = [], compiledname = nil) ⇒ Post

Creates a new Post object

Parameters:

  • filename (String)

    specifies the name of the post file

  • title (String)

    specifies the Post’s title

  • subtitle (String)

    specifies the Post’s subtitle

  • body (String)

    specifies the Post’s body

  • date (Date)

    specifies the Post’s published date

  • tags (Array) (defaults to: [])

    specifies the Post’s tags - each element is a String



14
15
16
17
18
19
20
21
22
23
# File 'lib/woody/post.rb', line 14

def initialize(site, filename, title, subtitle, raw_body, date, tags = [], compiledname = nil)
  @site = site
  @filename = filename
  @title = title
  @subtitle = subtitle
  @raw_body = raw_body
  @date = date
  @tags = tags.nil? ? [] : tags
  @compiledname = @filename[6..-1].gsub(/[^0-9A-Za-z ._]/, '').gsub(' ', '_')
end

Instance Attribute Details

#compilednameObject

Returns the value of attribute compiledname.



24
25
26
# File 'lib/woody/post.rb', line 24

def compiledname
  @compiledname
end

#dateObject

Returns the value of attribute date.



24
25
26
# File 'lib/woody/post.rb', line 24

def date
  @date
end

#filenameObject

Returns the value of attribute filename.



24
25
26
# File 'lib/woody/post.rb', line 24

def filename
  @filename
end

#raw_bodyObject

Returns the value of attribute raw_body.



24
25
26
# File 'lib/woody/post.rb', line 24

def raw_body
  @raw_body
end

#subtitleObject

Returns the value of attribute subtitle.



24
25
26
# File 'lib/woody/post.rb', line 24

def subtitle
  @subtitle
end

#tagsObject

Returns the value of attribute tags.



24
25
26
# File 'lib/woody/post.rb', line 24

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



24
25
26
# File 'lib/woody/post.rb', line 24

def title
  @title
end

Instance Method Details

#<=>(other) ⇒ Object



59
60
61
# File 'lib/woody/post.rb', line 59

def <=> (other)
  other.date <=> self.date
end

#body(regenerate = false) ⇒ Object



26
27
28
29
# File 'lib/woody/post.rb', line 26

def body(regenerate = false)
  return @body unless @body.nil? or regenerate
  return @body = Kramdown::Document.new(@raw_body).to_html
end

#has_file?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/woody/post.rb', line 55

def has_file?
  false
end

#keywordsString

Returns a comma separated list of tags, or nil if no tags.

Returns:

  • (String)

    a comma separated list of tags, or nil if no tags



51
52
53
# File 'lib/woody/post.rb', line 51

def keywords
  @tags.join ', ' unless @tags.nil? or @tags.empty?
end

#path(leader = true) ⇒ Object

Returns the Page’s page path where possible, otherwise false. Includes the site prefix if enabled.

Returns:

  • the Page’s page path where possible, otherwise false. Includes the site prefix if enabled.



44
45
46
47
48
# File 'lib/woody/post.rb', line 44

def path(leader=true)
  prefix = @site.config['s3']['prefix']
  return "#{leader ? "/" : ""}#{prefix.nil? ? "" : prefix + "/" }post/#{@compiledname.chomp(File.extname(@compiledname))}.html" unless @compiledname.nil?
  return false
end

#path!(leader = true) ⇒ Object

Returns the Page’s page path where possible, otherwise false. Does not take prefix in to account.

Returns:

  • the Page’s page path where possible, otherwise false. Does not take prefix in to account.



38
39
40
41
# File 'lib/woody/post.rb', line 38

def path!(leader=true)
  return "#{leader ? "/" : ""}post/#{@compiledname.chomp(File.extname(@compiledname))}.html" unless @compiledname.nil?
  return false
end

#urlObject

Returns the Page’s page URL where possible, otherwise false.

Returns:

  • the Page’s page URL where possible, otherwise false



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

def url
  return "#{@site.config['urlbase']}#{path!}" unless path! == false
  return false
end