Module: Textus::Manifest::Entry::Publish::Template

Defined in:
lib/textus/manifest/entry/publish/template.rb

Overview

The publish_each template vocabulary. A publish_each value is a path with ‘leaf`, `basename`, `key`, `ext` placeholders; a publish_tree value must be a plain path (any var is an error), so the modes reuse VAR_RE to detect stray vars there too.

Constant Summary collapse

KNOWN_VARS =
%w[leaf basename key ext].freeze
VAR_RE =
/\{([a-z]+)\}/
REQUIRED_DISCRIMINATOR_VARS =
%w[leaf basename key].freeze

Class Method Summary collapse

Class Method Details

.expand(template, vars) ⇒ Object

Substitute ‘var` placeholders from a string-keyed hash.



15
16
17
# File 'lib/textus/manifest/entry/publish/template.rb', line 15

def self.expand(template, vars)
  template.gsub(VAR_RE) { vars.fetch(::Regexp.last_match(1)) }
end