Class: Tufte::Post
- Inherits:
-
Object
- Object
- Tufte::Post
- Defined in:
- lib/tufte/post.rb
Instance Attribute Summary collapse
-
#slug ⇒ Object
readonly
Returns the value of attribute slug.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #body ⇒ Object
- #date ⇒ Object
-
#initialize(date:, title:, slug:, raw_body:) ⇒ Post
constructor
A new instance of Post.
- #output_directory ⇒ Object
- #output_filename ⇒ Object
Constructor Details
#initialize(date:, title:, slug:, raw_body:) ⇒ Post
7 8 9 10 11 12 |
# File 'lib/tufte/post.rb', line 7 def initialize(date:, title:, slug:, raw_body:) @date = date @slug = slug @title = title @raw_body = raw_body end |
Instance Attribute Details
#slug ⇒ Object (readonly)
Returns the value of attribute slug.
5 6 7 |
# File 'lib/tufte/post.rb', line 5 def slug @slug end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
5 6 7 |
# File 'lib/tufte/post.rb', line 5 def title @title end |
Class Method Details
.load(filename) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tufte/post.rb', line 30 def self.load(filename) file_contents = File.read(filename) = YAML.load(file_contents) new( date: .fetch("date"), title: .fetch("title"), slug: File.basename(filename, ".yml"), raw_body: file_contents.split("---\n", 3).last, ) end |
Instance Method Details
#body ⇒ Object
14 15 16 |
# File 'lib/tufte/post.rb', line 14 def body Markdown.new(@raw_body).to_html end |
#date ⇒ Object
18 19 20 |
# File 'lib/tufte/post.rb', line 18 def date @date.strftime("%Y %b %-d") end |
#output_directory ⇒ Object
22 23 24 |
# File 'lib/tufte/post.rb', line 22 def output_directory File.join(@date.year.to_s, @date.month.to_s, @date.day.to_s, slug) end |
#output_filename ⇒ Object
26 27 28 |
# File 'lib/tufte/post.rb', line 26 def output_filename File.join(output_directory, "index.html") end |