Class: Woody::Post
- Inherits:
-
Object
- Object
- Woody::Post
- Defined in:
- lib/woody/post.rb
Overview
Represents a post
Direct Known Subclasses
Instance Attribute Summary collapse
-
#compiledname ⇒ Object
Returns the value of attribute compiledname.
-
#date ⇒ Object
Returns the value of attribute date.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#raw_body ⇒ Object
Returns the value of attribute raw_body.
-
#subtitle ⇒ Object
Returns the value of attribute subtitle.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #body(regenerate = false) ⇒ Object
- #has_file? ⇒ Boolean
-
#initialize(site, filename, title, subtitle, raw_body, date, tags = [], compiledname = nil) ⇒ Post
constructor
Creates a new Post object.
-
#keywords ⇒ String
A comma separated list of tags, or nil if no tags.
-
#path(leader = true) ⇒ Object
The Page’s page path where possible, otherwise false.
-
#path!(leader = true) ⇒ Object
The Page’s page path where possible, otherwise false.
-
#url ⇒ Object
The Page’s page URL where possible, otherwise false.
Constructor Details
#initialize(site, filename, title, subtitle, raw_body, date, tags = [], compiledname = nil) ⇒ Post
Creates a new Post object
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, = [], compiledname = nil) @site = site @filename = filename @title = title @subtitle = subtitle @raw_body = raw_body @date = date @tags = .nil? ? [] : @compiledname = @filename[6..-1].gsub(/[^0-9A-Za-z ._]/, '').gsub(' ', '_') end |
Instance Attribute Details
#compiledname ⇒ Object
Returns the value of attribute compiledname.
24 25 26 |
# File 'lib/woody/post.rb', line 24 def compiledname @compiledname end |
#date ⇒ Object
Returns the value of attribute date.
24 25 26 |
# File 'lib/woody/post.rb', line 24 def date @date end |
#filename ⇒ Object
Returns the value of attribute filename.
24 25 26 |
# File 'lib/woody/post.rb', line 24 def filename @filename end |
#raw_body ⇒ Object
Returns the value of attribute raw_body.
24 25 26 |
# File 'lib/woody/post.rb', line 24 def raw_body @raw_body end |
#subtitle ⇒ Object
Returns the value of attribute subtitle.
24 25 26 |
# File 'lib/woody/post.rb', line 24 def subtitle @subtitle end |
#tags ⇒ Object
Returns the value of attribute tags.
24 25 26 |
# File 'lib/woody/post.rb', line 24 def @tags end |
#title ⇒ Object
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
55 56 57 |
# File 'lib/woody/post.rb', line 55 def has_file? false end |
#keywords ⇒ String
Returns 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.
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.
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 |
#url ⇒ Object
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 |