Class: OakTree::Template::Post
- Inherits:
-
Base
- Object
- Mustache
- Base
- OakTree::Template::Post
show all
- Defined in:
- lib/oaktree/template/post.rb
Constant Summary
Constants inherited
from Base
Base::DEFAULT_DATETIME_FORMAT
Instance Method Summary
collapse
Methods inherited from Base
#proc_for_datetime
Constructor Details
#initialize(spec, post) ⇒ Post
Returns a new instance of Post.
13
14
15
16
17
18
19
20
|
# File 'lib/oaktree/template/post.rb', line 13
def initialize spec, post
@post = post
@content = nil
@spec = spec
document = ::Kramdown::Document.new(@post.content)
@content, warnings = ::OakTree::Kramdown::OakHtml.convert(document.root, :auto_id_prefix => @post.time.strftime('%Y_%m_%d_'))
puts warnings unless warnings.empty?
end
|
Instance Method Details
#[](key) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/oaktree/template/post.rb', line 91
def [](key)
if respond_to?(key)
send(key)
elsif key.to_s.end_with?('?')
key = case key
when Symbol then key.to_s.chomp('?').to_sym
when String then key.to_s.chomp('?')
else raise "Not sure what has happened here"
end
respond_to?(key) || @post.metadata.include?(key)
else
@post.metadata[key]
end
end
|
#content ⇒ Object
59
60
61
|
# File 'lib/oaktree/template/post.rb', line 59
def content
@content
end
|
#has_key?(key) ⇒ Boolean
87
88
89
|
# File 'lib/oaktree/template/post.rb', line 87
def has_key?(key)
respond_to?(key) || @post.metadata.include?(key) || key.to_s.end_with?('?')
end
|
#permalink ⇒ Object
38
39
40
|
# File 'lib/oaktree/template/post.rb', line 38
def permalink
@post.permalink
end
|
#post? ⇒ Boolean
55
56
57
|
# File 'lib/oaktree/template/post.rb', line 55
def post?
@post.kind == :post
end
|
#post_data ⇒ Object
22
23
24
|
# File 'lib/oaktree/template/post.rb', line 22
def post_data
@post
end
|
#public_path ⇒ Object
67
68
69
|
# File 'lib/oaktree/template/post.rb', line 67
def public_path
@post.public_path
end
|
#published? ⇒ Boolean
75
76
77
|
# File 'lib/oaktree/template/post.rb', line 75
def published?
@post.status == :published
end
|
#slug ⇒ Object
71
72
73
|
# File 'lib/oaktree/template/post.rb', line 71
def slug
@post.slug
end
|
#source_link ⇒ Object
42
43
44
|
# File 'lib/oaktree/template/post.rb', line 42
def source_link
@post.link
end
|
#source_link? ⇒ Boolean
46
47
48
49
|
# File 'lib/oaktree/template/post.rb', line 46
def source_link?
plink = @post.link
! (plink.nil? || plink.empty?)
end
|
#static? ⇒ Boolean
51
52
53
|
# File 'lib/oaktree/template/post.rb', line 51
def static?
@post.kind == :static
end
|
#status ⇒ Object
83
84
85
|
# File 'lib/oaktree/template/post.rb', line 83
def status
@post.status
end
|
#time ⇒ Object
63
64
65
|
# File 'lib/oaktree/template/post.rb', line 63
def time
proc_for_datetime(@post.time)
end
|
#title ⇒ Object
26
27
28
|
# File 'lib/oaktree/template/post.rb', line 26
def title
@post.title
end
|
#unpublished? ⇒ Boolean
79
80
81
|
# File 'lib/oaktree/template/post.rb', line 79
def unpublished?
! published?
end
|
#url ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/oaktree/template/post.rb', line 30
def url
if source_link?
source_link
else
permalink
end
end
|