Class: GovukMarkdown::Renderer
- Inherits:
-
Redcarpet::Render::HTML
- Object
- Redcarpet::Render::HTML
- GovukMarkdown::Renderer
- Defined in:
- lib/govuk_markdown/renderer.rb
Instance Method Summary collapse
- #header(text, header_level) ⇒ Object
- #hrule ⇒ Object
-
#initialize(govuk_options, options = {}) ⇒ Renderer
constructor
A new instance of Renderer.
- #list(contents, list_type) ⇒ Object
- #paragraph(text) ⇒ Object
- #preprocess(document) ⇒ Object
- #table(header, body) ⇒ Object
- #table_cell(content, _alignment, header) ⇒ Object
- #table_row(content) ⇒ Object
Constructor Details
#initialize(govuk_options, options = {}) ⇒ Renderer
Returns a new instance of Renderer.
3 4 5 6 |
# File 'lib/govuk_markdown/renderer.rb', line 3 def initialize(, = {}) @headings_start_with = [:headings_start_with] super end |
Instance Method Details
#header(text, header_level) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/govuk_markdown/renderer.rb', line 45 def header(text, header_level) valid_header_sizes = %w[xl l m s].freeze start_size = valid_header_sizes.include?(@headings_start_with) ? @headings_start_with : "xl" start_size_index = valid_header_sizes.find_index(start_size) header_size = valid_header_sizes[start_size_index + header_level - 1] || "s" id_attribute = @options[:with_toc_data] ? " id=\"#{text.parameterize}\"" : "" <<~HTML <h#{header_level}#{id_attribute} class="govuk-heading-#{header_size}">#{text}</h#{header_level}> HTML end |
#hrule ⇒ Object
85 86 87 88 89 |
# File 'lib/govuk_markdown/renderer.rb', line 85 def hrule <<~HTML <hr class="govuk-section-break govuk-section-break--xl govuk-section-break--visible"> HTML end |
#list(contents, list_type) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/govuk_markdown/renderer.rb', line 66 def list(contents, list_type) case list_type when :unordered <<~HTML <ul class="govuk-list govuk-list--bullet"> #{contents} </ul> HTML when :ordered <<~HTML <ol class="govuk-list govuk-list--number"> #{contents} </ol> HTML else raise "Unexpected type #{list_type.inspect}" end end |
#paragraph(text) ⇒ Object
60 61 62 63 64 |
# File 'lib/govuk_markdown/renderer.rb', line 60 def paragraph(text) <<~HTML <p class="govuk-body-m">#{text}</p> HTML end |
#preprocess(document) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/govuk_markdown/renderer.rb', line 91 def preprocess(document) Preprocessor .new(document) .inject_inset_text .inject_details .output end |
#table(header, body) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/govuk_markdown/renderer.rb', line 8 def table(header, body) <<~HTML <table class='govuk-table'> <thead class='govuk-table__head'> #{header} </thead> <tbody class='govuk-table__body'> #{body} </tbody> </table> HTML end |
#table_cell(content, _alignment, header) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/govuk_markdown/renderer.rb', line 29 def table_cell(content, _alignment, header) if header <<~HTML <th class='govuk-table__header'> #{content} </th> HTML else <<~HTML <td class='govuk-table__cell'> #{content} </td> HTML end end |
#table_row(content) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/govuk_markdown/renderer.rb', line 21 def table_row(content) <<~HTML <tr class='govuk-table__row'> #{content} </tr> HTML end |