Class: Coradoc::Input::HTML::Converters::Ol

Inherits:
Base
  • Object
show all
Defined in:
lib/coradoc/input/html/converters/ol.rb

Instance Method Summary collapse

Methods inherited from Base

#convert, #extract_leading_trailing_whitespace, #extract_title, #node_has_ancestor?, #textnode_after_start_with?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?

Instance Method Details

#get_list_type(node, _state) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/coradoc/input/html/converters/ol.rb', line 26

def get_list_type(node, _state)
  case node.name
  when "ol"
    :ordered
  when "ul"
    :unordered
  end
end

#number_style(node) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/coradoc/input/html/converters/ol.rb', line 35

def number_style(node)
  case node["style"]
  when "1" then "arabic"
  when "A" then "upperalpha"
  when "a" then "loweralpha"
  when "I" then "upperroman"
  when "i" then "lowerroman"
  end
end

#ol_attrs(node) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/coradoc/input/html/converters/ol.rb', line 45

def ol_attrs(node)
  attrs = Coradoc::Element::AttributeList.new
  style = number_style(node)
  attrs.add_positional(style) if style
  attrs.add_positional("%reversed") if node["reversed"]
  attrs.add_named("start", node["start"]) if node["start"]
  attrs.add_named("type", node["type"]) if node["type"]
  attrs
end

#to_coradoc(node, state = {}) ⇒ Object

FIXIT



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/coradoc/input/html/converters/ol.rb', line 5

def to_coradoc(node, state = {})
  # convert(node, state)
  id = node["id"]
  ol_count = state.fetch(:ol_count, 0) + 1
  attrs = ol_attrs(node)
  items = treat_children_coradoc(node, state.merge(ol_count: ol_count))

  options = {}.tap do |hash|
    hash[:id] = id
    hash[:ol_count] = ol_count
    hash[:attrs] = attrs
  end

  case get_list_type(node, state)
  when :ordered
    Coradoc::Element::List::Ordered.new(items, options)
  when :unordered
    Coradoc::Element::List::Unordered.new(items, options)
  end
end