Class: Metanorma::Taste::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/metanorma/taste/base.rb,
lib/metanorma/taste/stage.rb,
lib/metanorma/taste/doctype.rb,
lib/metanorma/taste/committee.rb

Overview

Base processor for taste-specific document attribute handling

This class handles the processing of AsciiDoc attributes for taste-specific # document generation, including filename-based attributes, value-based attributes, and doctype-specific transformations.

Examples:

Basic usage

config = TasteConfig.from_yaml(yaml_content)
base = Base.new("icc", config, directory: "data/icc")

attrs = [":doctype: specification", ":title: My Document"]
options = {}
processed_attrs = base.process_input_adoc_overrides(attrs, options)

Processing workflow

# 1. File-based attributes are added (copyright, logo, i18n)
# 2. Base override attributes are applied
# 3. Doctype-specific transformations are performed
# 4. Boilerplate authority is set in options if copyright exists

Constant Summary collapse

VALUE_ATTRIBUTE_MAPPINGS =

Mapping of value-based attribute configuration keys to AsciiDoc attribute names

This constant defines how base_override.value_attributes configuration properties are translated into AsciiDoc document attributes.

TODO: metaprogramming to extract these from value_attributes.rb

Examples:

Configuration to attribute mapping

config.base_override.value_attributes.publisher => :publisher:
config.base_override.value_attributes.presentation_metadata_color_secondary => :presentation-metadata-color-secondary:
{
  publisher: "publisher",
  publisher_abbr: "publisher_abbr",
  presentation_metadata_color_secondary: "presentation-metadata-color-secondary",
  presentation_metadata_backcover_text: "presentation-metadata-backcover-text",
  presentation_metadata_ul_label_list: "presentation-metadata-ul-label-list",
  presentation_metadata_annex_delim: "presentation-metadata-annex-delim",
  presentation_metadata_middle_title: "presentation-metadata-middle-title",
  presentation_metadata_ol_label_template_alphabet: "presentation-metadata-ol-label-template-alphabet",
  presentation_metadata_ol_label_template_alphabet_upper: "presentation-metadata-ol-label-template-alphabet_upper",
  presentation_metadata_ol_label_template_roman: "presentation-metadata-ol-label-template-roman",
  presentation_metadata_ol_label_template_roman_upper: "presentation-metadata-ol-label-template-roman_upper",
  presentation_metadata_ol_label_template_arabic: "presentation-metadata-ol-label-template-arabic",
  body_font: "body-font",
  header_font: "header-font",
  monospace_font: "monospace-font",
  fonts: "fonts",
  docidentifier: "docidentifier",
  output_extensions: "output-extensions",
  toclevels: "toclevels",
  htmltoclevels: "toclevels-html",
  doctoclevels: "toclevels-doc",
  pdftoclevels: "toclevels-pdf",
  toc_figures: "toc-figures",
  toc_tables: "toc-tables",
  toc_recommendations: "toc-recommendations",
}.freeze
VALUE_ATTR_ADDITIVE =

Additive value attributes: if the document already has a value for this attribute, add the taste config values to it

{
  fonts: { delimiter: ";" },
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(flavor, config, directory: Dir.pwd) ⇒ Base

Initialize a new Base processor

Examples:

config = TasteConfig.from_yaml(File.read("config.yaml"))
base = Base.new("icc", config, directory: "data/icc")

Parameters:

  • flavor (String, Symbol)

    The taste flavor identifier

  • config (TasteConfig)

    The taste configuration object

  • directory (String) (defaults to: Dir.pwd)

    The base directory for taste files (default: current directory)



94
95
96
97
98
# File 'lib/metanorma/taste/base.rb', line 94

def initialize(flavor, config, directory: Dir.pwd)
  @flavor = flavor
  @config = config
  @directory = directory
end

Instance Attribute Details

#configTasteConfig (readonly)

Returns The taste configuration object.

Returns:



34
35
36
# File 'lib/metanorma/taste/base.rb', line 34

def config
  @config
end

#directoryString (readonly)

is stored, including file attributes

Returns:

  • (String)

    The directory in which the configuration for a taste



38
39
40
# File 'lib/metanorma/taste/base.rb', line 38

def directory
  @directory
end

#flavorString, Symbol (readonly)

Returns The flavor identifier (e.g., :icc, :elf).

Returns:

  • (String, Symbol)

    The flavor identifier (e.g., :icc, :elf)



31
32
33
# File 'lib/metanorma/taste/base.rb', line 31

def flavor
  @flavor
end

Instance Method Details

#build_all_attribute_overrides(attrs) ⇒ Array<Array<String>, Array<String>>

Build all attribute overrides from various sources

This method coordinates the building of attributes from:

  • Filename-based attributes (copyright, logo, i18n, stylesheets)

  • Value-based attributes (publisher, fonts, presentation metadata)

  • Doctype-specific overrides

  • Committee overrides

Parameters:

  • attrs (Array<String>)

    Original attributes array

Returns:

  • (Array<Array<String>, Array<String>>)

    Tuple of [original_attrs, override_attrs]



143
144
145
146
147
148
149
150
151
152
# File 'lib/metanorma/taste/base.rb', line 143

def build_all_attribute_overrides(attrs)
  override_attrs = []
  # Add attributes from different sources
  add_file_based_overrides(override_attrs)
  add_base_configuration_overrides(override_attrs, attrs)
  apply_doctype_overrides(attrs, override_attrs)
  apply_stage_overrides(attrs, override_attrs)
  apply_committee_overrides(attrs, override_attrs)
  [attrs, override_attrs]
end

#process_input_adoc_overrides(attrs, options) ⇒ Array<String>

Process input AsciiDoc attributes with taste-specific overrides

This is the main entry point for attribute processing. It applies file-based overrides, base configuration overrides, and doctype transformations to the input attributes.

settings

Examples:

attrs = [":doctype: specification", ":title: My Document"]
options = {}
result = base.process_input_adoc_overrides(attrs, options)
# => [":doctype: specification", ":title: My Document", ":publisher: ICC", ...]

Parameters:

  • attrs (Array<String>)

    Array of AsciiDoc attribute strings

  • options (Hash)

    Options hash that may be modified with additional

Returns:

  • (Array<String>)

    Modified array of AsciiDoc attributes



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/metanorma/taste/base.rb', line 116

def process_input_adoc_overrides(attrs, options)
  # Insert new attributes after the second element
  # (or at the end if fewer elements)
  insertion_index = calculate_insertion_index(attrs)
  # Build and insert override attributes
  attrs, override_attrs = build_all_attribute_overrides(attrs)
  unless override_attrs.empty?
    attrs.insert(insertion_index,
                 *override_attrs)
  end

  # Set boilerplate authority in options if copyright notice exists
  set_boilerplate_authority_option(options)

  attrs
end