lib/hyla/configuration.rb in hyla-1.0.3 vs lib/hyla/configuration.rb in hyla-1.0.4
- old
+ new
@@ -1,37 +1,47 @@
module Hyla
class Configuration < Hash
attr_reader :HEADER, :INDEX_SUFFIX, :HEADER_INDEX, :INCLUDE_PREFIX, :INCLUDE_SUFFIX, :LEVEL_1, :LEVEL_2, :SKIP_CHARACTERS,
:ADOC_EXT, :PREFIX_ARTEFACT, :YAML_CONFIG_FILE_NAME, :DEFAULTS,
- :templates, :samples, :resources, :styles, :backends
+ :templates, :cover_template, :samples, :resources, :styles, :fonts, :backends
DEFAULTS = {
- 'source' => Dir.pwd,
- 'destination' => File.join(Dir.pwd, 'generated_content'),
- 'watch_dir' => '.',
- 'watch_ext' => %w(ad adoc asc asciidoc txt index),
+ 'source' => Dir.pwd,
+ 'destination' => File.join(Dir.pwd, 'generated_content'),
+ 'watch_dir' => '.',
+ 'watch_ext' => %w(ad adoc asc asciidoc txt index),
# Asciidoctor
- 'backend' => 'html5',
- 'eruby' => 'erb',
- 'doctype' => 'article',
- 'compact' => false,
- 'to_dir' => '.',
- 'to_file' => '',
- 'attributes' => {
+ 'backend' => 'html5',
+ 'eruby' => 'erb',
+ 'doctype' => 'article',
+ 'compact' => false,
+ 'to_dir' => '.',
+ 'to_file' => '',
+ 'attributes' => {
'source-highlighter' => 'coderay',
- 'linkcss!' => 'true',
- 'data-uri' => 'true',
- 'stylesheet' => 'asciidoctor.css',
- 'stylesdir' => 'styles'
+ 'linkcss!' => 'true',
+ 'data-uri' => 'true',
+ 'stylesheet' => 'asciidoctor.css',
+ 'stylesdir' => 'styles'
},
- 'safe' => 'unsafe',
+ 'safe' => 'unsafe',
'header_footer' => true
}
+ #
+ # Matches an include preprocessor directive.
+ #
+ # Examples
+ #
+ # include::chapter1.ad[]
+ # include::example.txt[lines=1;2;5..10]
+ #
+ IncludeDirectiveRx = /^\\?include::([^\[]+)\[(.*?)\]$/
+
INCLUDE_PREFIX = 'include::'
INCLUDE_SUFFIX = '[]'
INDEX_SUFFIX = '_AllSlides.txt'
@@ -40,23 +50,24 @@
":icons: font\n" +
":last-update-label!:\n" +
":source-highlighter: coderay\n"
HEADER_INDEX = ":data-uri:\n" +
- ":navigation:\n" +
- ":menu:\n" +
- ":status:\n" +
- ":goto:\n" +
- ":notitle:\n"
+ ":navigation: # navigation attribute used for DeckJS Slideshow\n" +
+ ":menu: # navigation attribute used for DeckJS Slideshow\n" +
+ ":status: # navigation attribute used for DeckJS Slideshow\n" +
+ ":goto: # navigation attribute used for DeckJS Slideshow\n" +
+ ":notitle: \n" +
+ ":toc: left # Comment or uncomment this attribute if you don't need to display left part of the HTML page a table of content\n"
LEVEL_1 = '= '
LEVEL_2 = '== '
SKIP_CHARACTERS = '>>'
- ADOC_EXT = '.adoc'
+ ADOC_EXT = '.ad'
PREFIX_ARTEFACT = 'asciidoc_'
TEMPLATES = '../../lib/templates'
@@ -64,15 +75,26 @@
SAMPLES = '../../lib/templates/sample'
STYLES = '../../lib/resources/styles'
+ FONTS = '../../lib/resources/fonts'
+
BACKENDS = '../../lib/resources/backends'
+ COVER_TEMPLATE = '../../lib/resources/cover.slim'
+
YAML_CONFIG_FILE_NAME = '_config.yaml'
#
+ # Cover Slim Template
+ #
+ def self.cover_template
+ File.expand_path(COVER_TEMPLATE, File.dirname(__FILE__))
+ end
+
+ #
# Templates Location
#
def self.templates
File.expand_path(TEMPLATES, File.dirname(__FILE__))
end
@@ -90,10 +112,17 @@
def self.styles
File.expand_path(STYLES, File.dirname(__FILE__))
end
#
+ # Fonts Location
+ #
+ def self.fonts
+ File.expand_path(FONTS, File.dirname(__FILE__))
+ end
+
+ #
# Backends Location
#
def self.backends
File.expand_path(BACKENDS, File.dirname(__FILE__))
end
@@ -131,17 +160,25 @@
# Clone DEFAULTS
config = DEFAULTS
Hyla::logger.debug("DEFAULTS Keys: #{config.inspect}")
- # Read YAML config file IF it exists and
- # Merge content with DEFAULT config
- new_config = read_config_file(YAML_CONFIG_FILE_NAME)
- Hyla::logger.debug("OVERRIDE Keys: #{new_config.inspect}") if !new_config.nil?
- config = config.deep_merge(new_config) if !new_config.nil?
+ #
+ # Read the config file passed as parameter if it exists
+ # otherwise read default _config.yaml file if it exists and
+ # merge content with DEFAULT config
+ #
+ alt_config = read_config_file(override['config']) if override['config']
+ if !alt_config.nil?
+ config = config.deep_merge(alt_config)
+ else
+ new_config = read_config_file(YAML_CONFIG_FILE_NAME)
+ Hyla::logger.debug("OVERRIDE Keys: #{new_config.inspect}") if !new_config.nil?
+ config = config.deep_merge(new_config) if !new_config.nil?
+ end
- # Merge DEFAULTS < _config.yaml < override
+ # Merge DEFAULTS < _config.yaml or your_config.yaml file < override
config = config.deep_merge(override)
# Convert String Keys to Symbols Keys
config = Configuration[].transform_keys_to_symbols(config)
Hyla::logger.debug("Merged Keys: #{config.inspect}")
return config
@@ -154,11 +191,11 @@
f = File.expand_path(filename)
Hyla::logger.info("Config file to be parsed : #{f}")
config = safe_load_file(f)
config
rescue SystemCallError
- Hyla::logger.warn "No _config.yaml file retrieved"
+ Hyla::logger.warn "No configuration file retrieved for the name : #{filename}"
end
#
# Load Safely YAML File
#
@@ -178,20 +215,23 @@
#
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
+ 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
+ else
+ value
end
result[new_key] = new_value
result
}
end
\ No newline at end of file