Class: Siru::Post
- Inherits:
-
Object
- Object
- Siru::Post
- Defined in:
- lib/siru/post.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#front_matter ⇒ Object
readonly
Returns the value of attribute front_matter.
-
#rendered_content ⇒ Object
readonly
Returns the value of attribute rendered_content.
Instance Method Summary collapse
- #date ⇒ Object
- #draft? ⇒ Boolean
-
#initialize(file_path) ⇒ Post
constructor
A new instance of Post.
- #slug ⇒ Object
- #summary ⇒ Object
- #tags ⇒ Object
- #title ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(file_path) ⇒ Post
5 6 7 8 |
# File 'lib/siru/post.rb', line 5 def initialize(file_path) @file_path = file_path parse_file end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
3 4 5 |
# File 'lib/siru/post.rb', line 3 def content @content end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
3 4 5 |
# File 'lib/siru/post.rb', line 3 def file_path @file_path end |
#front_matter ⇒ Object (readonly)
Returns the value of attribute front_matter.
3 4 5 |
# File 'lib/siru/post.rb', line 3 def front_matter @front_matter end |
#rendered_content ⇒ Object (readonly)
Returns the value of attribute rendered_content.
3 4 5 |
# File 'lib/siru/post.rb', line 3 def rendered_content @rendered_content end |
Instance Method Details
#date ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/siru/post.rb', line 14 def date date_str = @front_matter['date'] return Date.today unless date_str if date_str.is_a?(String) Date.parse(date_str) else date_str end end |
#draft? ⇒ Boolean
25 26 27 |
# File 'lib/siru/post.rb', line 25 def draft? @front_matter['draft'] == true end |
#slug ⇒ Object
29 30 31 |
# File 'lib/siru/post.rb', line 29 def slug @front_matter['slug'] || File.basename(@file_path, '.md') end |
#summary ⇒ Object
37 38 39 |
# File 'lib/siru/post.rb', line 37 def summary @front_matter['summary'] || @content.split("\n\n").first&.strip || '' end |
#tags ⇒ Object
41 42 43 |
# File 'lib/siru/post.rb', line 41 def @front_matter['tags'] || [] end |
#title ⇒ Object
10 11 12 |
# File 'lib/siru/post.rb', line 10 def title @front_matter['title'] || File.basename(@file_path, '.md').tr('-', ' ').capitalize end |
#url ⇒ Object
33 34 35 |
# File 'lib/siru/post.rb', line 33 def url "/posts/#{slug}/" end |