Class: Dimples::Post
- Inherits:
-
Object
- Object
- Dimples::Post
- Includes:
- Frontable, Renderable, Writeable
- Defined in:
- lib/dimples/post.rb
Instance Attribute Summary collapse
-
#categories ⇒ Object
Returns the value of attribute categories.
-
#contents ⇒ Object
Returns the value of attribute contents.
-
#date ⇒ Object
Returns the value of attribute date.
-
#day ⇒ Object
Returns the value of attribute day.
-
#draft ⇒ Object
Returns the value of attribute draft.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#layout ⇒ Object
Returns the value of attribute layout.
-
#month ⇒ Object
Returns the value of attribute month.
-
#next_post ⇒ Object
Returns the value of attribute next_post.
-
#path ⇒ Object
Returns the value of attribute path.
-
#previous_post ⇒ Object
Returns the value of attribute previous_post.
-
#rendered_contents ⇒ Object
Returns the value of attribute rendered_contents.
-
#slug ⇒ Object
Returns the value of attribute slug.
-
#template ⇒ Object
Returns the value of attribute template.
-
#title ⇒ Object
Returns the value of attribute title.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
-
#initialize(site, path) ⇒ Post
constructor
A new instance of Post.
- #output_path(parent_path) ⇒ Object
Methods included from Renderable
#build_scope, #render, #renderer
Methods included from Writeable
Methods included from Frontable
#apply_metadata, #read_with_yaml
Constructor Details
#initialize(site, path) ⇒ Post
Returns a new instance of Post.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dimples/post.rb', line 25 def initialize(site, path) @site = site @path = path @filename = 'index' @extension = 'html' date_format = /(\d{4})-(\d{2})-(\d{2})-(.+)/ parts = File.basename(path, File.extname(path)).match(date_format) @slug = parts[4] @date = Time.mktime(parts[1], parts[2], parts[3]) @layout = @site.config['layouts']['post'] @categories = {} @draft = false @year = @date.strftime('%Y') @month = @date.strftime('%m') @day = @date.strftime('%d') @contents = read_with_yaml(path) end |
Instance Attribute Details
#categories ⇒ Object
Returns the value of attribute categories.
9 10 11 |
# File 'lib/dimples/post.rb', line 9 def categories @categories end |
#contents ⇒ Object
Returns the value of attribute contents.
14 15 16 |
# File 'lib/dimples/post.rb', line 14 def contents @contents end |
#date ⇒ Object
Returns the value of attribute date.
16 17 18 |
# File 'lib/dimples/post.rb', line 16 def date @date end |
#day ⇒ Object
Returns the value of attribute day.
19 20 21 |
# File 'lib/dimples/post.rb', line 19 def day @day end |
#draft ⇒ Object
Returns the value of attribute draft.
23 24 25 |
# File 'lib/dimples/post.rb', line 23 def draft @draft end |
#extension ⇒ Object
Returns the value of attribute extension.
12 13 14 |
# File 'lib/dimples/post.rb', line 12 def extension @extension end |
#filename ⇒ Object
Returns the value of attribute filename.
11 12 13 |
# File 'lib/dimples/post.rb', line 11 def filename @filename end |
#layout ⇒ Object
Returns the value of attribute layout.
13 14 15 |
# File 'lib/dimples/post.rb', line 13 def layout @layout end |
#month ⇒ Object
Returns the value of attribute month.
18 19 20 |
# File 'lib/dimples/post.rb', line 18 def month @month end |
#next_post ⇒ Object
Returns the value of attribute next_post.
22 23 24 |
# File 'lib/dimples/post.rb', line 22 def next_post @next_post end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/dimples/post.rb', line 7 def path @path end |
#previous_post ⇒ Object
Returns the value of attribute previous_post.
21 22 23 |
# File 'lib/dimples/post.rb', line 21 def previous_post @previous_post end |
#rendered_contents ⇒ Object
Returns the value of attribute rendered_contents.
20 21 22 |
# File 'lib/dimples/post.rb', line 20 def rendered_contents @rendered_contents end |
#slug ⇒ Object
Returns the value of attribute slug.
15 16 17 |
# File 'lib/dimples/post.rb', line 15 def slug @slug end |
#template ⇒ Object
Returns the value of attribute template.
10 11 12 |
# File 'lib/dimples/post.rb', line 10 def template @template end |
#title ⇒ Object
Returns the value of attribute title.
8 9 10 |
# File 'lib/dimples/post.rb', line 8 def title @title end |
#year ⇒ Object
Returns the value of attribute year.
17 18 19 |
# File 'lib/dimples/post.rb', line 17 def year @year end |
Instance Method Details
#output_path(parent_path) ⇒ Object
50 51 52 53 |
# File 'lib/dimples/post.rb', line 50 def output_path(parent_path) parent_path = @date.strftime(parent_path) if parent_path =~ /%/ File.join([parent_path, @slug.to_s, "#{@filename}.#{@extension}"]) end |