Class: Marko::Markup::Decorator

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/marko/markup/decorator.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj) ⇒ Decorator

Returns a new instance of Decorator.



10
11
12
13
# File 'lib/marko/markup/decorator.rb', line 10

def initialize(obj)
  super(obj)
  @macroproc = MacroProcPlug.plugged
end

Instance Method Details

#bodyObject



19
20
21
# File 'lib/marko/markup/decorator.rb', line 19

def body
  @macroproc.process(super, self).strip
end

#find_node(ref) ⇒ Object



29
30
31
32
33
# File 'lib/marko/markup/decorator.rb', line 29

def find_node(ref)
  obj = super(ref)
  return nil unless obj
  self.class.new(obj)
end

#metaHash

Returns metdata cleaned from system meta.

Returns:

  • (Hash)

    metdata cleaned from system meta



24
25
26
27
# File 'lib/marko/markup/decorator.rb', line 24

def meta
  super.dup.tap{|h| h.update(id: id)}
    .reject{|k,_| %i[origin parent order_index].include?(k)}
end

#propsObject

return [String] meta properties table



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/marko/markup/decorator.rb', line 47

def props
  meta.then{|h|
    klen = h.keys.map{ _1.to_s.size }.max + 4
    vlen = h.values.map(&:size).max
    mark = ?- * klen + ?\s + ?- * vlen
    h.map{|k, v| "__#{k.capitalize}__".ljust(klen) + ?\ + v }
      .unshift(mark)
      .push(mark)
      .join(?\n)
  }
end

#refObject



35
36
37
# File 'lib/marko/markup/decorator.rb', line 35

def ref
  "[#{title}](#{url})"
end

#textString

Returns decorated node content.

Returns:

  • (String)

    decorated node content



60
61
62
63
64
65
# File 'lib/marko/markup/decorator.rb', line 60

def text
  [ topic, props, body
  ].reject(&:empty?)
   .join("\n\n") +
   "\n\n"
end

#titleObject



15
16
17
# File 'lib/marko/markup/decorator.rb', line 15

def title
  super.then{|s| s.empty? ? ".#{id.split(/\./).last}" : s}
end

#topicString Also known as: header

Return header

Returns:

  • (String)

    return header



40
41
42
43
# File 'lib/marko/markup/decorator.rb', line 40

def topic
  return "% #{title}" if root?
  "#{'#' * nesting_level} #{title.strip} {#{url}}"
end