Class: BaseDocument

Inherits:
Object
  • Object
show all
Defined in:
lib/almirah/doc_types/base_document.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBaseDocument

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

.font_sizeObject

Returns the value of attribute font_size.



9
10
11
# File 'lib/almirah/doc_types/base_document.rb', line 9

def font_size
  @font_size
end

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

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

#domObject

Returns the value of attribute dom.



6
7
8
# File 'lib/almirah/doc_types/base_document.rb', line 6

def dom
  @dom
end

#headingsObject

Returns the value of attribute headings.



6
7
8
# File 'lib/almirah/doc_types/base_document.rb', line 6

def headings
  @headings
end

#idObject

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_pathObject

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

#titleObject

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



79
80
81
82
# File 'lib/almirah/doc_types/base_document.rb', line 79

def decisions_link(href)
  icon = '<span><i class="fa fa-gavel" aria-hidden="true"></i></span>'
  %(<a id="decisions_menu_item" href="#{href}">#{icon}&nbsp;Decision Records</a>)
end

#font_size_styleObject

The inline override carrying the project.yml font_size (ADR-224). Emitted after the main.css link only when the setting exists, so unconfigured projects render exactly as before.



100
101
102
# File 'lib/almirah/doc_types/base_document.rb', line 100

def font_size_style
  "<style>:root { --almirah-font-size: #{BaseDocument.font_size}px; }</style>"
end

The Documents item (ADR-223): the same link on every page, the Index page included, where it self-links — no Home variant. The element id stays index_menu_item; the label is presentation, the id is an interface.



92
93
94
95
# File 'lib/almirah/doc_types/base_document.rb', line 92

def index_link(href)
  icon = '<span><i class="fa fa-home" aria-hidden="true"></i></span>'
  %(<a id="index_menu_item" href="#{href}">#{icon}&nbsp;Documents</a>)
end

#needs_chartjs?Boolean

Whether this page needs the Chart.js library loaded (overridden by the planning pages that render charts).

Returns:

  • (Boolean)


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


84
85
86
87
# File 'lib/almirah/doc_types/base_document.rb', line 84

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}&nbsp;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
# 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.expand_path './../../..', 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 font_size_style if BaseDocument.font_size
      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}}')
      file.puts index_link(rel_to('index.html'))
      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