Module: Asciidoctor::Rhrev::Html5Converter
- Includes:
- Helpers
- Defined in:
- lib/asciidoctor/rhrev/rhrev_html.rb
Instance Method Summary collapse
- #collect_all_entries(doc) ⇒ Object
- #convert(node, transform = node.node_name, opts = {}) ⇒ Object
- #convert_rhrev_block(node) ⇒ Object
- #format_change_as_html_list(text) ⇒ Object
- #generate_html_output(doc, catalog) ⇒ Object
- #generate_html_table(doc, catalog) ⇒ Object
- #generate_initial_release_html(doc) ⇒ Object
- #is_initial_release?(revnumber) ⇒ Boolean
Methods included from Helpers
#antora_build?, #convert_anchor_to_xref, #debug_log, #format_prev_rev, #needs_asciidoc_cell?, #preprocess_attribute_content, #with_attribute_missing_suppressed
Instance Method Details
#collect_all_entries(doc) ⇒ Object
153 154 155 156 157 158 159 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 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 153 def collect_all_entries(doc) catalog = Catalog.new prefix = doc.attr 'revhistoryprefix', 'rhrev' # Collect document-level entries (-all) (0..9).each do |major| (0..9).each do |minor| revision = "#{major}-#{minor}" prevrev_attr = "#{revision}-prevrev" if doc.attr(prevrev_attr) all_attr_name = "#{prefix}#{revision}-all" if (all_value = doc.attr(all_attr_name)) catalog.add_all_entry revision, all_value end # Skip -cover entries for HTML end end end # Collect block-level entries by scanning document contexts = [:section, :floating_title, :example, :listing, :table, :image] doc.find_by { |b| contexts.include?(b.context) }.each do |block| next unless block.id if block.respond_to?(:attributes) block.attributes.each do |key, value| key_str = key.to_s next unless key_str.start_with?(prefix) next if key_str.include?('-all') || key_str.end_with?('-cover') revision = key_str.sub(prefix, '') catalog.add_entry revision, block.id, value.to_s, reftext: block.reftext, title: block.title, sectnum: block.respond_to?(:sectnum) ? block.sectnum : nil, context: block.context, is_chapter: false, sectname: block.respond_to?(:sectname) ? block.sectname : nil, caption_number: nil, source_line: block.lineno end end end catalog end |
#convert(node, transform = node.node_name, opts = {}) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 27 def convert node, transform = node.node_name, opts = {} if node.context == :rhrev convert_rhrev_block node else super end end |
#convert_rhrev_block(node) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 35 def convert_rhrev_block node doc = node.document return '' unless doc.attr? 'rhrev' return '' if doc.attr('rhrev') == 'manual' # Check for initial release handling revnumber = doc.attr('revnumber', '1.0') initial_handling = doc.attr('rhrev-initial-handling', 'initial-release') if is_initial_release?(revnumber) return '' if initial_handling == 'skip' return generate_initial_release_html(doc) if initial_handling == 'initial-release' end # Generate revision history HTML table catalog = collect_all_entries(doc) return '' if catalog.nil? || catalog.entries.empty? generate_html_output(doc, catalog) end |
#format_change_as_html_list(text) ⇒ Object
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 293 def format_change_as_html_list(text) return '' if text.to_s.empty? # Process attribute content (handle line breaks) processed = preprocess_attribute_content(text) # Split by asterisks to create list items tokens = processed.split(/\s(?=\*+\s)/) items = [] if tokens.empty? || tokens.length == 1 && !processed.include?('*') # Single item without asterisk - wrap in list anyway items << { level: 1, content: processed } else tokens.each do |token| next if token.strip.empty? # Count leading asterisks for nesting level if token.strip =~ /^(\*+)\s+(.+)/ level = $1.length content = $2 items << { level: level, content: content } else items << { level: 1, content: token.strip } end end end # Always generate HTML list html = ['<ul>'] items.each do |item| html << '<li>' + item[:content] + '</li>' end html << '</ul>' html.join("\n") end |
#generate_html_output(doc, catalog) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 60 def generate_html_output(doc, catalog) html = [] discrete = doc.attr? 'rhrev-discrete' # Wrapper html << '<div class="rhrev-section">' if discrete html << '<section id="revision-history">' unless discrete # Title if (title = doc.attr('rhrev-customization-title')) unless title.empty? version_label = doc.attr('version-label', 'Revision') resolved_title = title.gsub('{version-label}', version_label) html << %(<h2>#{resolved_title}</h2>) end else # Default title version_label = doc.attr('version-label', 'Revision') html << %(<h2>#{version_label} History</h2>) end # Table html << generate_html_table(doc, catalog) # Close wrapper html << (discrete ? '</div>' : '</section>') html.join("\n") end |
#generate_html_table(doc, catalog) ⇒ Object
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 203 def generate_html_table(doc, catalog) column_widths = doc.attr 'rhrev-table-column-width', '30,70' widths = column_widths.split(',').map(&:strip) html = [] # Build table CSS classes with frame and grid frame = doc.attr('rhrev-table-frame', 'all') grid = doc.attr('rhrev-table-grid', 'all') html << %(<table class="tableblock frame-#{frame} grid-#{grid} stretch">) # Caption as title div unless doc.attr? 'rhrev-disable-caption' if (caption = doc.attr('rhrev-table-caption')) html << %(<div class="title">#{caption}</div>) end end html << '<colgroup>' widths.each { |w| html << %(<col style="width: #{w}%;">) } html << '</colgroup>' html << '<tbody>' # Custom first row if (first_row = doc.attr('rhrev-customization-first-row')) html << '<tr class="rhrev-custom-first-row">' html << %(<td colspan="2">#{first_row}</td>) html << '</tr>' elsif (first_row_left = doc.attr('rhrev-customization-first-row-left')) || (first_row_right = doc.attr('rhrev-customization-first-row-right')) html << '<tr class="rhrev-custom-first-row">' html << %(<td>#{first_row_left || ' '}</td>) html << %(<td>#{first_row_right || ' '}</td>) html << '</tr>' end section_label = doc.attr 'rhrev-localization-location', 'Section' major_changes_text = doc.attr 'rhrev-localization-major-changes', 'Major changes since' all_text = doc.attr 'rhrev-localization-all', 'All' catalog.sorted_revisions.each do |revision| prevrev_attr = "#{revision}-prevrev" prevrevdate_attr = "#{revision}-prevrevdate" revision_label = doc.attr('version-label', 'Revision') prev_title = doc.attr(prevrev_attr) || revision.tr('-', '.') prev_date = doc.attr(prevrevdate_attr) || "" prev_rev_text = format_prev_rev(prev_title, prev_date, doc) # Build header text if prev_title.strip.downcase.start_with?(revision_label.downcase) header_text = "#{major_changes_text} #{prev_rev_text}" else header_text = "#{major_changes_text} #{revision_label} #{prev_rev_text}" end # Header row for this revision html << '<tr class="rhrev-header">' html << %(<th class="tableblock halign-left valign-top">#{section_label}</th>) html << %(<th class="tableblock halign-left valign-top"><strong>#{header_text}</strong></th>) html << '</tr>' # All entry if (all_change = catalog.instance_variable_get(:@all_entries)[revision]) html << '<tr>' html << %(<td>#{all_text}</td>) html << %(<td>#{format_change_as_html_list(all_change)}</td>) html << '</tr>' end # Block entries entries = catalog.entries[revision] || [] entries.sort_by! { |e| e[:sequence] || 0 } entries.each do |entry| anchor = entry[:anchor] title = entry[:title] || anchor.tr('_-', ' ').split.map(&:capitalize).join(' ') html << '<tr>' html << %(<td><a href="##{anchor}">#{title}</a></td>) html << %(<td>#{format_change_as_html_list(entry[:change])}</td>) html << '</tr>' end end html << '</tbody>' html << '</table>' html.join("\n") end |
#generate_initial_release_html(doc) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 90 def generate_initial_release_html(doc) html = [] discrete = doc.attr? 'rhrev-discrete' # Wrapper html << '<div class="rhrev-section">' if discrete html << '<section id="revision-history">' unless discrete # Title if (title = doc.attr('rhrev-customization-title')) unless title.empty? version_label = doc.attr('version-label', 'Revision') resolved_title = title.gsub('{version-label}', version_label) html << %(<h2>#{resolved_title}</h2>) end else version_label = doc.attr('version-label', 'Revision') html << %(<h2>#{version_label} History</h2>) end # Simple table initial_text = doc.attr('rhrev-customization-initial-release-text') || doc.attr('rhrev-localization-initial-release') || 'Initial release' column_widths = doc.attr('rhrev-table-column-width', '30,70').split(',').map(&:strip) section_label = doc.attr('rhrev-localization-location', 'Section') major_changes_text = doc.attr('rhrev-localization-major-changes', 'Major changes since') version_label = doc.attr('version-label', 'Revision') revnumber = doc.attr('revnumber', '1.0') # Build table CSS classes with frame and grid frame = doc.attr('rhrev-table-frame', 'all') grid = doc.attr('rhrev-table-grid', 'all') html << %(<table class="tableblock frame-#{frame} grid-#{grid} stretch">) # Caption as title div unless doc.attr? 'rhrev-disable-caption' if (caption = doc.attr('rhrev-table-caption')) html << %(<div class="title">#{caption}</div>) end end html << '<colgroup>' column_widths.each { |w| html << %(<col style="width: #{w}%;">)} html << '</colgroup>' html << '<tbody>' html << '<tr class="rhrev-header">' html << %(<th class="tableblock halign-left valign-top">#{section_label}</th>) html << %(<th class="tableblock halign-left valign-top"><strong>#{major_changes_text} #{version_label} #{revnumber}</strong></th>) html << '</tr>' html << '<tr>' html << '<td> </td>' html << %(<td>#{initial_text}</td>) html << '</tr>' html << '</tbody>' html << '</table>' html << (discrete ? '</div>' : '</section>') html.join("\n") end |
#is_initial_release?(revnumber) ⇒ Boolean
56 57 58 |
# File 'lib/asciidoctor/rhrev/rhrev_html.rb', line 56 def is_initial_release?(revnumber) revnumber.to_s == '1.0' || revnumber.to_s == '1' end |