Class: OrigenDocHelpers::HtmlFlowFormatter

Inherits:
ATP::Formatter
  • Object
show all
Includes:
Origen::Generator::Compiler::DocHelpers::TestFlowHelpers
Defined in:
lib/origen_doc_helpers/html_flow_formatter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Origen::Generator::Compiler::DocHelpers::TestFlowHelpers

#_bin_number, #_sbin_number, #_start_accordion, #_start_test_flow_table, #_stop_accordion, #_stop_test_flow_table, #_test_name, #_test_number, #_test_to_local_link

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



7
8
9
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 7

def html
  @html
end

Instance Method Details

#format(node, options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 9

def format(node, options = {})
  @html = ''
  process(node)
  html
end

#on_continue(node) ⇒ Object



154
155
156
157
158
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 154

def on_continue(node)
  if @within_on_fail
    html << "<span class=\"label label-danger\">Continue</span>"
  end
end

#on_flow(node) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 15

def on_flow(node)
  @flow ||= 0
  @flow += 1
  html << "<div class=\"panel-group\" id=\"test_flow_#{@flow}\">"
  html << _start_accordion(node.to_a[0].value)
  if node.description && !node.description.empty?
    html << to_html(node.description.join("\n"))
    html << '<hr>'
  end
  process_all(node)
  html << _stop_accordion
  html << '</div>'
end

#on_flow_flag(node) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 63

def on_flow_flag(node)
  @flow_flag ||= 0
  @flow_flag += 1
  flags = [node.to_a[0]].flatten
  flags = flags.map do |flag|
    "<span class=\"label label-info\">#{flag}</span>"
  end
  if node.to_a[1]
    text = "<span class=\"connector\">IF</span>" + flags.join("<span class=\"connector\">OR</span>")
  else
    text = "<span class=\"connector\">UNLESS</span>" + flags.join("<span class=\"connector\">OR</span>")
  end
  html << "<div class=\"row test-overview\">"
  html << "<div class=\"panel-group col-md-12\" id=\"flow_flag_#{@flow_flag}\">"
  html << _start_accordion(text, panel: :warning)
  process_all(node)
  html << _stop_accordion
  html << '</div>'
  html << '</div>'
end

#on_group(node) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 29

def on_group(node)
  html << "<div class=\"row test-overview\">"
  html << "  <div class=\"header\">"
  html << "    <span class=\"pull-right\"><a class=\"top-link\" href=\"#\">back to top</a></span>"
  html << "    <h4 class=\"no-anchor\">#{node.to_a[0].value}</h4>"
  html << '  </div>'

  html << "<div class=\"col-md-12\" style=\"margin-bottom: 15px;\">"
  html << "  <div class=\"col-md-4\">"
  @within_test = true
  @object = ''
  on_fail = node.find(:on_fail)
  on_pass = node.find(:on_pass)
  process(on_fail) if on_fail
  process(on_pass) if on_pass
  html << @object
  @within_test = false
  html << '  </div>'
  html << "  <div class=\"col-md-8 description-pane\">"
  html << to_html(node.description.join("\n")) if node.description
  html << '  </div>'
  html << '  </div>'

  @group ||= 0
  @group += 1
  html << "<div class=\"col-md-12 panel-group\" id=\"test_group_#{@group}\">"
  html << _start_accordion('Tests')
  process_all(node.children - [on_fail, on_pass])
  html << _stop_accordion
  html << '</div>'

  html << '</div>'
end

#on_object(node) ⇒ Object



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 187

def on_object(node)
  t = node.to_a.first
  @object << "<hr><div class=\"test-attributes\">"
  if t.is_a?(String)
    @object << "<strong>Test: </strong><span>#{t}</span>"
  elsif t.is_a?(Hash)
    t.each do |key, value|
      @object << "<strong>#{key}: </strong><span>#{value}</span><br>"
    end
  end
  @object << '</div>'
end

#on_on_fail(node) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 146

def on_on_fail(node)
  @within_continue = !!node.find(:continue)
  @within_on_fail = true
  process_all(node.children)
  @within_continue = false
  @within_on_fail = false
