class Hyla::Configuration

Constants

ADOC_EXT

ADOC_EXT = '.ad'

ASSESSMENT_TXT
ASSETS
AUDIO_TXT
BACKENDS
CONFIGS
COVERS
COVER_TEMPLATE
COVER_TXT
DEFAULTS
FONTS
HEADER_INDEX
HEADER_TXT
INCLUDE_PREFIX
INCLUDE_SUFFIX
INDEX
INDEX_FILE
INDEX_SUFFIX
IncludeDirectiveRx

Matches an include preprocessor directive.

Examples

include::chapter1.ad[]
include::example.txt[lines=1;2;5..10]
LABS_TXT
LEVEL_1
LEVEL_2
NEW_COVER_TEMPLATE
OBJECTIVES_TXT
PREFIX_ARTEFACT
RESOURCES
SAMPLES
SKIP_CHARACTERS
SNIPPET_TAG
STYLES
SUMMARY_TXT
TEMPLATES
YAML_CONFIG_FILE_NAME

Attributes

ADOC_EXT[R]
DEFAULTS[R]
HEADER[R]
HEADER_INDEX[R]
INCLUDE_PREFIX[R]
INCLUDE_SUFFIX[R]
INDEX_SUFFIX[R]
LEVEL_1[R]
LEVEL_2[R]
PREFIX_ARTEFACT[R]
SKIP_CHARACTERS[R]
YAML_CONFIG_FILE_NAME[R]
assets[R]
backends[R]
configs[R]
cover_template[R]
fonts[R]
resources[R]
samples[R]
styles[R]
templates[R]

Public Class Methods

assets() click to toggle source

Assets Location

# File lib/hyla/configuration.rb, line 118
def self.assets
  File.expand_path(ASSETS, File.dirname(__FILE__))
end
backends() click to toggle source

Backends Location

# File lib/hyla/configuration.rb, line 125
def self.backends
  File.expand_path(BACKENDS, File.dirname(__FILE__))
end
configs() click to toggle source

Config Location

# File lib/hyla/configuration.rb, line 83
def self.configs
  File.expand_path(CONFIGS, File.dirname(__FILE__))
end
cover_template() click to toggle source

Cover Slim Template

# File lib/hyla/configuration.rb, line 69
def self.cover_template
  File.expand_path(COVER_TEMPLATE, File.dirname(__FILE__))
end
covers() click to toggle source

Cover Slim Template

# File lib/hyla/configuration.rb, line 76
def self.covers
  File.expand_path(COVERS, File.dirname(__FILE__))
end
extract_attributes(attributes) click to toggle source

Retrieve asciidoctor attributes Could be an Arrays of Strings key=value,key=value or Could be a Hash (DEFAULTS, CONFIG_File)

# File lib/hyla/configuration.rb, line 213
def self.extract_attributes(attributes)
  result = attributes.split(',')
  attributes = Hash.new
  result.each do |entry|
    words = entry.split('=')
    attributes[words[0]] = words[1]
  end
  return attributes
end
fonts() click to toggle source

Fonts Location

# File lib/hyla/configuration.rb, line 111
def self.fonts
  File.expand_path(FONTS, File.dirname(__FILE__))
end
parse(override) click to toggle source

Public: Generate a Hyla configuration Hash by merging the default options with anything in _config.yaml, and adding the given options on top.

override - A Hash of options that override any options in both

the defaults and the config file. See Hyla::Configuration::DEFAULTS for a
list of option names and their defaults.

Returns the final configuration Hash.

# File lib/hyla/configuration.rb, line 144
def self.parse(override)

  # Extract Asciidoctor attributes received from hyla command line '-a key=value,key=value'
  # Convert them to a Hash of attributes 'attributes' => { 'backend' => html5 ... }
  # Assign hash to override[:attributes]
  extracted_attributes = self.extract_attributes(override[:attributes]) if override[:attributes]
  override[:attributes] = extracted_attributes if extracted_attributes

  extracted_email_attributes = self.extract_attributes(override[:email_attributes]) if override[:email_attributes]
  override[:email_attributes] = extracted_email_attributes if extracted_email_attributes

  # Stringify keys of the hash
  override = Configuration[override].stringify_keys
  Hyla::logger2.debug("OVERRIDE Keys: #{override.inspect}")
  
  # Config
  config = DEFAULTS
  Hyla::logger2.debug("DEFAULTS Keys: #{config.inspect}")

  #
  # Check if config parameter was passed and split content which is a list of files
  # Read each config file and merge content with DEFAULTS
  # Otherwise, check if there is a _config.yaml
  #
  configs = override['config'].split(",").map(&:strip) if override['config']
  if !configs.nil? && !configs.empty?
    configs.each do |cfg_file|
      cfg = read_config_file(cfg_file)
      config = config.deep_merge(cfg)
    end
  else
    new_config = read_config_file(YAML_CONFIG_FILE_NAME)
    Hyla::logger2.debug("OVERRIDE Keys: #{new_config.inspect}") if !new_config.nil?
    config = config.deep_merge(new_config) if !new_config.nil? && !new_config.empty?
  end

  # Merge files with parameters  coming from the cmd line
  config = config.deep_merge(override)
  Hyla::logger2.debug("DEFAULTS Keys: #{config.inspect}")
  # Convert String Keys to Symbols Keys
  config = Configuration[].transform_keys_to_symbols(config)
  Hyla::logger2.debug("Merged Keys: #{config.inspect}")
  return config
end
read_config_file(filename) click to toggle source

Read YAML Config file

# File lib/hyla/configuration.rb, line 192
def self.read_config_file(filename)
  f = File.expand_path(filename)
  Hyla::logger2.info("Config file to be parsed : #{f}")
  safe_load_file(f)
rescue SystemCallError
  Hyla::logger2.error "No configuration file retrieved for : #{filename}"
  nil
end
resources() click to toggle source

Resources Location

# File lib/hyla/configuration.rb, line 97
def self.resources
  File.expand_path(RESOURCES, File.dirname(__FILE__))
end
safe_load_file(filename) click to toggle source

Load Safely YAML File

# File lib/hyla/configuration.rb, line 204
def self.safe_load_file(filename)
  YAML.safe_load_file(filename)
end
samples() click to toggle source

Samples Location

# File lib/hyla/configuration.rb, line 132
def self.samples
  File.expand_path(SAMPLES, File.dirname(__FILE__))
end
styles() click to toggle source

Stylesheets Location

# File lib/hyla/configuration.rb, line 104
def self.styles
  File.expand_path(STYLES, File.dirname(__FILE__))
end
templates() click to toggle source

Templates Location

# File lib/hyla/configuration.rb, line 90
def self.templates
  File.expand_path(TEMPLATES, File.dirname(__FILE__))
end

Public Instance Methods

stringify_keys() click to toggle source

Public: Turn all keys into string

Return a copy of the hash where all its keys are strings

# File lib/hyla/configuration.rb, line 226
def stringify_keys
  reduce({}) { |hsh, (k, v)| hsh.merge(k.to_s => v) }
end
transform_keys_to_symbols(hash) click to toggle source

Take keys of hash and transform those to a symbols

# File lib/hyla/configuration.rb, line 233
def transform_keys_to_symbols(hash)
  return hash if not hash.is_a?(Hash)
  hash.inject({}) { |result, (key, value)|
    new_key = case key
                when String then
                  key.to_sym
                else
                  key
              end
    new_value = case value
                  when Hash
                    if key.eql? 'attributes'
                      value
                    else
                      transform_keys_to_symbols(value)
                    end
                  else
                    value
                end
    result[new_key] = new_value
    result
  }
end