Class: BaseDocument
- Inherits:
-
Object
- Object
- BaseDocument
- Defined in:
- lib/almirah/doc_types/base_document.rb
Direct Known Subclasses
Coverage, CriticalChainPage, 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
- #critical_chain_link(href) ⇒ Object
- #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.
- #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 |
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
#critical_chain_link(href) ⇒ Object
89 90 91 92 |
# File 'lib/almirah/doc_types/base_document.rb', line 89 def critical_chain_link(href) icon = '<span><i class="fa fa-link" aria-hidden="true"></i></span>' %(<a id="critical_chain_menu_item" href="#{href}">#{icon} Critical Chain</a>) end |
#decisions_link(href) ⇒ Object
84 85 86 87 |
# File 'lib/almirah/doc_types/base_document.rb', line 84 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
99 100 101 102 |
# File 'lib/almirah/doc_types/base_document.rb', line 99 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
94 95 96 97 |
# File 'lib/almirah/doc_types/base_document.rb', line 94 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.
105 106 107 |
# File 'lib/almirah/doc_types/base_document.rb', line 105 def rel_to(target) RelativeUrl.between(@output_rel_path, target) 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 81 82 |
# 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? CriticalChainPage 'critical-chain.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| 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 if BaseDocument.show_decisions_link file.puts decisions_link(rel_to('decisions/overview.html')) file.puts critical_chain_link(rel_to('decisions/critical-chain.html')) end elsif s.include?('{{GEM_VERSION}}') file.puts "(#{Gem.loaded_specs['Almirah'].version.version})" else file.puts s end end file.close end |