Class: SemiStatic::Post
- Includes:
- Convertable
- Defined in:
- lib/semi-static/post.rb
Overview
Post represents a single post in the site. Post itself only represents a single source file, but can have a Layout and any number of Snippets, each of which has its own source file. Post’s modification time is the most recent of itself, its Layout, and any Snippets used.
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Date Post was created.
-
#name ⇒ Object
readonly
The Post’s name.
-
#output_dir ⇒ Object
readonly
The Post’s output directory.
-
#output_path ⇒ Object
readonly
The Post’s output path.
-
#slug ⇒ Object
readonly
The Post’s slug.
-
#tags ⇒ Object
readonly
The Post’s Tags.
-
#updated ⇒ Object
readonly
Date the Post was last updated.
-
#uri ⇒ Object
readonly
The Post’s URI.
Attributes inherited from Base
#full_source_path, #site, #source_content, #source_ext, #source_metadata, #source_path
Instance Method Summary collapse
-
#day ⇒ Object
Day the Post was published as a String (i.e., “15”).
-
#id ⇒ Object
Get the Post’s unique identifier.
-
#initialize(site, path) ⇒ Post
constructor
Initializes a new Post.
-
#month ⇒ Object
Month the Post was published as a String (i.e., “03”).
-
#permalink ⇒ Object
Get the Post’s permalink.
-
#time? ⇒ Boolean
Does the post have a Time set?.
-
#year ⇒ Object
Year the Post was published as a String (i.e., “2009”).
Methods included from Convertable
#content, #layout, #layout_name, #load, #object_ref, #render, #snippet, #source_mtime, #underscore
Methods inherited from Base
Constructor Details
#initialize(site, path) ⇒ Post
Initializes a new Post
site-
The Site object we belong to
path-
The relative path to the source file
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/semi-static/post.rb', line 50 def initialize(site, path) super @metadata = [ :title, :layout, :author ] @name = File.basename(source_path, source_ext) @tags = [] unless [:tags].nil? for tag in [:tags] @tags << site.[tag] @tags.last << self end end if name =~ /^(\d+-\d+-\d+)-(.+)$/ @created = Time.parse $1 @updated ||= @created @slug = $2 @output_dir = created.strftime('%Y/%m/%d') @output_path = File.join output_dir, "#{slug}.html" @uri = "/#{output_path}" else raise ArgumentError, "Bad file name: #{name}" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SemiStatic::Base
Instance Attribute Details
#created ⇒ Object (readonly)
Date Post was created
35 36 37 |
# File 'lib/semi-static/post.rb', line 35 def created @created end |
#name ⇒ Object (readonly)
The Post’s name
11 12 13 |
# File 'lib/semi-static/post.rb', line 11 def name @name end |
#output_dir ⇒ Object (readonly)
The Post’s output directory
19 20 21 |
# File 'lib/semi-static/post.rb', line 19 def output_dir @output_dir end |
#output_path ⇒ Object (readonly)
The Post’s output path
23 24 25 |
# File 'lib/semi-static/post.rb', line 23 def output_path @output_path end |
#slug ⇒ Object (readonly)
The Post’s slug
27 28 29 |
# File 'lib/semi-static/post.rb', line 27 def slug @slug end |
#tags ⇒ Object (readonly)
The Post’s Tags
15 16 17 |
# File 'lib/semi-static/post.rb', line 15 def @tags end |
#updated ⇒ Object (readonly)
Date the Post was last updated
39 40 41 |
# File 'lib/semi-static/post.rb', line 39 def updated @updated end |
#uri ⇒ Object (readonly)
The Post’s URI
31 32 33 |
# File 'lib/semi-static/post.rb', line 31 def uri @uri end |
Instance Method Details
#day ⇒ Object
Day the Post was published as a String (i.e., “15”)
102 103 104 |
# File 'lib/semi-static/post.rb', line 102 def day created.strftime '%d' end |
#id ⇒ Object
Get the Post’s unique identifier
78 79 80 |
# File 'lib/semi-static/post.rb', line 78 def id name.gsub /-/, '_' end |
#month ⇒ Object
Month the Post was published as a String (i.e., “03”)
96 97 98 |
# File 'lib/semi-static/post.rb', line 96 def month created.strftime '%m' end |
#permalink ⇒ Object
Get the Post’s permalink
84 85 86 |
# File 'lib/semi-static/post.rb', line 84 def permalink return "#{uri}" end |
#time? ⇒ Boolean
Does the post have a Time set?
108 109 110 |
# File 'lib/semi-static/post.rb', line 108 def time? false end |
#year ⇒ Object
Year the Post was published as a String (i.e., “2009”)
90 91 92 |
# File 'lib/semi-static/post.rb', line 90 def year created.strftime '%Y' end |