Class: ReverseAdoc::Converters::Ol

Inherits:
Base
  • Object
show all
Defined in:
lib/reverse_adoc/converters/ol.rb

Instance Method Summary collapse

Methods inherited from Base

#escape_keychars, #extract_title, #treat, #treat_children

Instance Method Details

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



4
5
6
7
8
9
10
# File 'lib/reverse_adoc/converters/ol.rb', line 4

def convert(node, state = {})
  id = node['id']
  anchor = id ? "[[#{id}]]\n" : ""
  ol_count = state.fetch(:ol_count, 0) + 1
  attrs = ol_attrs(node)
  "\n#{anchor}#{attrs}" << treat_children(node, state.merge(ol_count: ol_count))
end

#number_style(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/reverse_adoc/converters/ol.rb', line 12

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

#ol_attrs(node) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/reverse_adoc/converters/ol.rb', line 24

def ol_attrs(node)
  style = number_style(node)
  reversed = "%reversed" if node["reversed"]
  start = "start=#{node['start']}" if node["start"]
  type = "type=#{node['type']}" if node["type"]
  attrs = []
  attrs << style if style
  attrs << reversed if reversed
  attrs << start if start
  attrs << type if type
  if attrs.empty?
    ""
  else
    "[#{attrs.join(',')}]\n"
  end
end