Class: TreeMacro

Inherits:
MarkupMacro show all
Defined in:
lib/assets/lib/markup_macro.rb

Overview

Builds a tree of Node#items where items linked to appropriate headers

Instance Attribute Summary

Attributes inherited from MarkupMacro

#regex, #title

Instance Method Summary collapse

Constructor Details

#initializeTreeMacro

Returns a new instance of TreeMacro.



64
65
66
67
# File 'lib/assets/lib/markup_macro.rb', line 64

def initialize
  @title = "Tree"
  @regex = /{{@@tree}}/
end

Instance Method Details

#process(macro, node) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/assets/lib/markup_macro.rb', line 69

def process(macro, node)
  this_level = node.nesting_level + 1
  node.to_a.drop(1).inject([]) do |ary, n|
    lead_spaces = '   ' * (n.nesting_level - this_level)
    ary << "#{lead_spaces}* [#{n.title}](##{node.url(n.id)})"
  end.join("\n")
end