Class: NanDoc::Helpers::NanDocHelpers::SiteMap Private

Inherits:
Object
  • Object
show all
Extended by:
BlockAttrAccessor, SharedAttrReader
Includes:
Glyphs, SecretParent
Defined in:
lib/nandoc/helpers/site-map.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Modules: Glyphs

Constant Summary

Constants included from Glyphs

Glyphs::ArcUpL, Glyphs::Blank, Glyphs::DashQV, Glyphs::DownLf, Glyphs::DownRt, Glyphs::HvVert, Glyphs::HvVtLf, Glyphs::UpLeft, Glyphs::UpRite, Glyphs::UseThisForBlanks, Glyphs::VertLf, Glyphs::VertRt, Glyphs::Vertic, Glyphs::VtHori

Instance Attribute Summary collapse

Attributes included from BlockAttrAccessor

#block_attr_accessors

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedAttrReader

shared_attr_reader

Methods included from BlockAttrAccessor

block_attr_accessor, extended

Methods included from Glyphs

#glyphs_right, #glyphs_right_for_child

Methods included from SecretParent

#parent, #parent=, #parent?

Constructor Details

#initializeSiteMap

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of SiteMap.



37
38
39
# File 'lib/nandoc/helpers/site-map.rb', line 37

def initialize
  @tab = '  '
end

Instance Attribute Details

#glyphsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/nandoc/helpers/site-map.rb', line 40

def glyphs
  @glyphs
end

#is_firstObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/nandoc/helpers/site-map.rb', line 40

def is_first
  @is_first
end

#is_lastObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/nandoc/helpers/site-map.rb', line 40

def is_last
  @is_last
end

#itemObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/nandoc/helpers/site-map.rb', line 40

def item
  @item
end

#levelObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



42
43
44
# File 'lib/nandoc/helpers/site-map.rb', line 42

def level
  @level
end

#root_identifierObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/nandoc/helpers/site-map.rb', line 40

def root_identifier
  @root_identifier
end

#tabObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/nandoc/helpers/site-map.rb', line 40

def tab
  @tab
end

#tabsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



40
41
42
# File 'lib/nandoc/helpers/site-map.rb', line 40

def tabs
  @tabs
end

Class Method Details

.next_unique_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



25
26
27
28
# File 'lib/nandoc/helpers/site-map.rb', line 25

def next_unique_name
  @next_unique_name += 1
  @next_unique_name
end

.singleton(name, binding, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
33
34
35
# File 'lib/nandoc/helpers/site-map.rb', line 29

def singleton(name, binding, &block)
  @singletons[name] ||= begin
    sing = new
    sing.init_root(binding, &block)
    sing
  end
end

Instance Method Details

#children_populate_recursive(cx) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/nandoc/helpers/site-map.rb', line 65

def children_populate_recursive cx
  if cx.any? # keep our @children nil unless we have any children
   last_idx = cx.size - 1
    @children = cx.each.with_index.map do |item, idx|
      map = self.class.new
      map.is_first = idx == 0
      map.is_last  = idx == last_idx
      map.init_child self, item
      map
    end
  end
end

#init_child(parent, item) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



56
57
58
59
60
61
62
63
64
# File 'lib/nandoc/helpers/site-map.rb', line 56

def init_child parent, item
  self.parent = parent
  @item = item
  self.shared = parent.shared # this does a lot, see SharedAttrReader
  @level = parent.level + 1
  @tabs =  parent.tabs + 1
  cx = children_proc.call(@item)
  children_populate_recursive cx
end

#init_root(binding, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



47
48
49
50
51
52
53
54
55
# File 'lib/nandoc/helpers/site-map.rb', line 47

def init_root binding, &block
  block.call(self)
  @is_first = @is_last = true
  @level = 0
  @item = nil
  @tabs ||= 0
  root = eval('@items',binding).find{|x| x.identifier == root_identifier}
  children_populate_recursive [root]
end

#merge_opts(opts) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



78
79
80
81
82
# File 'lib/nandoc/helpers/site-map.rb', line 78

def merge_opts opts
  fail("just for setting tabs for now") unless opts.keys == [:tabs]
  @tabs = opts[:tabs]
  opts
end

#render_children(opts = {}) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns chunk of <li’s> for eg.

Returns:

  • (String)

    chunk of <li’s> for eg.



102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/nandoc/helpers/site-map.rb', line 102

def render_children opts={}
  these = @children.map do |map|
    map.merge_opts opts
    h1 = render_child_proc.call(map)
    h2 = map.reindent(h1)
    h3 = h2.strip
    h3
  end
  last = @children.last
  hz = these.join("\n" + last.tab * last.tabs) if last
  hz
end

#render_parent(&block) ⇒ String

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns <ul> for e.g. Sets block if given.

Returns:

  • (String)

    <ul> for e.g. Sets block if given.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/nandoc/helpers/site-map.rb', line 85

def render_parent &block
  if block_given?
    @render_parent_proc = block
    class << self
      attr_accessor :render_parent_proc
    end
    nil
  elsif @children.nil?
    nil
  else
    h1 = render_parent_proc.call(self)
    h2 = reindent(h1).strip
    h2
  end
end