Class: Swordfish::Node::List

Inherits:
Base
  • Object
show all
Defined in:
lib/swordfish/nodes/list.rb

Instance Attribute Summary

Attributes inherited from Base

#children, #content, #style

Instance Method Summary collapse

Methods inherited from Base

#append, #clear_children, #find_nodes_by_type, #inform!, #initialize, #replace, #replace_with, #stylize, #wrap_children

Constructor Details

This class inherits a constructor from Swordfish::Node::Base

Instance Method Details

#depth_of_final_nodeObject

Get the zero-indexed depth of the bottommost child list (This is not the deepest node, just the last child)



17
18
19
20
21
22
23
24
# File 'lib/swordfish/nodes/list.rb', line 17

def depth_of_final_node
  depth = 0
  node = self
  while !@children.empty? && node = node.last_list_item.nested_list do
    depth += 1
  end
  depth
end

#last_listObject

Return the final child list



27
28
29
30
31
32
33
# File 'lib/swordfish/nodes/list.rb', line 27

def last_list
  node = self
  while node.children && node.last_list_item.nested_list
    node = node.last_list_item.nested_list
  end
  node
end

#last_list_item(opts = {}) ⇒ Object

Return the final child list item



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/swordfish/nodes/list.rb', line 36

def last_list_item(opts = {})
  if opts[:recurse]
    node = self
    li = @children.last
    while node.children && node = node.last_list_item.nested_list
      li = node.children.last
    end
    li
  else
    @children.last
  end
end

#to_htmlObject



7
8
9
10
11
12
13
# File 'lib/swordfish/nodes/list.rb', line 7

def to_html
  if @style.bullet?
    "<ul>#{@children.map(&:to_html).join}</ul>"
  else
    "<ol>#{@children.map(&:to_html).join}</ol>"
  end
end