Class: Lilliput::Post
- Inherits:
-
Object
- Object
- Lilliput::Post
- Defined in:
- lib/lilliput.rb
Instance Method Summary collapse
- #==(other_post) ⇒ Object
- #author ⇒ Object
- #content ⇒ Object
- #email ⇒ Object
- #html ⇒ Object
-
#initialize(path) ⇒ Post
constructor
A new instance of Post.
- #next ⇒ Object
- #previous ⇒ Object
- #published? ⇒ Boolean
- #published_on ⇒ Object
- #slug ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(path) ⇒ Post
Returns a new instance of Post.
28 29 30 |
# File 'lib/lilliput.rb', line 28 def initialize(path) @path = path end |
Instance Method Details
#==(other_post) ⇒ Object
78 79 80 |
# File 'lib/lilliput.rb', line 78 def ==(other_post) slug == other_post.slug end |
#author ⇒ Object
45 46 47 |
# File 'lib/lilliput.rb', line 45 def credentials[0] || Lilliput. end |
#content ⇒ Object
62 63 64 |
# File 'lib/lilliput.rb', line 62 def content strip_off_blank_lines(lines[1..-1]).join("\n") end |
#email ⇒ Object
49 50 51 |
# File 'lib/lilliput.rb', line 49 def email credentials[1] || Lilliput.email end |
#html ⇒ Object
66 67 68 |
# File 'lib/lilliput.rb', line 66 def html Maruku.new(content).to_html end |
#next ⇒ Object
74 75 76 |
# File 'lib/lilliput.rb', line 74 def next Lilliput.all[post_nr - 1] unless post_nr <= 0 end |
#previous ⇒ Object
70 71 72 |
# File 'lib/lilliput.rb', line 70 def previous Lilliput.all[post_nr + 1] end |
#published? ⇒ Boolean
37 38 39 |
# File 'lib/lilliput.rb', line 37 def published? published_on < Date.today end |
#published_on ⇒ Object
32 33 34 35 |
# File 'lib/lilliput.rb', line 32 def published_on date = filename.match(/^([\d]{4}-[\d]{2}-[\d]{2})/)[1] Date.parse(date) if date end |
#slug ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/lilliput.rb', line 53 def slug slug = filename.match(/^[\d]{4}-[\d]{2}-[\d]{2}-([a-z0-9\-]+)/i) if slug slug[1] else lines.first.downcase.gsub(/[^a-z0-9\-]/, '-').gsub(/^\-*(.*?)\-*$/, '\1') end end |
#title ⇒ Object
41 42 43 |
# File 'lib/lilliput.rb', line 41 def title lines.first.chomp end |