Class: PDK::Template::Renderer::V1::LegacyTemplateDir
- Inherits:
-
Object
- Object
- PDK::Template::Renderer::V1::LegacyTemplateDir
- Defined in:
- lib/pdk/template/renderer/v1/legacy_template_dir.rb
Overview
The old templating code in the PDK passed through a TemplateDir object. This class mimics the methods of that old class so that existing custom templates will still function with the newer refactor templating code. Methods which have no use in custom templates exist but do no nothing, for example ‘def render; end`
:nocov: This class is tested in the packaging and acceptance testing suites
Instance Attribute Summary collapse
-
#module_metadata ⇒ Object
Returns the value of attribute module_metadata.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#config_for(dest_path, sync_config_path = nil) ⇒ Hash
private
Generate a hash of data to be used when rendering the specified template.
-
#initialize(context, uri, path, module_metadata = {}) ⇒ LegacyTemplateDir
constructor
A new instance of LegacyTemplateDir.
- #metadata ⇒ Object
- #object_config ⇒ Object
- #object_template_for ⇒ Object
-
#read_config(loc) ⇒ Hash
private
Generates a hash of data from a given yaml file location.
- #render ⇒ Object
- #template_path(_uri) ⇒ Object
Constructor Details
#initialize(context, uri, path, module_metadata = {}) ⇒ LegacyTemplateDir
Returns a new instance of LegacyTemplateDir.
17 18 19 20 21 22 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 17 def initialize(context, uri, path, = {}) @uri = uri @module_metadata = @context = context @path = path end |
Instance Attribute Details
#module_metadata ⇒ Object
Returns the value of attribute module_metadata.
14 15 16 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 14 def @module_metadata end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
15 16 17 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 15 def uri @uri end |
Instance Method Details
#config_for(dest_path, sync_config_path = nil) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generate a hash of data to be used when rendering the specified template.
data is for, relative to the root of the module.
‘@configs` instance variable.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 44 def config_for(dest_path, sync_config_path = nil) require 'pdk/util' module_root = PDK::Util.module_root sync_config_path ||= File.join(module_root, '.sync.yml') unless module_root.nil? config_path = File.join(@path, 'config_defaults.yml') if @config.nil? require 'deep_merge' conf_defaults = read_config(config_path) @sync_config = read_config(sync_config_path) unless sync_config_path.nil? @config = conf_defaults @config.deep_merge!(@sync_config, knockout_prefix: '---') unless @sync_config.nil? end file_config = @config.fetch('common', {}).clone file_config['module_metadata'] = @module_metadata file_config.merge!(@config.fetch(dest_path, {})) unless dest_path.nil? file_config.merge!(@config).tap do |c| if uri.default? if c['unmanaged'] 'unmanaged' elsif c['delete'] 'deleted' elsif @sync_config&.key?(dest_path) 'customized' else 'default' end end end end |
#metadata ⇒ Object
24 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 24 def ; end |
#object_config ⇒ Object
30 31 32 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 30 def object_config config_for(nil) end |
#object_template_for ⇒ Object
28 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 28 def object_template_for; end |
#read_config(loc) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Generates a hash of data from a given yaml file location.
if so.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 86 def read_config(loc) if PDK::Util::Filesystem.file?(loc) && PDK::Util::Filesystem.readable?(loc) require 'yaml' begin YAML.safe_load(PDK::Util::Filesystem.read_file(loc), permitted_classes: [], permitted_symbols: [], aliases: true) rescue Psych::SyntaxError => e PDK.logger.warn format("'%{file}' is not a valid YAML file: %{problem} %{context} at line %{line} column %{column}", file: loc, problem: e.problem, context: e.context, line: e.line, column: e.column) {} end else {} end end |
#render ⇒ Object
26 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 26 def render; end |
#template_path(_uri) ⇒ Object
102 |
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 102 def template_path(_uri); end |