Module: Pandocomatic::PandocomaticYAML

Defined in:
lib/pandocomatic/pandocomatic_yaml.rb

Overview

PandocomaticYAML is a wrapper around ruby’s YAML library that replaces occurrences of “$(X)$” in the YAML by the value of the evironment variable

  1. If variable X cannot be found, an exception is thrown.

Constant Summary collapse

PERMITTED_YAML_CLASSES =

List of classes that are permitted in YAML

[Date].freeze
VAR_PATTERN =

Regular expression representing environment variables in templates

/\$\((?<var>[a-zA-Z_][a-zA-Z0-9_]*)\)\$/

Class Method Summary collapse

Class Method Details

.load(str, path = nil) ⇒ Hash

Load a string, substitute any variables, and parse as YAML.

Parameters:

  • str (String)

    String to parse as YAML

  • path (Path|Nil) (defaults to: nil)

    Path of the source of the string, if any

Returns:

  • (Hash)

Raises:



43
44
45
# File 'lib/pandocomatic/pandocomatic_yaml.rb', line 43

def self.load(str, path = nil)
  YAML.safe_load substitute_variables(str, path), permitted_classes: PERMITTED_YAML_CLASSES
end

.load_file(path) ⇒ Hash

Load a text file, substitute any variables, and parse as YAML.

Parameters:

  • path (String)

    Path to text file to parse as YAML

Returns:

  • (Hash)

Raises:



52
53
54
# File 'lib/pandocomatic/pandocomatic_yaml.rb', line 52

def self.load_file(path)
  self.load File.read(path), path
end