Class: BaseDocument
- Inherits:
-
Object
- Object
- BaseDocument
- Defined in:
- lib/almirah/doc_types/base_document.rb
Overview
rubocop:disable Style/Documentation
Direct Known Subclasses
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.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
-
#initialize ⇒ BaseDocument
constructor
A new instance of BaseDocument.
-
#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.
6 7 8 9 10 11 12 |
# File 'lib/almirah/doc_types/base_document.rb', line 6 def initialize @items = [] @headings = [] @title = '' @id = '' @dom = nil end |
Instance Attribute Details
#dom ⇒ Object
Returns the value of attribute dom.
4 5 6 |
# File 'lib/almirah/doc_types/base_document.rb', line 4 def dom @dom end |
#headings ⇒ Object
Returns the value of attribute headings.
4 5 6 |
# File 'lib/almirah/doc_types/base_document.rb', line 4 def headings @headings end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/almirah/doc_types/base_document.rb', line 4 def id @id end |
#title ⇒ Object
Returns the value of attribute title.
4 5 6 |
# File 'lib/almirah/doc_types/base_document.rb', line 4 def title @title end |
Instance Method Details
#save_html_to_file(html_rows, nav_pane, output_file_path) ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
14 15 16 17 18 19 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 |
# File 'lib/almirah/doc_types/base_document.rb', line 14 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" else "#{@id}/#{@id}.html" end 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}}') if @id == 'index' file.puts '<script type="module" src="./scripts/orama_search.js"></script>' file.puts '<link rel="stylesheet" href="./css/search.css">' file.puts '<link rel="stylesheet" href="./css/main.css">' file.puts '<script src="./scripts/main.js"></script>' elsif instance_of? Specification file.puts '<link rel="stylesheet" href="../../css/main.css">' file.puts '<script src="../../scripts/main.js"></script>' elsif instance_of? Traceability file.puts '<link rel="stylesheet" href="../../css/main.css">' file.puts '<script src="../../scripts/main.js"></script>' elsif instance_of? Coverage file.puts '<link rel="stylesheet" href="../../css/main.css">' file.puts '<script src="../../scripts/main.js"></script>' elsif instance_of? Protocol file.puts '<link rel="stylesheet" href="../../../css/main.css">' file.puts '<script src="../../../scripts/main.js"></script>' end elsif s.include?('{{GEM_VERSION}}') file.puts "(#{Gem.loaded_specs['Almirah'].version.version})" else file.puts s end end file.close end |