Class: ReverseAdoc::Converters::Ol
- Inherits:
-
Base
- Object
- Base
- ReverseAdoc::Converters::Ol
show all
- Defined in:
- lib/reverse_adoc/converters/ol.rb
Instance Method Summary
collapse
Methods inherited from Base
#constrained?, #escape_keychars, #extract_title, #node_has_ancestor?, #textnode_before_end_with?, #treat, #treat_children, #treat_children_coradoc, #treat_coradoc, #unconstrained_after?, #unconstrained_before?
Instance Method Details
#convert(node, state = {}) ⇒ Object
26
27
28
|
# File 'lib/reverse_adoc/converters/ol.rb', line 26
def convert(node, state = {})
Coradoc::Generator.gen_adoc(to_coradoc(node, state))
end
|
#get_list_type(node, _state) ⇒ Object
30
31
32
33
34
35
36
37
|
# File 'lib/reverse_adoc/converters/ol.rb', line 30
def get_list_type(node, _state)
case node.name
when "ol"
:ordered
when "ul"
:unordered
end
end
|
#number_style(node) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/reverse_adoc/converters/ol.rb', line 39
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
49
50
51
52
53
54
55
56
57
|
# File 'lib/reverse_adoc/converters/ol.rb', line 49
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
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/reverse_adoc/converters/ol.rb', line 5
def to_coradoc(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
|