Class: Indexmap::Output
- Inherits:
-
Object
- Object
- Indexmap::Output
- Defined in:
- lib/indexmap/output.rb
Constant Summary collapse
- VALID_FORMATS =
%i[index single_file].freeze
Instance Attribute Summary collapse
- #base_url ⇒ Object
- #entries ⇒ Object
- #format ⇒ Object
- #index_filename ⇒ Object
- #public_path ⇒ Object
- #sections ⇒ Object
Instance Method Summary collapse
-
#initialize(configuration:) ⇒ Output
constructor
A new instance of Output.
- #writer ⇒ Object
Constructor Details
#initialize(configuration:) ⇒ Output
Returns a new instance of Output.
9 10 11 |
# File 'lib/indexmap/output.rb', line 9 def initialize(configuration:) @configuration = configuration end |
Instance Attribute Details
#base_url ⇒ Object
13 14 15 |
# File 'lib/indexmap/output.rb', line 13 def base_url resolve(@base_url) || configuration.base_url end |
#entries ⇒ Object
17 18 19 20 21 |
# File 'lib/indexmap/output.rb', line 17 def entries resolved_entries = resolve(@entries) Array(resolved_entries.nil? ? configuration.entries : resolved_entries) end |
#format ⇒ Object
23 24 25 26 |
# File 'lib/indexmap/output.rb', line 23 def format value = resolve(@format) || configuration.format value.nil? ? :index : value.to_sym end |
#index_filename ⇒ Object
28 29 30 |
# File 'lib/indexmap/output.rb', line 28 def index_filename resolve(@index_filename) || configuration.index_filename end |
#public_path ⇒ Object
32 33 34 35 |
# File 'lib/indexmap/output.rb', line 32 def public_path value = resolve(@public_path) || configuration.public_path Pathname(value) end |
#sections ⇒ Object
37 38 39 40 41 |
# File 'lib/indexmap/output.rb', line 37 def sections resolved_sections = resolve(@sections) Array(resolved_sections.nil? ? configuration.sections : resolved_sections) end |
Instance Method Details
#writer ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/indexmap/output.rb', line 43 def writer raise ConfigurationError, "Indexmap base_url is not configured" if base_url.to_s.strip.empty? unless VALID_FORMATS.include?(format) raise ConfigurationError, "Indexmap format must be one of: #{VALID_FORMATS.join(", ")}" end if format == :single_file raise ConfigurationError, "Indexmap entries are not configured" if entries.empty? elsif sections.empty? raise ConfigurationError, "Indexmap sections are not configured" if sections.empty? end Writer.new( entries: entries, format: format, sections: sections, public_path: public_path, base_url: base_url, index_filename: index_filename ) end |