Class: Lilliput::Post

Inherits:
Object
  • Object
show all
Defined in:
lib/lilliput.rb

Instance Method Summary collapse

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

#authorObject



45
46
47
# File 'lib/lilliput.rb', line 45

def author
  credentials[0] || Lilliput.author
end

#contentObject



62
63
64
# File 'lib/lilliput.rb', line 62

def content
  strip_off_blank_lines(lines[1..-1]).join("\n")
end

#emailObject



49
50
51
# File 'lib/lilliput.rb', line 49

def email
  credentials[1] || Lilliput.email
end

#htmlObject



66
67
68
# File 'lib/lilliput.rb', line 66

def html
  Maruku.new(content).to_html
end

#nextObject



74
75
76
# File 'lib/lilliput.rb', line 74

def next
  Lilliput.all[post_nr - 1] unless post_nr <= 0
end

#previousObject



70
71
72
# File 'lib/lilliput.rb', line 70

def previous
  Lilliput.all[post_nr + 1]
end

#published?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/lilliput.rb', line 37

def published?
  published_on < Date.today
end

#published_onObject



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

#slugObject



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

#titleObject



41
42
43
# File 'lib/lilliput.rb', line 41

def title
  lines.first.chomp
end