Class: BaseDocument
- Inherits:
-
Object
- Object
- BaseDocument
- Defined in:
- lib/almirah/doc_types/base_document.rb
Overview
rubocop:disable Style/Documentation
Direct Known Subclasses
Coverage, DecisionsOverview, Implementation, Index, PersistentDocument, Traceability
Class Attribute Summary collapse
-
.show_decisions_link ⇒ Object
Returns the value of attribute show_decisions_link.
Instance Attribute Summary collapse
-
#dom ⇒ Object
Returns the value of attribute dom.
-
#headings ⇒ Object
Returns the value of attribute headings.
-
#id ⇒ Object
Returns the value of attribute id.
-
#output_rel_path ⇒ Object
Returns the value of attribute output_rel_path.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #decisions_link(href) ⇒ Object
- #home_link(href) ⇒ Object
- #index_link(href) ⇒ Object
-
#initialize ⇒ BaseDocument
constructor
A new instance of BaseDocument.
-
#rel_to(target) ⇒ Object
Relative URL from this page to a target path under the build root.
-
#save_html_to_file(html_rows, nav_pane, output_file_path) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity.
Constructor Details
#initialize ⇒ BaseDocument
Returns a new instance of BaseDocument.
12 13 14 15 16 17 18 |
# File 'lib/almirah/doc_types/base_document.rb', line 12 def initialize @items = [] @headings = [] @title = '' @id = '' @dom = nil end |
Class Attribute Details
.show_decisions_link ⇒ Object
Returns the value of attribute show_decisions_link.
9 10 11 |
# File 'lib/almirah/doc_types/base_document.rb', line 9 def show_decisions_link @show_decisions_link end |
Instance Attribute Details
#dom ⇒ Object
Returns the value of attribute dom.
6 7 8 |
# File 'lib/almirah/doc_types/base_document.rb', line 6 def dom @dom end |
#headings ⇒ Object
Returns the value of attribute headings.
6 7 8 |
# File 'lib/almirah/doc_types/base_document.rb', line 6 def headings @headings end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/almirah/doc_types/base_document.rb', line 6 def id @id end |
#output_rel_path ⇒ Object
Returns the value of attribute output_rel_path.
6 7 8 |
# File 'lib/almirah/doc_types/base_document.rb', line 6 def output_rel_path @output_rel_path end |
#title ⇒ Object
Returns the value of attribute title.
6 7 8 |
# File 'lib/almirah/doc_types/base_document.rb', line 6 def title @title end |
Instance Method Details
#decisions_link(href) ⇒ Object
73 74 75 76 |
# File 'lib/almirah/doc_types/base_document.rb', line 73 def decisions_link(href) icon = '<span><i class="fa fa-gavel" aria-hidden="true"></i></span>' %(<a id="decisions_menu_item" href="#{href}">#{icon} Decision Records</a>) end |
#home_link(href) ⇒ Object
83 84 85 86 |
# File 'lib/almirah/doc_types/base_document.rb', line 83 def home_link(href) icon = '<span><i class="fa fa-home" aria-hidden="true"></i></span>' %(<a id="home_menu_item" href="#{href}">#{icon} Home</a>) end |
#index_link(href) ⇒ Object
78 79 80 81 |
# File 'lib/almirah/doc_types/base_document.rb', line 78 def index_link(href) icon = '<span><i class="fa fa-info" aria-hidden="true"></i></span>' %(<a id="index_menu_item" href="#{href}">#{icon} Index</a>) end |
#rel_to(target) ⇒ Object
Relative URL from this page to a target path under the build root.
89 90 91 |
# File 'lib/almirah/doc_types/base_document.rb', line 89 def rel_to(target) RelativeUrl.between(@output_rel_path, target) end |
#save_html_to_file(html_rows, nav_pane, output_file_path) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
20 21 22 23 24 25 26 27 28 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 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/almirah/doc_types/base_document.rb', line 20 def save_html_to_file(html_rows, nav_pane, output_file_path) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity gem_root = File. './../../..', File.dirname(__FILE__) template_file = "#{gem_root}/lib/almirah/templates/page.html" file = File.open(template_file) file_data = file.readlines file.close output_file_path += if @id == 'index' "#{@id}.html" elsif instance_of? DecisionsOverview 'overview.html' elsif instance_of? Decision "#{@id}.html" else "#{@id}/#{@id}.html" end @output_rel_path = output_file_path.split('/build/', 2).last file = File.open(output_file_path, 'w') file_data.each do |s| # rubocop:disable Metrics/BlockLength if s.include?('{{CONTENT}}') html_rows.each do |r| file.puts r end elsif s.include?('{{NAV_PANE}}') file.puts nav_pane.to_html if nav_pane elsif s.include?('{{DOCUMENT_TITLE}}') file.puts s.gsub! '{{DOCUMENT_TITLE}}', @title elsif s.include?('{{STYLES_AND_SCRIPTS}}') file.puts "<link rel=\"stylesheet\" href=\"#{rel_to('css/main.css')}\">" file.puts "<script src=\"#{rel_to('scripts/main.js')}\"></script>" if @id == 'index' file.puts "<script type=\"module\" src=\"#{rel_to('scripts/orama_search.js')}\"></script>" file.puts "<link rel=\"stylesheet\" href=\"#{rel_to('css/search.css')}\">" elsif instance_of? DecisionsOverview file.puts '<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>' end elsif s.include?('{{HOME_BUTTON}}') if @id == 'index' file.puts home_link(rel_to('index.html')) else file.puts index_link(rel_to('index.html')) end file.puts decisions_link(rel_to('decisions/overview.html')) if BaseDocument.show_decisions_link elsif s.include?('{{GEM_VERSION}}') file.puts "(#{Gem.loaded_specs['Almirah'].version.version})" else file.puts s end end file.close end |