Class: PDK::Template::Renderer::V1::LegacyTemplateDir

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_metadataObject

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

#uriObject (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.

Parameters:

  • dest_path (String)

    The destination path of the file that the

Returns:

  • (Hash)

    The data that will be available to the template via the



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
75
76
77
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 44

def config_for(dest_path, sync_config_path = nil)
  require 'pdk/util'
  require 'pdk/analytics'

  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(:global, {})
  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?
      file_value = if c['unmanaged']
                     'unmanaged'
                   elsif c['delete']
                     'deleted'
                   elsif @sync_config && @sync_config.key?(dest_path)
                     'customized'
                   else
                     'default'
                   end

      PDK.analytics.event('TemplateDir', 'file', label: dest_path, value: file_value)
    end
  end
end

#metadataObject



24
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 24

def ; end

#object_configObject



30
31
32
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 30

def object_config
  config_for(nil)
end

#object_template_forObject



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.

Parameters:

  • loc (String)

    The path of the yaml config file.

Returns:

  • (Hash)

    The data that has been read in from the given yaml file.



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 89

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), [], [], true)
    rescue Psych::SyntaxError => e
      PDK.logger.warn _("'%{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

#renderObject



26
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 26

def render; end

#template_path(_uri) ⇒ Object



110
# File 'lib/pdk/template/renderer/v1/legacy_template_dir.rb', line 110

def template_path(_uri); end