Class: Hyla::Configuration
Constant Summary collapse
- DEFAULTS =
{ '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' => { 'source-highlighter' => 'coderay', 'linkcss!' => 'true', 'data-uri' => 'true', 'stylesheet' => 'asciidoctor.css', 'stylesdir' => 'styles' }, 'safe' => 'unsafe', 'header_footer' => true }
- IncludeDirectiveRx =
Matches an include preprocessor directive.
Examples
include::chapter1.ad[] include::example.txt[lines=1;2;5..10]
/^\\?include::([^\[]+)\[(.*?)\]$/
- INCLUDE_PREFIX =
'include::'
- INCLUDE_SUFFIX =
'[]'
- INDEX_SUFFIX =
'_AllSlides.txt'
- SNIPPET_TAG =
'snippet'
- HEADER =
":data-uri:\n" + ":icons: font\n" + ":last-update-label!:\n" + ":source-highlighter: coderay\n"
- HEADER_INDEX =
":data-uri:\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 =
'.ad'
- PREFIX_ARTEFACT =
'asciidoc_'
- TEMPLATES =
'../../lib/templates'
- RESOURCES =
'../../lib/resources'
- 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'
Instance Attribute Summary collapse
-
#ADOC_EXT ⇒ Object
readonly
Returns the value of attribute ADOC_EXT.
-
#backends ⇒ Object
readonly
Returns the value of attribute backends.
-
#cover_template ⇒ Object
readonly
Returns the value of attribute cover_template.
-
#DEFAULTS ⇒ Object
readonly
Returns the value of attribute DEFAULTS.
-
#fonts ⇒ Object
readonly
Returns the value of attribute fonts.
-
#HEADER ⇒ Object
readonly
Returns the value of attribute HEADER.
-
#HEADER_INDEX ⇒ Object
readonly
Returns the value of attribute HEADER_INDEX.
-
#INCLUDE_PREFIX ⇒ Object
readonly
Returns the value of attribute INCLUDE_PREFIX.
-
#INCLUDE_SUFFIX ⇒ Object
readonly
Returns the value of attribute INCLUDE_SUFFIX.
-
#INDEX_SUFFIX ⇒ Object
readonly
Returns the value of attribute INDEX_SUFFIX.
-
#LEVEL_1 ⇒ Object
readonly
Returns the value of attribute LEVEL_1.
-
#LEVEL_2 ⇒ Object
readonly
Returns the value of attribute LEVEL_2.
-
#PREFIX_ARTEFACT ⇒ Object
readonly
Returns the value of attribute PREFIX_ARTEFACT.
-
#resources ⇒ Object
readonly
Returns the value of attribute resources.
-
#samples ⇒ Object
readonly
Returns the value of attribute samples.
-
#SKIP_CHARACTERS ⇒ Object
readonly
Returns the value of attribute SKIP_CHARACTERS.
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
-
#templates ⇒ Object
readonly
Returns the value of attribute templates.
-
#YAML_CONFIG_FILE_NAME ⇒ Object
readonly
Returns the value of attribute YAML_CONFIG_FILE_NAME.
Class Method Summary collapse
-
.backends ⇒ Object
Backends Location.
-
.cover_template ⇒ Object
Cover Slim Template.
-
.extract_attributes(attributes) ⇒ Object
Retrieve asciidoctor attributes Could be an Arrays of Strings key=value,key=value or Could be a Hash (DEFAULTS, CONFIG_File).
-
.fonts ⇒ Object
Fonts Location.
-
.parse(override) ⇒ Object
Public: Generate a Hyla configuration Hash by merging the default options with anything in _config.yaml, and adding the given options on top.
-
.read_config_file(filename) ⇒ Object
Read YAML Config file.
-
.resources ⇒ Object
Resources Location.
-
.safe_load_file(filename) ⇒ Object
Load Safely YAML File.
-
.samples ⇒ Object
Samples Location.
-
.styles ⇒ Object
Stylesheets Location.
-
.templates ⇒ Object
Templates Location.
Instance Method Summary collapse
-
#stringify_keys ⇒ Object
Public: Turn all keys into string.
-
#transform_keys_to_symbols(hash) ⇒ Object
Take keys of hash and transform those to a symbols.
Methods inherited from Hash
Instance Attribute Details
#ADOC_EXT ⇒ Object (readonly)
Returns the value of attribute ADOC_EXT.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def ADOC_EXT @ADOC_EXT end |
#backends ⇒ Object (readonly)
Returns the value of attribute backends.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def backends @backends end |
#cover_template ⇒ Object (readonly)
Returns the value of attribute cover_template.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def cover_template @cover_template end |
#DEFAULTS ⇒ Object (readonly)
Returns the value of attribute DEFAULTS.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def DEFAULTS @DEFAULTS end |
#fonts ⇒ Object (readonly)
Returns the value of attribute fonts.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def fonts @fonts end |
#HEADER ⇒ Object (readonly)
Returns the value of attribute HEADER.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def HEADER @HEADER end |
#HEADER_INDEX ⇒ Object (readonly)
Returns the value of attribute HEADER_INDEX.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def HEADER_INDEX @HEADER_INDEX end |
#INCLUDE_PREFIX ⇒ Object (readonly)
Returns the value of attribute INCLUDE_PREFIX.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def INCLUDE_PREFIX @INCLUDE_PREFIX end |
#INCLUDE_SUFFIX ⇒ Object (readonly)
Returns the value of attribute INCLUDE_SUFFIX.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def INCLUDE_SUFFIX @INCLUDE_SUFFIX end |
#INDEX_SUFFIX ⇒ Object (readonly)
Returns the value of attribute INDEX_SUFFIX.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def INDEX_SUFFIX @INDEX_SUFFIX end |
#LEVEL_1 ⇒ Object (readonly)
Returns the value of attribute LEVEL_1.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def LEVEL_1 @LEVEL_1 end |
#LEVEL_2 ⇒ Object (readonly)
Returns the value of attribute LEVEL_2.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def LEVEL_2 @LEVEL_2 end |
#PREFIX_ARTEFACT ⇒ Object (readonly)
Returns the value of attribute PREFIX_ARTEFACT.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def PREFIX_ARTEFACT @PREFIX_ARTEFACT end |
#resources ⇒ Object (readonly)
Returns the value of attribute resources.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def resources @resources end |
#samples ⇒ Object (readonly)
Returns the value of attribute samples.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def samples @samples end |
#SKIP_CHARACTERS ⇒ Object (readonly)
Returns the value of attribute SKIP_CHARACTERS.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def SKIP_CHARACTERS @SKIP_CHARACTERS end |
#styles ⇒ Object (readonly)
Returns the value of attribute styles.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def styles @styles end |
#templates ⇒ Object (readonly)
Returns the value of attribute templates.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def templates @templates end |
#YAML_CONFIG_FILE_NAME ⇒ Object (readonly)
Returns the value of attribute YAML_CONFIG_FILE_NAME.
4 5 6 |
# File 'lib/hyla/configuration.rb', line 4 def YAML_CONFIG_FILE_NAME @YAML_CONFIG_FILE_NAME end |
Class Method Details
.backends ⇒ Object
Backends Location
128 129 130 |
# File 'lib/hyla/configuration.rb', line 128 def self.backends File.(BACKENDS, File.dirname(__FILE__)) end |
.cover_template ⇒ Object
Cover Slim Template
93 94 95 |
# File 'lib/hyla/configuration.rb', line 93 def self.cover_template File.(COVER_TEMPLATE, File.dirname(__FILE__)) end |
.extract_attributes(attributes) ⇒ Object
Retrieve asciidoctor attributes Could be an Arrays of Strings key=value,key=value or Could be a Hash (DEFAULTS, CONFIG_File)
247 248 249 250 251 252 253 254 255 |
# File 'lib/hyla/configuration.rb', line 247 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 ⇒ Object
Fonts Location
121 122 123 |
# File 'lib/hyla/configuration.rb', line 121 def self.fonts File.(FONTS, File.dirname(__FILE__)) end |
.parse(override) ⇒ Object
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.
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/hyla/configuration.rb', line 147 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 that we receive from Hyla override = Configuration[override].stringify_keys Hyla::logger.debug("OVERRIDE Keys: #{override.inspect}") # Clone DEFAULTS config = DEFAULTS Hyla::logger.debug("DEFAULTS Keys: #{config.inspect}") # # 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 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 end |
.read_config_file(filename) ⇒ Object
Read YAML Config file
192 193 194 195 196 197 198 199 |
# File 'lib/hyla/configuration.rb', line 192 def self.read_config_file(filename) f = File.(filename) Hyla::logger.info("Config file to be parsed : #{f}") config = safe_load_file(f) config rescue SystemCallError Hyla::logger.warn "No configuration file retrieved for the name : #{filename}" end |
.resources ⇒ Object
Resources Location
107 108 109 |
# File 'lib/hyla/configuration.rb', line 107 def self.resources File.(RESOURCES, File.dirname(__FILE__)) end |
.safe_load_file(filename) ⇒ Object
Load Safely YAML File
204 205 206 |
# File 'lib/hyla/configuration.rb', line 204 def self.safe_load_file(filename) YAML.safe_load_file(filename) end |
.samples ⇒ Object
Samples Location
135 136 137 |
# File 'lib/hyla/configuration.rb', line 135 def self.samples File.(SAMPLES, File.dirname(__FILE__)) end |
.styles ⇒ Object
Stylesheets Location
114 115 116 |
# File 'lib/hyla/configuration.rb', line 114 def self.styles File.(STYLES, File.dirname(__FILE__)) end |
.templates ⇒ Object
Templates Location
100 101 102 |
# File 'lib/hyla/configuration.rb', line 100 def self.templates File.(TEMPLATES, File.dirname(__FILE__)) end |
Instance Method Details
#stringify_keys ⇒ Object
Public: Turn all keys into string
Return a copy of the hash where all its keys are strings
211 212 213 |
# File 'lib/hyla/configuration.rb', line 211 def stringify_keys reduce({}) { |hsh, (k, v)| hsh.merge(k.to_s => v) } end |
#transform_keys_to_symbols(hash) ⇒ Object
Take keys of hash and transform those to a symbols
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/hyla/configuration.rb', line 218 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 |