pdk 2.4.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +803 -1329
- data/LICENSE +201 -201
- data/README.md +165 -163
- data/exe/pdk +10 -10
- data/lib/pdk/analytics/client/google_analytics.rb +143 -143
- data/lib/pdk/analytics/client/noop.rb +25 -25
- data/lib/pdk/analytics/util.rb +19 -19
- data/lib/pdk/analytics.rb +30 -30
- data/lib/pdk/answer_file.rb +12 -12
- data/lib/pdk/bolt.rb +19 -19
- data/lib/pdk/cli/build.rb +82 -82
- data/lib/pdk/cli/bundle.rb +48 -48
- data/lib/pdk/cli/config/get.rb +26 -26
- data/lib/pdk/cli/config.rb +22 -22
- data/lib/pdk/cli/console.rb +148 -148
- data/lib/pdk/cli/convert.rb +52 -52
- data/lib/pdk/cli/env.rb +52 -52
- data/lib/pdk/cli/errors.rb +25 -25
- data/lib/pdk/cli/exec/command.rb +293 -293
- data/lib/pdk/cli/exec/interactive_command.rb +114 -114
- data/lib/pdk/cli/exec.rb +84 -84
- data/lib/pdk/cli/exec_group.rb +104 -104
- data/lib/pdk/cli/get/config.rb +24 -24
- data/lib/pdk/cli/get.rb +20 -20
- data/lib/pdk/cli/module/build.rb +12 -12
- data/lib/pdk/cli/module/generate.rb +47 -47
- data/lib/pdk/cli/module.rb +14 -14
- data/lib/pdk/cli/new/class.rb +32 -32
- data/lib/pdk/cli/new/defined_type.rb +32 -32
- data/lib/pdk/cli/new/fact.rb +29 -29
- data/lib/pdk/cli/new/function.rb +29 -29
- data/lib/pdk/cli/new/module.rb +53 -53
- data/lib/pdk/cli/new/provider.rb +29 -29
- data/lib/pdk/cli/new/task.rb +34 -34
- data/lib/pdk/cli/new/test.rb +52 -52
- data/lib/pdk/cli/new/transport.rb +27 -27
- data/lib/pdk/cli/new.rb +21 -21
- data/lib/pdk/cli/release/prep.rb +39 -39
- data/lib/pdk/cli/release/publish.rb +50 -50
- data/lib/pdk/cli/release.rb +194 -194
- data/lib/pdk/cli/remove/config.rb +80 -80
- data/lib/pdk/cli/remove.rb +20 -20
- data/lib/pdk/cli/set/config.rb +119 -119
- data/lib/pdk/cli/set.rb +20 -20
- data/lib/pdk/cli/test/unit.rb +90 -90
- data/lib/pdk/cli/test.rb +11 -11
- data/lib/pdk/cli/update.rb +64 -64
- data/lib/pdk/cli/util/command_redirector.rb +27 -27
- data/lib/pdk/cli/util/interview.rb +72 -72
- data/lib/pdk/cli/util/option_normalizer.rb +55 -55
- data/lib/pdk/cli/util/option_validator.rb +68 -68
- data/lib/pdk/cli/util/spinner.rb +13 -13
- data/lib/pdk/cli/util/update_manager_printer.rb +82 -82
- data/lib/pdk/cli/util.rb +305 -305
- data/lib/pdk/cli/validate.rb +116 -116
- data/lib/pdk/cli.rb +175 -175
- data/lib/pdk/config/analytics_schema.json +26 -26
- data/lib/pdk/config/errors.rb +5 -5
- data/lib/pdk/config/ini_file.rb +183 -183
- data/lib/pdk/config/ini_file_setting.rb +39 -39
- data/lib/pdk/config/json.rb +34 -34
- data/lib/pdk/config/json_schema_namespace.rb +142 -142
- data/lib/pdk/config/json_schema_setting.rb +53 -53
- data/lib/pdk/config/json_with_schema.rb +49 -49
- data/lib/pdk/config/namespace.rb +354 -354
- data/lib/pdk/config/setting.rb +135 -135
- data/lib/pdk/config/validator.rb +31 -31
- data/lib/pdk/config/yaml.rb +46 -46
- data/lib/pdk/config/yaml_with_schema.rb +59 -59
- data/lib/pdk/config.rb +390 -390
- data/lib/pdk/context/control_repo.rb +60 -60
- data/lib/pdk/context/module.rb +28 -28
- data/lib/pdk/context/none.rb +22 -22
- data/lib/pdk/context.rb +99 -99
- data/lib/pdk/control_repo.rb +90 -90
- data/lib/pdk/generate/defined_type.rb +43 -43
- data/lib/pdk/generate/fact.rb +25 -25
- data/lib/pdk/generate/function.rb +48 -48
- data/lib/pdk/generate/module.rb +352 -352
- data/lib/pdk/generate/provider.rb +28 -28
- data/lib/pdk/generate/puppet_class.rb +43 -43
- data/lib/pdk/generate/puppet_object.rb +232 -232
- data/lib/pdk/generate/task.rb +68 -68
- data/lib/pdk/generate/transport.rb +33 -33
- data/lib/pdk/generate.rb +24 -24
- data/lib/pdk/i18n.rb +4 -4
- data/lib/pdk/logger.rb +45 -45
- data/lib/pdk/module/build.rb +322 -322
- data/lib/pdk/module/convert.rb +296 -296
- data/lib/pdk/module/metadata.rb +202 -202
- data/lib/pdk/module/release.rb +260 -260
- data/lib/pdk/module/update.rb +131 -131
- data/lib/pdk/module/update_manager.rb +227 -227
- data/lib/pdk/module.rb +30 -30
- data/lib/pdk/report/event.rb +370 -370
- data/lib/pdk/report.rb +121 -121
- data/lib/pdk/template/fetcher/git.rb +85 -85
- data/lib/pdk/template/fetcher/local.rb +28 -28
- data/lib/pdk/template/fetcher.rb +98 -98
- data/lib/pdk/template/renderer/v1/legacy_template_dir.rb +116 -116
- data/lib/pdk/template/renderer/v1/renderer.rb +132 -132
- data/lib/pdk/template/renderer/v1/template_file.rb +102 -102
- data/lib/pdk/template/renderer/v1.rb +25 -25
- data/lib/pdk/template/renderer.rb +96 -96
- data/lib/pdk/template/template_dir.rb +67 -67
- data/lib/pdk/template.rb +59 -59
- data/lib/pdk/tests/unit.rb +252 -252
- data/lib/pdk/util/bundler.rb +259 -259
- data/lib/pdk/util/changelog_generator.rb +137 -137
- data/lib/pdk/util/env.rb +47 -47
- data/lib/pdk/util/filesystem.rb +138 -138
- data/lib/pdk/util/git.rb +179 -179
- data/lib/pdk/util/json_finder.rb +85 -85
- data/lib/pdk/util/puppet_strings.rb +125 -125
- data/lib/pdk/util/puppet_version.rb +266 -266
- data/lib/pdk/util/ruby_version.rb +179 -179
- data/lib/pdk/util/template_uri.rb +295 -295
- data/lib/pdk/util/vendored_file.rb +93 -93
- data/lib/pdk/util/version.rb +43 -43
- data/lib/pdk/util/windows/api_types.rb +82 -82
- data/lib/pdk/util/windows/file.rb +36 -36
- data/lib/pdk/util/windows/process.rb +79 -79
- data/lib/pdk/util/windows/string.rb +16 -16
- data/lib/pdk/util/windows.rb +15 -15
- data/lib/pdk/util.rb +278 -278
- data/lib/pdk/validate/control_repo/control_repo_validator_group.rb +23 -23
- data/lib/pdk/validate/control_repo/environment_conf_validator.rb +98 -98
- data/lib/pdk/validate/external_command_validator.rb +208 -208
- data/lib/pdk/validate/internal_ruby_validator.rb +100 -100
- data/lib/pdk/validate/invokable_validator.rb +228 -228
- data/lib/pdk/validate/metadata/metadata_json_lint_validator.rb +86 -86
- data/lib/pdk/validate/metadata/metadata_syntax_validator.rb +78 -78
- data/lib/pdk/validate/metadata/metadata_validator_group.rb +20 -20
- data/lib/pdk/validate/puppet/puppet_epp_validator.rb +133 -133
- data/lib/pdk/validate/puppet/puppet_lint_validator.rb +66 -66
- data/lib/pdk/validate/puppet/puppet_syntax_validator.rb +137 -137
- data/lib/pdk/validate/puppet/puppet_validator_group.rb +21 -21
- data/lib/pdk/validate/ruby/ruby_rubocop_validator.rb +80 -80
- data/lib/pdk/validate/ruby/ruby_validator_group.rb +19 -19
- data/lib/pdk/validate/tasks/tasks_metadata_lint_validator.rb +88 -88
- data/lib/pdk/validate/tasks/tasks_name_validator.rb +50 -50
- data/lib/pdk/validate/tasks/tasks_validator_group.rb +20 -20
- data/lib/pdk/validate/validator.rb +118 -118
- data/lib/pdk/validate/validator_group.rb +104 -104
- data/lib/pdk/validate/yaml/yaml_syntax_validator.rb +95 -95
- data/lib/pdk/validate/yaml/yaml_validator_group.rb +19 -19
- data/lib/pdk/validate.rb +94 -94
- data/lib/pdk/version.rb +4 -4
- data/lib/pdk.rb +76 -76
- data/locales/config.yaml +21 -21
- data/locales/pdk.pot +2111 -2094
- metadata +3 -3
@@ -1,102 +1,102 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
require 'ostruct'
|
3
|
-
|
4
|
-
module PDK
|
5
|
-
module Template
|
6
|
-
module Renderer
|
7
|
-
module V1
|
8
|
-
class TemplateFile < OpenStruct
|
9
|
-
# Initialises the TemplateFile object with the path to the template file
|
10
|
-
# and the data to be used when rendering the template.
|
11
|
-
#
|
12
|
-
# @param template_file [String] The path on disk to the template file.
|
13
|
-
# @param data [Hash{Symbol => Object}] The data that should be provided to
|
14
|
-
# the template when rendering.
|
15
|
-
# @option data [Object] :configs The value of this key will be provided to
|
16
|
-
# the template as an instance variable `@configs` in order to maintain
|
17
|
-
# compatibility with modulesync.
|
18
|
-
#
|
19
|
-
# @api public
|
20
|
-
def initialize(template_file, data = {})
|
21
|
-
@template_file = template_file
|
22
|
-
|
23
|
-
if data.key?(:configs)
|
24
|
-
@configs = data[:configs]
|
25
|
-
end
|
26
|
-
|
27
|
-
super(data)
|
28
|
-
end
|
29
|
-
|
30
|
-
# Renders the template by calling the appropriate engine based on the file
|
31
|
-
# extension.
|
32
|
-
#
|
33
|
-
# If the template has an `.erb` extension, the content of the template
|
34
|
-
# file will be treated as an ERB template. All other extensions are treated
|
35
|
-
# as plain text.
|
36
|
-
#
|
37
|
-
# @return [String] The rendered template
|
38
|
-
#
|
39
|
-
# @raise (see #template_content)
|
40
|
-
#
|
41
|
-
# @api public
|
42
|
-
def render
|
43
|
-
case File.extname(@template_file)
|
44
|
-
when '.erb'
|
45
|
-
render_erb
|
46
|
-
else
|
47
|
-
render_plain
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def config_for(path)
|
52
|
-
return unless respond_to?(:template_dir)
|
53
|
-
|
54
|
-
template_dir.config_for(path)
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
|
59
|
-
# Reads the content of the template file into memory.
|
60
|
-
#
|
61
|
-
# @return [String] The content of the template file.
|
62
|
-
#
|
63
|
-
# @raise [ArgumentError] If the template file does not exist or can not be
|
64
|
-
# read.
|
65
|
-
#
|
66
|
-
# @api private
|
67
|
-
def template_content
|
68
|
-
if PDK::Util::Filesystem.file?(@template_file) && PDK::Util::Filesystem.readable?(@template_file)
|
69
|
-
return PDK::Util::Filesystem.read_file(@template_file)
|
70
|
-
end
|
71
|
-
|
72
|
-
raise ArgumentError, _("'%{template}' is not a readable file") % { template: @template_file }
|
73
|
-
end
|
74
|
-
|
75
|
-
# Renders the content of the template file as an ERB template.
|
76
|
-
#
|
77
|
-
# @return [String] The rendered template.
|
78
|
-
#
|
79
|
-
# @raise (see #template_content)
|
80
|
-
#
|
81
|
-
# @api private
|
82
|
-
def render_erb
|
83
|
-
renderer = ERB.new(template_content, nil, '-')
|
84
|
-
renderer.filename = @template_file
|
85
|
-
renderer.result(binding)
|
86
|
-
end
|
87
|
-
|
88
|
-
# Renders the content of the template file as plain text.
|
89
|
-
#
|
90
|
-
# @return [String] The rendered template.
|
91
|
-
#
|
92
|
-
# @raise (see #template_content)
|
93
|
-
#
|
94
|
-
# @api private
|
95
|
-
def render_plain
|
96
|
-
template_content
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module PDK
|
5
|
+
module Template
|
6
|
+
module Renderer
|
7
|
+
module V1
|
8
|
+
class TemplateFile < OpenStruct
|
9
|
+
# Initialises the TemplateFile object with the path to the template file
|
10
|
+
# and the data to be used when rendering the template.
|
11
|
+
#
|
12
|
+
# @param template_file [String] The path on disk to the template file.
|
13
|
+
# @param data [Hash{Symbol => Object}] The data that should be provided to
|
14
|
+
# the template when rendering.
|
15
|
+
# @option data [Object] :configs The value of this key will be provided to
|
16
|
+
# the template as an instance variable `@configs` in order to maintain
|
17
|
+
# compatibility with modulesync.
|
18
|
+
#
|
19
|
+
# @api public
|
20
|
+
def initialize(template_file, data = {})
|
21
|
+
@template_file = template_file
|
22
|
+
|
23
|
+
if data.key?(:configs)
|
24
|
+
@configs = data[:configs]
|
25
|
+
end
|
26
|
+
|
27
|
+
super(data)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Renders the template by calling the appropriate engine based on the file
|
31
|
+
# extension.
|
32
|
+
#
|
33
|
+
# If the template has an `.erb` extension, the content of the template
|
34
|
+
# file will be treated as an ERB template. All other extensions are treated
|
35
|
+
# as plain text.
|
36
|
+
#
|
37
|
+
# @return [String] The rendered template
|
38
|
+
#
|
39
|
+
# @raise (see #template_content)
|
40
|
+
#
|
41
|
+
# @api public
|
42
|
+
def render
|
43
|
+
case File.extname(@template_file)
|
44
|
+
when '.erb'
|
45
|
+
render_erb
|
46
|
+
else
|
47
|
+
render_plain
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def config_for(path)
|
52
|
+
return unless respond_to?(:template_dir)
|
53
|
+
|
54
|
+
template_dir.config_for(path)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# Reads the content of the template file into memory.
|
60
|
+
#
|
61
|
+
# @return [String] The content of the template file.
|
62
|
+
#
|
63
|
+
# @raise [ArgumentError] If the template file does not exist or can not be
|
64
|
+
# read.
|
65
|
+
#
|
66
|
+
# @api private
|
67
|
+
def template_content
|
68
|
+
if PDK::Util::Filesystem.file?(@template_file) && PDK::Util::Filesystem.readable?(@template_file)
|
69
|
+
return PDK::Util::Filesystem.read_file(@template_file)
|
70
|
+
end
|
71
|
+
|
72
|
+
raise ArgumentError, _("'%{template}' is not a readable file") % { template: @template_file }
|
73
|
+
end
|
74
|
+
|
75
|
+
# Renders the content of the template file as an ERB template.
|
76
|
+
#
|
77
|
+
# @return [String] The rendered template.
|
78
|
+
#
|
79
|
+
# @raise (see #template_content)
|
80
|
+
#
|
81
|
+
# @api private
|
82
|
+
def render_erb
|
83
|
+
renderer = ERB.new(template_content, nil, '-')
|
84
|
+
renderer.filename = @template_file
|
85
|
+
renderer.result(binding)
|
86
|
+
end
|
87
|
+
|
88
|
+
# Renders the content of the template file as plain text.
|
89
|
+
#
|
90
|
+
# @return [String] The rendered template.
|
91
|
+
#
|
92
|
+
# @raise (see #template_content)
|
93
|
+
#
|
94
|
+
# @api private
|
95
|
+
def render_plain
|
96
|
+
template_content
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Template
|
5
|
-
module Renderer
|
6
|
-
module V1
|
7
|
-
autoload :LegacyTemplateDir, 'pdk/template/renderer/v1/legacy_template_dir'
|
8
|
-
autoload :Renderer, 'pdk/template/renderer/v1/renderer'
|
9
|
-
autoload :TemplateFile, 'pdk/template/renderer/v1/template_file'
|
10
|
-
|
11
|
-
# Whether the template directory and context are valid for the V1 renderer
|
12
|
-
# @see PDK::Template::Renderer.instance
|
13
|
-
def self.compatible?(template_root, _context)
|
14
|
-
%w[moduleroot moduleroot_init].all? { |dir| PDK::Util::Filesystem.directory?(File.join(template_root, dir)) }
|
15
|
-
end
|
16
|
-
|
17
|
-
# Creates an instance of the V1 Renderer
|
18
|
-
# @see PDK::Template::Renderer.instance
|
19
|
-
def self.instance(template_root, template_uri, context)
|
20
|
-
PDK::Template::Renderer::V1::Renderer.new(template_root, template_uri, context)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Template
|
5
|
+
module Renderer
|
6
|
+
module V1
|
7
|
+
autoload :LegacyTemplateDir, 'pdk/template/renderer/v1/legacy_template_dir'
|
8
|
+
autoload :Renderer, 'pdk/template/renderer/v1/renderer'
|
9
|
+
autoload :TemplateFile, 'pdk/template/renderer/v1/template_file'
|
10
|
+
|
11
|
+
# Whether the template directory and context are valid for the V1 renderer
|
12
|
+
# @see PDK::Template::Renderer.instance
|
13
|
+
def self.compatible?(template_root, _context)
|
14
|
+
%w[moduleroot moduleroot_init].all? { |dir| PDK::Util::Filesystem.directory?(File.join(template_root, dir)) }
|
15
|
+
end
|
16
|
+
|
17
|
+
# Creates an instance of the V1 Renderer
|
18
|
+
# @see PDK::Template::Renderer.instance
|
19
|
+
def self.instance(template_root, template_uri, context)
|
20
|
+
PDK::Template::Renderer::V1::Renderer.new(template_root, template_uri, context)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,96 +1,96 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
|
3
|
-
module PDK
|
4
|
-
module Template
|
5
|
-
module Renderer
|
6
|
-
autoload :V1, 'pdk/template/renderer/v1'
|
7
|
-
|
8
|
-
# Returns the most appropriate renderer for the given Template Directory and Context
|
9
|
-
#
|
10
|
-
# @param template_root [String] The path to where the template exists on disk
|
11
|
-
# @param template_uri [PDK::Util::TemplateUri] A URI which points to the source location of the Template
|
12
|
-
# @param context [PDK::Context] The context in which the redering will occur in
|
13
|
-
#
|
14
|
-
# @return [AbstractRenderer, nil] An instance of an AbstractRenderer subclass. Returns nil if no renderer could be found
|
15
|
-
def self.instance(template_uri, template_root, context)
|
16
|
-
return V1.instance(template_root, template_uri, context) if V1.compatible?(template_root, context)
|
17
|
-
nil
|
18
|
-
end
|
19
|
-
|
20
|
-
# An abstract class which all Template Renderers should subclass and implement. This class is responsible for
|
21
|
-
# rendering a template or a single item within a template directory
|
22
|
-
#
|
23
|
-
# To implement a new renderer:
|
24
|
-
# 1. Create a new class which subclasses AbstractRenderer and implements the public methods (has_single_item?, render and render_single_item)
|
25
|
-
# 2. Add class methods .compatible? and .instance which are used to detect if a template is compatible with the new renderer
|
26
|
-
# and create an instance of the new renderer respectively
|
27
|
-
# 3. Update the PDK::Template::Renderer.instance method to detect and create an instance of the new renderer (using the .compatible? and .instance methods
|
28
|
-
# created in step 2).
|
29
|
-
#
|
30
|
-
# See the PDK::Template::Renderer::V1 module and classes for an example on how to to this.
|
31
|
-
#
|
32
|
-
# @api private
|
33
|
-
# @abstract
|
34
|
-
class AbstractRenderer
|
35
|
-
# @return [String] The path to where the template exists on disk
|
36
|
-
attr_reader :template_root
|
37
|
-
|
38
|
-
# @return [PDK::Util::TemplateURI] The URI which points to the source location of the Template
|
39
|
-
attr_reader :template_uri
|
40
|
-
|
41
|
-
# @return context [PDK::Context] The context in which the redering will occur in
|
42
|
-
attr_reader :context
|
43
|
-
|
44
|
-
# @param template_root [String] The path to where the template exists on disk
|
45
|
-
# @param template_uri [PDK::Util::TemplateUri] A URI which points to the source location of the Template
|
46
|
-
# @param context [PDK::Context] The context in which the redering will occur in
|
47
|
-
def initialize(template_root, template_uri, context)
|
48
|
-
@template_root = template_root
|
49
|
-
@template_uri = template_uri
|
50
|
-
@context = context
|
51
|
-
end
|
52
|
-
|
53
|
-
# Whether the renderer supports rendering the a single item called 'item_path'. This is used when rendering things like a new Task or a new Puppet Classes.
|
54
|
-
# Rendering a single item is different than redering an entire project, like a entire Puppet Module or Control Repo.
|
55
|
-
#
|
56
|
-
# @param item_path [String] The path to the item to check
|
57
|
-
#
|
58
|
-
# @return [Boolean] Whether the renderer can render the item
|
59
|
-
# @abstract
|
60
|
-
def has_single_item?(_item_path) # rubocop:disable Naming/PredicateName Changing the method name to `single_item?` will convey the wrong intent
|
61
|
-
false
|
62
|
-
end
|
63
|
-
|
64
|
-
# Loop through the files in the template type, yielding each rendered file to the supplied block.
|
65
|
-
#
|
66
|
-
# @param template_type [PDK::Template::*_TEMPLATE_TYPE] The type of template to render
|
67
|
-
# @param name [String] The name to use in the rendering process
|
68
|
-
# @param options [Hash{Object => Object}] A list of options to pass through to the renderer. See PDK::Template::TemplateDir helper methods for other options
|
69
|
-
# @option options [Boolean] :include_first_time Whether to include "first time" items when rendering the project. While it is up to the renderer to implement this
|
70
|
-
# the expected behavior is that if the item already exists, it will not be rendererd again. Unlike normal items which
|
71
|
-
# are always rendered to keep them in-sync
|
72
|
-
#
|
73
|
-
# @yieldparam dest_path [String] The path of the destination file, relative to the root of the context.
|
74
|
-
# @yieldparam dest_content [String] The rendered content of the destination file.
|
75
|
-
# @yieldparam dest_status [Symbol] :unmanage, :delete, :init, :manage
|
76
|
-
#
|
77
|
-
# @see PDK::Template::TemplateDir.render
|
78
|
-
#
|
79
|
-
# @return [void]
|
80
|
-
# @abstract
|
81
|
-
def render(template_type, name, options = {}); end
|
82
|
-
|
83
|
-
# Render a single item and return the resulting string. This is used when rendering things like a new Task or a new Puppet Classes.
|
84
|
-
# Rendering a single item is different than redering an entire project, like a entire Puppet Module or Control Repo. This method is
|
85
|
-
# used in conjunction with .has_single_item?
|
86
|
-
#
|
87
|
-
# @param item_path [String] The path of the single item to render
|
88
|
-
# @param template_data_hash [Hash{Object => Object}] A hash of information which will be used in the rendering process
|
89
|
-
#
|
90
|
-
# @return [String, Nil] The rendered content, or nil of the file could not be rendered
|
91
|
-
# @abstract
|
92
|
-
def render_single_item(item_path, template_data_hash = {}); end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
|
3
|
+
module PDK
|
4
|
+
module Template
|
5
|
+
module Renderer
|
6
|
+
autoload :V1, 'pdk/template/renderer/v1'
|
7
|
+
|
8
|
+
# Returns the most appropriate renderer for the given Template Directory and Context
|
9
|
+
#
|
10
|
+
# @param template_root [String] The path to where the template exists on disk
|
11
|
+
# @param template_uri [PDK::Util::TemplateUri] A URI which points to the source location of the Template
|
12
|
+
# @param context [PDK::Context] The context in which the redering will occur in
|
13
|
+
#
|
14
|
+
# @return [AbstractRenderer, nil] An instance of an AbstractRenderer subclass. Returns nil if no renderer could be found
|
15
|
+
def self.instance(template_uri, template_root, context)
|
16
|
+
return V1.instance(template_root, template_uri, context) if V1.compatible?(template_root, context)
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
# An abstract class which all Template Renderers should subclass and implement. This class is responsible for
|
21
|
+
# rendering a template or a single item within a template directory
|
22
|
+
#
|
23
|
+
# To implement a new renderer:
|
24
|
+
# 1. Create a new class which subclasses AbstractRenderer and implements the public methods (has_single_item?, render and render_single_item)
|
25
|
+
# 2. Add class methods .compatible? and .instance which are used to detect if a template is compatible with the new renderer
|
26
|
+
# and create an instance of the new renderer respectively
|
27
|
+
# 3. Update the PDK::Template::Renderer.instance method to detect and create an instance of the new renderer (using the .compatible? and .instance methods
|
28
|
+
# created in step 2).
|
29
|
+
#
|
30
|
+
# See the PDK::Template::Renderer::V1 module and classes for an example on how to to this.
|
31
|
+
#
|
32
|
+
# @api private
|
33
|
+
# @abstract
|
34
|
+
class AbstractRenderer
|
35
|
+
# @return [String] The path to where the template exists on disk
|
36
|
+
attr_reader :template_root
|
37
|
+
|
38
|
+
# @return [PDK::Util::TemplateURI] The URI which points to the source location of the Template
|
39
|
+
attr_reader :template_uri
|
40
|
+
|
41
|
+
# @return context [PDK::Context] The context in which the redering will occur in
|
42
|
+
attr_reader :context
|
43
|
+
|
44
|
+
# @param template_root [String] The path to where the template exists on disk
|
45
|
+
# @param template_uri [PDK::Util::TemplateUri] A URI which points to the source location of the Template
|
46
|
+
# @param context [PDK::Context] The context in which the redering will occur in
|
47
|
+
def initialize(template_root, template_uri, context)
|
48
|
+
@template_root = template_root
|
49
|
+
@template_uri = template_uri
|
50
|
+
@context = context
|
51
|
+
end
|
52
|
+
|
53
|
+
# Whether the renderer supports rendering the a single item called 'item_path'. This is used when rendering things like a new Task or a new Puppet Classes.
|
54
|
+
# Rendering a single item is different than redering an entire project, like a entire Puppet Module or Control Repo.
|
55
|
+
#
|
56
|
+
# @param item_path [String] The path to the item to check
|
57
|
+
#
|
58
|
+
# @return [Boolean] Whether the renderer can render the item
|
59
|
+
# @abstract
|
60
|
+
def has_single_item?(_item_path) # rubocop:disable Naming/PredicateName Changing the method name to `single_item?` will convey the wrong intent
|
61
|
+
false
|
62
|
+
end
|
63
|
+
|
64
|
+
# Loop through the files in the template type, yielding each rendered file to the supplied block.
|
65
|
+
#
|
66
|
+
# @param template_type [PDK::Template::*_TEMPLATE_TYPE] The type of template to render
|
67
|
+
# @param name [String] The name to use in the rendering process
|
68
|
+
# @param options [Hash{Object => Object}] A list of options to pass through to the renderer. See PDK::Template::TemplateDir helper methods for other options
|
69
|
+
# @option options [Boolean] :include_first_time Whether to include "first time" items when rendering the project. While it is up to the renderer to implement this
|
70
|
+
# the expected behavior is that if the item already exists, it will not be rendererd again. Unlike normal items which
|
71
|
+
# are always rendered to keep them in-sync
|
72
|
+
#
|
73
|
+
# @yieldparam dest_path [String] The path of the destination file, relative to the root of the context.
|
74
|
+
# @yieldparam dest_content [String] The rendered content of the destination file.
|
75
|
+
# @yieldparam dest_status [Symbol] :unmanage, :delete, :init, :manage
|
76
|
+
#
|
77
|
+
# @see PDK::Template::TemplateDir.render
|
78
|
+
#
|
79
|
+
# @return [void]
|
80
|
+
# @abstract
|
81
|
+
def render(template_type, name, options = {}); end
|
82
|
+
|
83
|
+
# Render a single item and return the resulting string. This is used when rendering things like a new Task or a new Puppet Classes.
|
84
|
+
# Rendering a single item is different than redering an entire project, like a entire Puppet Module or Control Repo. This method is
|
85
|
+
# used in conjunction with .has_single_item?
|
86
|
+
#
|
87
|
+
# @param item_path [String] The path of the single item to render
|
88
|
+
# @param template_data_hash [Hash{Object => Object}] A hash of information which will be used in the rendering process
|
89
|
+
#
|
90
|
+
# @return [String, Nil] The rendered content, or nil of the file could not be rendered
|
91
|
+
# @abstract
|
92
|
+
def render_single_item(item_path, template_data_hash = {}); end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -1,67 +1,67 @@
|
|
1
|
-
require 'pdk'
|
2
|
-
require 'forwardable'
|
3
|
-
|
4
|
-
module PDK
|
5
|
-
module Template
|
6
|
-
# A helper class representing an already fetched template on disk, with an appropriate renderer instance.
|
7
|
-
# @see PDK::Template.with
|
8
|
-
class TemplateDir
|
9
|
-
# Creates an instance of TemplateDir object
|
10
|
-
# @see TemplateDir.new
|
11
|
-
def self.instance(uri, path, context, renderer = nil)
|
12
|
-
new(uri, path, context, renderer)
|
13
|
-
end
|
14
|
-
|
15
|
-
extend Forwardable
|
16
|
-
|
17
|
-
# Helper methods for rendering
|
18
|
-
def_delegators :@renderer, :render, :render_single_item, :has_single_item?
|
19
|
-
|
20
|
-
# @return [PDK::Util::TemplateURI] The URI which points to the source location of the Template
|
21
|
-
attr_accessor :uri
|
22
|
-
|
23
|
-
# @return [String] The path to where the template exists on disk
|
24
|
-
attr_accessor :path
|
25
|
-
|
26
|
-
# @return [Hash{String => String}] A hash of information about the template
|
27
|
-
attr_accessor :metadata
|
28
|
-
|
29
|
-
# @param template_uri [PDK::Util::TemplateUri] A URI which points to the source location of the Template
|
30
|
-
# @param path [String] The path to where the template exists on disk
|
31
|
-
# @param context [PDK::Context] The context in which the redering will occur in
|
32
|
-
# @param renderer [PDK::Template::Renderer::AbstractRenderer] The an instance of a rendering class. If nil, a renderer will be created that's appropriate for the template and context
|
33
|
-
def initialize(uri, path, context, renderer = nil)
|
34
|
-
@uri = uri
|
35
|
-
@path = path
|
36
|
-
@metadata = {}
|
37
|
-
|
38
|
-
@renderer = renderer.nil? ? Renderer.instance(uri, path, context) : renderer
|
39
|
-
raise _('Could not find a compatible template renderer for %{path}') % { path: path } if @renderer.nil?
|
40
|
-
end
|
41
|
-
|
42
|
-
# Later additions may include Control Repo rendering, for example
|
43
|
-
#
|
44
|
-
# def render_control_repo(name, options = {})
|
45
|
-
# render(CONTROL_REPO_TEMPLATE_TYPE, name, options.merge(include_first_time: false)) { |*args| yield(*args) }
|
46
|
-
# end
|
47
|
-
#
|
48
|
-
# def render_new_control_repo(name, repo_metadata = {}, options = {})
|
49
|
-
# render(CONTROL_REPO_TEMPLATE_TYPE, name, options.merge(include_first_time: true, control_repo_metadata: repo_metadata)) { |*args| yield(*args) }
|
50
|
-
# end
|
51
|
-
#:nocov: These are just helper methods and are tested elsewhere.
|
52
|
-
|
53
|
-
# Render an existing module
|
54
|
-
# @see PDK::Template::Renderer::AbstractRenderer.render
|
55
|
-
def render_module(module_name, options = {})
|
56
|
-
@renderer.render(MODULE_TEMPLATE_TYPE, module_name, options.merge(include_first_time: false)) { |*args| yield(*args) }
|
57
|
-
end
|
58
|
-
|
59
|
-
# Render a new module
|
60
|
-
# @see PDK::Template::Renderer::AbstractRenderer.render
|
61
|
-
def render_new_module(module_name, module_metadata = {}, options = {})
|
62
|
-
@renderer.render(MODULE_TEMPLATE_TYPE, module_name, options.merge(include_first_time: true, module_metadata: module_metadata)) { |*args| yield(*args) }
|
63
|
-
end
|
64
|
-
#:nocov:
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
1
|
+
require 'pdk'
|
2
|
+
require 'forwardable'
|
3
|
+
|
4
|
+
module PDK
|
5
|
+
module Template
|
6
|
+
# A helper class representing an already fetched template on disk, with an appropriate renderer instance.
|
7
|
+
# @see PDK::Template.with
|
8
|
+
class TemplateDir
|
9
|
+
# Creates an instance of TemplateDir object
|
10
|
+
# @see TemplateDir.new
|
11
|
+
def self.instance(uri, path, context, renderer = nil)
|
12
|
+
new(uri, path, context, renderer)
|
13
|
+
end
|
14
|
+
|
15
|
+
extend Forwardable
|
16
|
+
|
17
|
+
# Helper methods for rendering
|
18
|
+
def_delegators :@renderer, :render, :render_single_item, :has_single_item?
|
19
|
+
|
20
|
+
# @return [PDK::Util::TemplateURI] The URI which points to the source location of the Template
|
21
|
+
attr_accessor :uri
|
22
|
+
|
23
|
+
# @return [String] The path to where the template exists on disk
|
24
|
+
attr_accessor :path
|
25
|
+
|
26
|
+
# @return [Hash{String => String}] A hash of information about the template
|
27
|
+
attr_accessor :metadata
|
28
|
+
|
29
|
+
# @param template_uri [PDK::Util::TemplateUri] A URI which points to the source location of the Template
|
30
|
+
# @param path [String] The path to where the template exists on disk
|
31
|
+
# @param context [PDK::Context] The context in which the redering will occur in
|
32
|
+
# @param renderer [PDK::Template::Renderer::AbstractRenderer] The an instance of a rendering class. If nil, a renderer will be created that's appropriate for the template and context
|
33
|
+
def initialize(uri, path, context, renderer = nil)
|
34
|
+
@uri = uri
|
35
|
+
@path = path
|
36
|
+
@metadata = {}
|
37
|
+
|
38
|
+
@renderer = renderer.nil? ? Renderer.instance(uri, path, context) : renderer
|
39
|
+
raise _('Could not find a compatible template renderer for %{path}') % { path: path } if @renderer.nil?
|
40
|
+
end
|
41
|
+
|
42
|
+
# Later additions may include Control Repo rendering, for example
|
43
|
+
#
|
44
|
+
# def render_control_repo(name, options = {})
|
45
|
+
# render(CONTROL_REPO_TEMPLATE_TYPE, name, options.merge(include_first_time: false)) { |*args| yield(*args) }
|
46
|
+
# end
|
47
|
+
#
|
48
|
+
# def render_new_control_repo(name, repo_metadata = {}, options = {})
|
49
|
+
# render(CONTROL_REPO_TEMPLATE_TYPE, name, options.merge(include_first_time: true, control_repo_metadata: repo_metadata)) { |*args| yield(*args) }
|
50
|
+
# end
|
51
|
+
#:nocov: These are just helper methods and are tested elsewhere.
|
52
|
+
|
53
|
+
# Render an existing module
|
54
|
+
# @see PDK::Template::Renderer::AbstractRenderer.render
|
55
|
+
def render_module(module_name, options = {})
|
56
|
+
@renderer.render(MODULE_TEMPLATE_TYPE, module_name, options.merge(include_first_time: false)) { |*args| yield(*args) }
|
57
|
+
end
|
58
|
+
|
59
|
+
# Render a new module
|
60
|
+
# @see PDK::Template::Renderer::AbstractRenderer.render
|
61
|
+
def render_new_module(module_name, module_metadata = {}, options = {})
|
62
|
+
@renderer.render(MODULE_TEMPLATE_TYPE, module_name, options.merge(include_first_time: true, module_metadata: module_metadata)) { |*args| yield(*args) }
|
63
|
+
end
|
64
|
+
#:nocov:
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|