Class: BaseDocument
- Inherits:
-
Object
- Object
- BaseDocument
- Defined in:
- lib/almirah/doc_types/base_document.rb
Direct Known Subclasses
Coverage, DecisionsOverview, Implementation, Index, PersistentDocument, RiskRegistryPage, RisksOverview, Traceability
Class Attribute Summary collapse
-
.show_decisions_link ⇒ Object
Returns the value of attribute show_decisions_link.
-
.show_risks_link ⇒ Object
Returns the value of attribute show_risks_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.
-
#needs_chartjs? ⇒ Boolean
Whether this page needs the Chart.js library loaded (overridden by the planning pages that render charts).
-
#rel_to(target) ⇒ Object
Relative URL from this page to a target path under the build root.
- #risks_link(href) ⇒ Object
- #save_html_to_file(html_rows, nav_pane, output_file_path) ⇒ Object
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 |
.show_risks_link ⇒ Object
Returns the value of attribute show_risks_link.
9 10 11 |
# File 'lib/almirah/doc_types/base_document.rb', line 9 def show_risks_link @show_risks_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
82 83 84 85 |
# File 'lib/almirah/doc_types/base_document.rb', line 82 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
97 98 99 100 |
# File 'lib/almirah/doc_types/base_document.rb', line 97 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
92 93 94 95 |
# File 'lib/almirah/doc_types/base_document.rb', line 92 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 |
#needs_chartjs? ⇒ Boolean
Whether this page needs the Chart.js library loaded (overridden by the planning pages that render charts).
22 23 24 |
# File 'lib/almirah/doc_types/base_document.rb', line 22 def needs_chartjs? false end |
#rel_to(target) ⇒ Object
Relative URL from this page to a target path under the build root.
103 104 105 |
# File 'lib/almirah/doc_types/base_document.rb', line 103 def rel_to(target) RelativeUrl.between(@output_rel_path, target) end |
#risks_link(href) ⇒ Object
87 88 89 90 |
# File 'lib/almirah/doc_types/base_document.rb', line 87 def risks_link(href) icon = '<span><i class="fa fa-exclamation-triangle" aria-hidden="true"></i></span>' %(<a id="risks_menu_item" href="#{href}">#{icon} Risks</a>) end |
#save_html_to_file(html_rows, nav_pane, output_file_path) ⇒ Object
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 72 73 74 75 76 77 78 79 80 |
# File 'lib/almirah/doc_types/base_document.rb', line 26 def save_html_to_file(html_rows, nav_pane, output_file_path) 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?(RiskRegistryPage) || instance_of?(RisksOverview) 'overview.html' elsif is_a? Decision # RiskRecord included "#{@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| 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 needs_chartjs? 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 file.puts risks_link(rel_to('risks/overview.html')) if BaseDocument.show_risks_link elsif s.include?('{{GEM_VERSION}}') file.puts "(#{Gem.loaded_specs['Almirah'].version.version})" else file.puts s end end file.close end |