Module: Booky::Layout::Helpers

Instance Method Summary collapse

Instance Method Details

#add_to_toc(level, name = ) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/booky/layout/helpers.rb', line 13

def add_to_toc(level, name = options[:text])
  return unless is_first_rendering?
  
  path = Booky::Layout.config.levels.values.dup.reject{|e| e == 0}
  
  parent = []
  parent = Booky::Layout.config.toc.dup.reverse.each{ |entry| break(entry[:name]) if entry[:level] == (level - 1) } if level > 1
  
  Booky::Layout.config.toc << { :name => name, :page => page_number, :level => level, :levels => Booky::Layout.config.levels.dup, :path => path, :parent => parent }
end

#is_first_rendering?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/booky/layout/helpers.rb', line 24

def is_first_rendering?
  Booky::Layout.config.runs == 1
end

#update_levels(level) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/booky/layout/helpers.rb', line 4

def update_levels(level)
  return unless is_first_rendering?
  
  ((level+1)..Booky::Layout.config.last_level).each{ |l| Booky::Layout.config.levels[l] = 0  } if Booky::Layout.config.last_level > level
  
  Booky::Layout.config.levels[level] += 1                           
  Booky::Layout.config.last_level = level
end