Class: Metanorma::Generic::Configuration
- Inherits:
-
Object
- Object
- Metanorma::Generic::Configuration
- Defined in:
- lib/metanorma/generic.rb
Constant Summary collapse
- CONFIG_ATTRS =
%i[ organization_name_short organization_name_long bibliography_titles boilerplate committees document_namespace docid_template doctypes default_doctype fonts_manifest i18nyaml logo_path logo_paths header htmlcoverpage htmlintropage htmlstylesheet html_bodyfont html_headerfont html_monospacefont html_normalfontsize html_monospacefontsize html_smallerfontsize html_footnotefontsize metadata_extensions metanorma_name normref_titles published_stages relations default_stage stage_abbreviations scripts scripts_pdf standardstylesheet symbols_titles termsdefs_titles validate_rng_file webfont wordcoverpage wordintropage wordstylesheet word_bodyfont word_headerfont word_monospacefont word_normalfontsize word_monospacefontsize word_smallerfontsize word_footnotefontsize xml_root_tag pdf_stylesheet formats ].freeze
Class Attribute Summary collapse
-
._file ⇒ Object
Returns the value of attribute _file.
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
rubocop:disable Lint/MissingSuper.
Instance Method Summary collapse
- #absolute_path(value, root_path) ⇒ Object
- #absolute_path1(hash, pref) ⇒ Object
- #absolute_path1_array(value, pref) ⇒ Object
- #blank?(val) ⇒ Boolean
-
#default_formats ⇒ Object
convert array to hash; if already is hash (no override in customize), don’t reconvert.
- #default_org ⇒ Object
- #default_titles ⇒ Object
- #filepath_attrs ⇒ Object
-
#initialize(*args) ⇒ Configuration
constructor
A new instance of Configuration.
-
#postprocess_defaults ⇒ Object
may be invoked multiple times, needs to not overwrite.
- #set_default_value_from_yaml_file(attr, root_path, default_options) ⇒ Object
- #set_default_values_from_yaml_file(config_file) ⇒ Object
- #set_default_values_from_yaml_file_prep(config_file) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Configuration
Returns a new instance of Configuration.
89 90 91 92 93 94 95 |
# File 'lib/metanorma/generic.rb', line 89 def initialize(*args) super # Try to set config values from yaml file in current directory @yaml = File.join(File.dirname(self.class::_file || __FILE__), "..", "..", YAML_CONFIG_FILE) set_default_values_from_yaml_file(@yaml) end |
Class Attribute Details
._file ⇒ Object
Returns the value of attribute _file.
82 83 84 |
# File 'lib/metanorma/generic.rb', line 82 def _file @_file end |
Class Method Details
.inherited(klass) ⇒ Object
rubocop:disable Lint/MissingSuper
85 86 87 |
# File 'lib/metanorma/generic.rb', line 85 def self.inherited(klass) # rubocop:disable Lint/MissingSuper klass._file = caller_locations(1..1).first.absolute_path end |
Instance Method Details
#absolute_path(value, root_path) ⇒ Object
169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/metanorma/generic.rb', line 169 def absolute_path(value, root_path) case value when Hash then absolute_path1(value, root_path) when Array then absolute_path1_array(value, root_path) when String if !value.empty? && !Pathname.new(value).absolute? Pathname.new(File.join(root_path, value)).cleanpath.to_s else value end else value end end |
#absolute_path1(hash, pref) ⇒ Object
182 183 184 185 186 |
# File 'lib/metanorma/generic.rb', line 182 def absolute_path1(hash, pref) hash.reject { |_k, v| blank?(v) }.transform_values do |v| absolute_path(v, pref) end end |
#absolute_path1_array(value, pref) ⇒ Object
188 189 190 191 192 |
# File 'lib/metanorma/generic.rb', line 188 def absolute_path1_array(value, pref) value.reject { |a| blank?(a) }.each_with_object([]) do |v1, g| g << absolute_path(v1, pref) end end |
#blank?(val) ⇒ Boolean
165 166 167 |
# File 'lib/metanorma/generic.rb', line 165 def blank?(val) val.nil? || (val.respond_to?(:empty?) && val.empty?) end |
#default_formats ⇒ Object
convert array to hash; if already is hash (no override in customize), don’t reconvert
112 113 114 115 116 117 118 119 |
# File 'lib/metanorma/generic.rb', line 112 def default_formats formats.is_a?(Hash) and return self.formats ||= %w(html doc) self.formats = self.formats.each_with_object({}) do |k, m| m[k.to_sym] = k end self.formats.merge! DummyProcessor.new.output_formats end |
#default_org ⇒ Object
104 105 106 107 108 |
# File 'lib/metanorma/generic.rb', line 104 def default_org self.organization_name_short ||= ORGANIZATION_NAME_SHORT self.organization_name_long ||= ORGANIZATION_NAME_LONG self.document_namespace ||= DOCUMENT_NAMESPACE end |
#default_titles ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/metanorma/generic.rb', line 121 def default_titles self.termsdefs_titles ||= ["Terms and definitions", "Terms, definitions, symbols and abbreviated terms", "Terms, definitions, symbols and abbreviations", "Terms, definitions and symbols", "Terms, definitions and abbreviations", "Terms, definitions and abbreviated terms"] self.symbols_titles ||= ["Symbols and abbreviated terms", "Symbols", "Abbreviated terms", "Abbreviations"] self.normref_titles ||= ["Normative references"] self.bibliography_titles ||= ["Bibliography"] end |
#filepath_attrs ⇒ Object
72 73 74 75 76 77 |
# File 'lib/metanorma/generic.rb', line 72 def filepath_attrs %i[i18nyaml boilerplate logo_path logo_paths header boilerplate htmlcoverpage htmlintropage htmlstylesheet scripts scripts_pdf standardstylesheet validate_rng_file wordcoverpage wordintropage wordstylesheet pdf_stylesheet] end |
#postprocess_defaults ⇒ Object
may be invoked multiple times, needs to not overwrite
98 99 100 101 102 |
# File 'lib/metanorma/generic.rb', line 98 def postprocess_defaults default_org default_formats default_titles end |
#set_default_value_from_yaml_file(attr, root_path, default_options) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/metanorma/generic.rb', line 146 def set_default_value_from_yaml_file(attr, root_path, ) value = [attr.to_s] value && filepath_attrs.include?(attr) and value = absolute_path(value, root_path) instance_variable_set("@#{attr}", value) end |
#set_default_values_from_yaml_file(config_file) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/metanorma/generic.rb', line 134 def set_default_values_from_yaml_file(config_file) if File.file?(config_file) root_path, = set_default_values_from_yaml_file_prep(config_file) CONFIG_ATTRS.each do |attr| set_default_value_from_yaml_file(attr, root_path, ) end end postprocess_defaults end |
#set_default_values_from_yaml_file_prep(config_file) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/metanorma/generic.rb', line 153 def set_default_values_from_yaml_file_prep(config_file) root_path = File.dirname(config_file) = YAML.safe_load(File.read(config_file, encoding: "UTF-8")) ["doctypes"].is_a? Array and ["doctypes"] = ["doctypes"].each_with_object({}) do |k, m| m[k] = nil end [root_path, ] end |