end

#on_run_flag(node) ⇒ Object



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 84

def on_run_flag(node)
  @run_flag ||= 0
  @run_flag += 1
  flags = [node.to_a[0]].flatten
  flags = flags.map do |flag|
    if flag =~ /FAILED/
      "<span class=\"label label-danger\">#{flag}</span>"
    elsif flag =~ /PASSED/
      "<span class=\"label label-success\">#{flag}</span>"
    else
      "<span class=\"label label-info\">#{flag}</span>"
    end
  end
  text = "<span class=\"connector\">IF</span>" + flags.join("<span class=\"connector\">OR</span>")
  html << "<div class=\"row test-overview\">"
  html << "<div class=\"panel-group col-md-12\" id=\"run_flag_#{@run_flag}\">"
  html << _start_accordion(text, panel: :info)
  process_all(node)
  html << _stop_accordion
  html << '</div>'
  html << '</div>'
end

#on_set_result(node) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 107

def on_set_result(node)
  unless @within_continue
    type, *nodes = *node
    bin = node.find(:bin).try(:value)
    sbin = node.find(:softbin).try(:value)
    unless @within_test
      html << "<div class=\"row\">"
      html << "  <div class=\"col-md-4\">"
      if type == 'fail'
        html << "    <h4 class=\"no-anchor\">Set Result - FAIL</h4>"
      else
        html << "    <h4 class=\"no-anchor\">Set Result - PASS</h4>"
      end
    end
    if type == 'fail'
      html << "<span class=\"label label-danger\">Bin #{bin}</span>" if bin
      html << "<span class=\"label label-danger\">Softbin #{sbin}</span>" if sbin
    else
      html << "<span class=\"label label-success\">Bin #{bin}</span>" if bin
      html << "<span class=\"label label-success\">Softbin #{sbin}</span>" if sbin
    end
    unless @within_test
      html << '  </div>'
      html << "  <div class=\"col-md-8 description-pane\">"
      html << '  </div>'
      html << '</div>'
      html << '<hr>'
    end
  end
end

#on_set_run_flag(node) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 138

def on_set_run_flag(node)
  if @within_on_fail
    html << "<span class=\"label label-danger\">#{node.value}</span>"
  else
    html << "<span class=\"label label-success\">#{node.value}</span>"
  end
end

#on_test(node) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 160

def on_test(node)
  id = node.find(:id).value
  html << "<div class=\"row test-overview\" id=\"flow_#{@flow}_test_#{id}\">"
  html << "  <a class=\"anchor\" name=\"flow_#{@flow}_test_#{id}\"></a>"
  html << "  <div class=\"header\">"
  if n = node.find(:name)
    name = n.value
  else
    name = node.find(:object).value['Test']
  end
  number = node.find(:number).try(:value)
  html << "    <span class=\"pull-right\"><a class=\"list-link\" href=\"#\" data-testid=\"list_#{@flow}_test_#{id}\">view in datalog</a><span> | </span><a class=\"top-link\" href=\"#\">back to top</a></span>"
  html << "    <h4 class=\"no-anchor\">#{name}<span class=\"test-number\">#{number ? ' - ' + number.to_s : ''}</span></h4>"
  html << '  </div>'
  html << "  <div class=\"col-md-4\">"
  @within_test = true
  @object = ''
  process_all(node.children)
  html << @object
  @within_test = false
  html << '  </div>'
  html << "  <div class=\"col-md-8 description-pane\">"
  html << to_html(node.description.join("\n")) if node.description
  html << '  </div>'
  html << '</div>'
end

#to_html(string, _options = {}) ⇒ Object

Convert the given markdown string to HTML



201
202
203
204
205
206
207
# File 'lib/origen_doc_helpers/html_flow_formatter.rb', line 201

def to_html(string, _options = {})
  # Escape any " that are not already escaped
  string.gsub!(/([^\\])"/, '\1\"')
  # Escape any ' that are not already escaped
  string.gsub!(/([^\\])'/, %q(\1\\\'))
  html = Kramdown::Document.new(string, input: :kramdown).to_html
end