Class: OakTree::Template::Post

Inherits:
Base
  • Object
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..include?(key)
  else
    @post.[key]
  end
end

#contentObject



59
60
61
# File 'lib/oaktree/template/post.rb', line 59

def content
  @content
end

#has_key?(key) ⇒ Boolean

Returns:

  • (Boolean)


87
88
89
# File 'lib/oaktree/template/post.rb', line 87

def has_key?(key)
  respond_to?(key) || @post..include?(key) || key.to_s.end_with?('?')
end


38
39
40
# File 'lib/oaktree/template/post.rb', line 38

def permalink
  @post.permalink
end

#post?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/oaktree/template/post.rb', line 55

def post?
  @post.kind == :post
end

#post_dataObject



22
23
24
# File 'lib/oaktree/template/post.rb', line 22

def post_data
  @post
end

#public_pathObject



67
68
69
# File 'lib/oaktree/template/post.rb', line 67

def public_path
  @post.public_path
end

#published?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/oaktree/template/post.rb', line 75

def published?
  @post.status == :published
end

#slugObject



71
72
73
# File 'lib/oaktree/template/post.rb', line 71

def slug
  @post.slug
end


42
43
44
# File 'lib/oaktree/template/post.rb', line 42

def source_link
  @post.link
end

#source_link?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


51
52
53
# File 'lib/oaktree/template/post.rb', line 51

def static?
  @post.kind == :static
end

#statusObject



83
84
85
# File 'lib/oaktree/template/post.rb', line 83

def status
  @post.status
end

#timeObject



63
64
65
# File 'lib/oaktree/template/post.rb', line 63

def time
  proc_for_datetime(@post.time)
end

#titleObject



26
27
28
# File 'lib/oaktree/template/post.rb', line 26

def title
  @post.title
end

#unpublished?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/oaktree/template/post.rb', line 79

def unpublished?
  ! published?
end

#urlObject



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