Module: Asciidoctor::Html::Utils

Defined in:
lib/asciidoctor/html/utils.rb

Overview

Utilities shared by multiple elements

Class Method Summary collapse

Class Method Details

.display_number(node) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/asciidoctor/html/utils.rb', line 19

def self.display_number(node)
  if node.numeral
    chapter_number = node.document.attr("chapnum")
    chapter_number ? "#{chapter_number}.#{node.numeral}" : node.numeral.to_s
  else
    ""
  end
end

.display_title(node) ⇒ Object



28
29
30
31
32
# File 'lib/asciidoctor/html/utils.rb', line 28

def self.display_title(node)
  prefix = display_title_prefix node
  title = prefix.empty? ? node.title : %(<span class="title-content">#{node.title}</span>)
  node.title? ? %(<h5 class="block-title">#{prefix}#{title}</h5>\n) : ""
end

.display_title_prefix(node) ⇒ Object



38
39
40
41
# File 'lib/asciidoctor/html/utils.rb', line 38

def self.display_title_prefix(node)
  prefix = title_prefix node
  prefix.empty? ? "" : %(<span class="title-prefix">#{prefix}</span>)
end

.id_class_attr_str(id, classes = nil) ⇒ Object



7
8
9
10
11
# File 'lib/asciidoctor/html/utils.rb', line 7

def self.id_class_attr_str(id, classes = nil)
  id_attr = id ? %( id="#{id}") : ""
  class_attr = classes ? %( class="#{classes}") : ""
  "#{id_attr}#{class_attr}"
end

.id_class_sel_str(id, classes) ⇒ Object



13
14
15
16
17
# File 'lib/asciidoctor/html/utils.rb', line 13

def self.id_class_sel_str(id, classes)
  result = ""
  result += "##{id}" if id
  result + ".#{classes.tr "\s", "."}" if classes
end

.title_prefix(node) ⇒ Object



34
35
36
# File 'lib/asciidoctor/html/utils.rb', line 34

def self.title_prefix(node)
  (node.style ? "#{node.style.capitalize} " : "") + display_number(node)
end

.wrap_id_classes(content, id, classes, tag_name = :div) ⇒ Object



43
44
45
46
# File 'lib/asciidoctor/html/utils.rb', line 43

def self.wrap_id_classes(content, id, classes, tag_name = :div)
  id_class = id_class_attr_str id, classes
  %(<#{tag_name}#{id_class}>\n#{content}\n</#{tag_name}> <!-- #{id_class_sel_str id, classes} -->\n)
end

.wrap_node(content, node, tag_name = :div) ⇒ Object



48
49
50
51
# File 'lib/asciidoctor/html/utils.rb', line 48

def self.wrap_node(content, node, tag_name = :div)
  classes = [node.context, node.style, node.role].compact.join " "
  wrap_id_classes content, node.id, classes, tag_name
end