Class: Marko::Markup::Decorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Marko::Markup::Decorator
- Defined in:
- lib/marko/markup/decorator.rb
Instance Method Summary collapse
- #body ⇒ Object
- #find_node(ref) ⇒ Object
-
#initialize(obj) ⇒ Decorator
constructor
A new instance of Decorator.
-
#meta ⇒ Hash
Metdata cleaned from system meta.
-
#props ⇒ Object
return [String] meta properties table.
- #ref ⇒ Object
-
#text ⇒ String
Decorated node content.
- #title ⇒ Object
-
#topic ⇒ String
(also: #header)
Return header.
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
#body ⇒ Object
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 |
#meta ⇒ Hash
Returns metdata cleaned from system meta.
24 25 26 27 |
# File 'lib/marko/markup/decorator.rb', line 24 def super.dup.tap{|h| h.update(id: id)} .reject{|k,_| %i[origin parent order_index].include?(k)} end |
#props ⇒ Object
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 .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 |
#ref ⇒ Object
35 36 37 |
# File 'lib/marko/markup/decorator.rb', line 35 def ref "[#{title}](#{url})" end |
#text ⇒ String
Returns 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 |
#title ⇒ Object
15 16 17 |
# File 'lib/marko/markup/decorator.rb', line 15 def title super.then{|s| s.empty? ? ".#{id.split(/\./).last}" : s} end |
#topic ⇒ String Also known as: header
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 |