eac_templates 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eac_templates/abstract/directory.rb +42 -0
- data/lib/eac_templates/abstract/file.rb +25 -0
- data/lib/eac_templates/abstract/fs_object.rb +94 -0
- data/lib/eac_templates/abstract/fs_object_by_pathname.rb +13 -0
- data/lib/eac_templates/abstract/not_found_error.rb +8 -0
- data/lib/eac_templates/interface_methods.rb +3 -3
- data/lib/eac_templates/modules/ancestor/directory.rb +4 -2
- data/lib/eac_templates/modules/ancestor/file.rb +3 -2
- data/lib/eac_templates/modules/ancestor/fs_object.rb +6 -13
- data/lib/eac_templates/modules/ancestor.rb +6 -3
- data/lib/eac_templates/patches/module.rb +1 -1
- data/lib/eac_templates/patches/object.rb +1 -1
- data/lib/eac_templates/patches.rb +1 -1
- data/lib/eac_templates/sources/directory.rb +23 -10
- data/lib/eac_templates/sources/file.rb +3 -14
- data/lib/eac_templates/sources/from_all_gems.rb +1 -1
- data/lib/eac_templates/sources/fs_object.rb +17 -17
- data/lib/eac_templates/sources/set.rb +7 -5
- data/lib/eac_templates/variables/content.rb +52 -0
- data/lib/eac_templates/variables/directory.rb +10 -9
- data/lib/eac_templates/variables/file.rb +9 -33
- data/lib/eac_templates/variables/providers/base.rb +2 -1
- data/lib/eac_templates/version.rb +1 -1
- metadata +21 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02c1db1cefd43c90ea04e40096c2bbe73a932827259cc1e249cd830dde64e949
|
4
|
+
data.tar.gz: 3339fb93550f9bdb819b5c7278d5905fd9da0481096115cccaa8eca74f1a704c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eaadc382fd654d49eb8b5c8f9ce40a71f19f01a9181ddbac397cd378baa839706f46578e8428724e2a7b31471159476b8c2b9209cd7a07db81ad3304fd6d35b8
|
7
|
+
data.tar.gz: 4f876c41e037302bcbc4759c442d3466cc9ba30a188a219a7414256bdddb22c7e2777f5b7cc4c005b5f8de2b7f3eefffe7b9b61d79f3a1d0b1b9b65e1b2890aa
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/interface_methods'
|
5
|
+
require 'eac_templates/abstract/fs_object'
|
6
|
+
require 'eac_templates/variables/directory'
|
7
|
+
|
8
|
+
module EacTemplates
|
9
|
+
module Abstract
|
10
|
+
class Directory < ::EacTemplates::Abstract::FsObject
|
11
|
+
enable_abstract_methods
|
12
|
+
delegate(*::EacTemplates::InterfaceMethods::DIRECTORY - %i[child chidren], to: :applier)
|
13
|
+
|
14
|
+
# @param basename [Pathname]
|
15
|
+
# @return [EacTemplates::Abstract::FsObject
|
16
|
+
def build_child(child_basename, child_type)
|
17
|
+
child_basename = child_basename.to_pathname
|
18
|
+
child_type = type_list.value_validate!(child_type)
|
19
|
+
category_module.const_get(child_type.to_s.camelize)
|
20
|
+
.new(owner, self, child_basename, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param basename [Pathname]
|
24
|
+
# @return [EacTemplates::Abstract::FsObject]
|
25
|
+
def child(basename)
|
26
|
+
basename = basename.to_pathname
|
27
|
+
children.find { |c| c.basename == basename } ||
|
28
|
+
raise_not_found("No child found with basename \"#{basename}\"")
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Enumerable<EacTemplates::Abstract::FsObject>]
|
32
|
+
def children
|
33
|
+
children_basenames.map { |c_basename, c_type| build_child(c_basename, c_type) }
|
34
|
+
end
|
35
|
+
|
36
|
+
# @return [Hash<Pathname, Symbol>]
|
37
|
+
def children_basenames
|
38
|
+
raise_abstract_method __method__
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/interface_methods'
|
5
|
+
require 'eac_templates/abstract/fs_object'
|
6
|
+
require 'eac_templates/variables/file'
|
7
|
+
|
8
|
+
module EacTemplates
|
9
|
+
module Abstract
|
10
|
+
class File < ::EacTemplates::Abstract::FsObject
|
11
|
+
enable_abstract_methods
|
12
|
+
delegate(*::EacTemplates::InterfaceMethods::FILE - %i[content path], to: :applier)
|
13
|
+
|
14
|
+
# @return [String]
|
15
|
+
def content
|
16
|
+
path.read
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Pathname]
|
20
|
+
def path
|
21
|
+
raise_abstract_method __method__
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/abstract/fs_object_by_pathname'
|
5
|
+
require 'eac_templates/abstract/not_found_error'
|
6
|
+
|
7
|
+
module EacTemplates
|
8
|
+
module Abstract
|
9
|
+
class FsObject
|
10
|
+
class << self
|
11
|
+
# @param obj [Object]
|
12
|
+
# @return [EacTemplates::Abstract::FsObject, EacTemplates::Abstracts::FsObjectByPathname]
|
13
|
+
def assert(obj)
|
14
|
+
if obj.is_a?(self)
|
15
|
+
obj
|
16
|
+
else
|
17
|
+
::EacTemplates::Abstract::FsObjectByPathname.new(obj)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param owner [Object]
|
22
|
+
# @param parent_object [Object, nil]
|
23
|
+
# @param subpath [Pathname]
|
24
|
+
# @return [EacTemplates::Abstract::FsObject]
|
25
|
+
def by_subpath(owner, parent_object, subpath, options = {})
|
26
|
+
r = nil
|
27
|
+
subpath.to_pathname.each_filename do |basename|
|
28
|
+
r = new(owner, parent_object, basename, options)
|
29
|
+
parent_object = r
|
30
|
+
end
|
31
|
+
r || raise("Subpath is empty: #{subpath}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
enable_abstract_methods
|
36
|
+
enable_simple_cache
|
37
|
+
enable_listable
|
38
|
+
lists.add_symbol :option, :source_set
|
39
|
+
lists.add_symbol :type, :directory, :file
|
40
|
+
common_constructor :owner, :parent_object, :basename, :options, default: [{}] do
|
41
|
+
self.basename = basename.present? ? basename.to_pathname : ::Pathname.new('')
|
42
|
+
self.options = ::EacTemplates::Abstract::FsObject.lists.option.hash_keys_validate!(options)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [EacTemplates::Variables::Directory, EacTemplates::Variables::File]
|
46
|
+
def applier
|
47
|
+
applier_class.new(self)
|
48
|
+
end
|
49
|
+
|
50
|
+
# @return [Class]
|
51
|
+
def applier_class
|
52
|
+
::EacTemplates::Variables.const_get(type.to_s.camelize)
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Module]
|
56
|
+
def category_module
|
57
|
+
self.class.module_parent
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [Pathname]
|
61
|
+
def path_for_search
|
62
|
+
if parent_object.present?
|
63
|
+
parent_object.path_for_search.join(basename)
|
64
|
+
else
|
65
|
+
path_for_search_prefix.join(basename)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# @return [Pathname]
|
70
|
+
def path_for_search_prefix
|
71
|
+
raise_abstract_method __method__
|
72
|
+
end
|
73
|
+
|
74
|
+
def raise_not_found(message)
|
75
|
+
raise ::EacTemplates::Abstract::NotFoundError, message
|
76
|
+
end
|
77
|
+
|
78
|
+
# @return [EacTemplates::Sources::Set]
|
79
|
+
def source_set
|
80
|
+
options[OPTION_SOURCE_SET] || ::EacTemplates::Sources::Set.default
|
81
|
+
end
|
82
|
+
|
83
|
+
# @return [Symbol]
|
84
|
+
def type
|
85
|
+
type_list.value_validate!(self.class.name.demodulize.underscore.to_sym)
|
86
|
+
end
|
87
|
+
|
88
|
+
# @return [EacRubyUtils::Listable::SymbolList]
|
89
|
+
def type_list
|
90
|
+
::EacTemplates::Abstract::FsObject.lists.type
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -2,10 +2,10 @@
|
|
2
2
|
|
3
3
|
module EacTemplates
|
4
4
|
module InterfaceMethods
|
5
|
-
COMMON = %
|
6
|
-
ONLY_DIRECTORY = %
|
5
|
+
COMMON = %i[apply path].freeze
|
6
|
+
ONLY_DIRECTORY = %i[child children].freeze
|
7
7
|
DIRECTORY = COMMON + ONLY_DIRECTORY
|
8
|
-
ONLY_FILE = %
|
8
|
+
ONLY_FILE = %i[apply_to_file content variables].freeze
|
9
9
|
FILE = COMMON + ONLY_FILE
|
10
10
|
ALL = COMMON + ONLY_DIRECTORY + ONLY_FILE
|
11
11
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/abstract/directory'
|
4
5
|
require 'eac_templates/interface_methods'
|
5
6
|
require 'eac_templates/modules/ancestor/fs_object'
|
6
7
|
|
7
8
|
module EacTemplates
|
8
9
|
module Modules
|
9
10
|
class Ancestor
|
10
|
-
class Directory < ::EacTemplates::
|
11
|
-
|
11
|
+
class Directory < ::EacTemplates::Abstract::Directory
|
12
|
+
include ::EacTemplates::Modules::Ancestor::FsObject
|
13
|
+
delegate :children_basenames, to: :source_object
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/abstract/file'
|
4
5
|
require 'eac_templates/interface_methods'
|
5
6
|
require 'eac_templates/modules/ancestor/fs_object'
|
6
7
|
|
7
8
|
module EacTemplates
|
8
9
|
module Modules
|
9
10
|
class Ancestor
|
10
|
-
class File < ::EacTemplates::
|
11
|
-
|
11
|
+
class File < ::EacTemplates::Abstract::File
|
12
|
+
include ::EacTemplates::Modules::Ancestor::FsObject
|
12
13
|
end
|
13
14
|
end
|
14
15
|
end
|
@@ -6,25 +6,18 @@ require 'eac_templates/interface_methods'
|
|
6
6
|
module EacTemplates
|
7
7
|
module Modules
|
8
8
|
class Ancestor
|
9
|
-
|
10
|
-
|
11
|
-
common_constructor :base
|
12
|
-
delegate(*::EacTemplates::InterfaceMethods::COMMON, :found?, to: :source_object)
|
9
|
+
module FsObject
|
10
|
+
delegate :found?, :path, to: :source_object
|
13
11
|
|
14
|
-
# @return [
|
15
|
-
def
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
# @return [Pathname, nil]
|
20
|
-
def path
|
21
|
-
source_object.found? ? source_object.send(:real_paths).first : nil
|
12
|
+
# @return [Pathname]
|
13
|
+
def path_for_search_prefix
|
14
|
+
owner.path_for_search
|
22
15
|
end
|
23
16
|
|
24
17
|
private
|
25
18
|
|
26
19
|
def source_object_uncached
|
27
|
-
|
20
|
+
owner.source_set.send(type, path_for_search)
|
28
21
|
end
|
29
22
|
end
|
30
23
|
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
4
|
require 'eac_templates/interface_methods'
|
5
|
+
require 'eac_templates/abstract/not_found_error'
|
5
6
|
|
6
7
|
module EacTemplates
|
7
8
|
module Modules
|
@@ -20,12 +21,14 @@ module EacTemplates
|
|
20
21
|
|
21
22
|
# @return [EacTemplates::Modules::Directory]
|
22
23
|
def directory
|
23
|
-
::EacTemplates::Modules::Ancestor::Directory
|
24
|
+
@directory ||= ::EacTemplates::Modules::Ancestor::Directory
|
25
|
+
.new(self, nil, nil, source_set: source_set)
|
24
26
|
end
|
25
27
|
|
26
28
|
# @return [EacTemplates::Modules::File]
|
27
29
|
def file
|
28
|
-
@file ||= ::EacTemplates::Modules::Ancestor::File
|
30
|
+
@file ||= ::EacTemplates::Modules::Ancestor::File
|
31
|
+
.new(self, nil, nil, source_set: source_set)
|
29
32
|
end
|
30
33
|
|
31
34
|
# @return [Pathname]
|
@@ -39,7 +42,7 @@ module EacTemplates
|
|
39
42
|
return file if file.found?
|
40
43
|
return directory if directory.found?
|
41
44
|
|
42
|
-
raise "No template found: #{path_for_search}"
|
45
|
+
raise ::EacTemplates::Abstract::NotFoundError, "No template found: #{path_for_search}"
|
43
46
|
end
|
44
47
|
|
45
48
|
require_sub __FILE__
|
@@ -1,23 +1,36 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/abstract/directory'
|
4
5
|
require 'eac_templates/sources/fs_object'
|
5
|
-
require 'eac_templates/variables/directory'
|
6
6
|
|
7
7
|
module EacTemplates
|
8
8
|
module Sources
|
9
|
-
class Directory < ::EacTemplates::
|
10
|
-
|
9
|
+
class Directory < ::EacTemplates::Abstract::Directory
|
10
|
+
include ::EacTemplates::Sources::FsObject
|
11
11
|
|
12
|
-
# @return [
|
13
|
-
def
|
14
|
-
|
12
|
+
# @return [Hash<Pathname, Symbol>]
|
13
|
+
def children_basenames
|
14
|
+
r = {}
|
15
|
+
real_paths.each do |real_path|
|
16
|
+
real_path.children.each do |child|
|
17
|
+
next if r.key?(child.basename)
|
18
|
+
|
19
|
+
r[child.basename] = real_path_type(child)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
r
|
15
23
|
end
|
16
24
|
|
17
|
-
# @
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
# @return [Pathname]
|
26
|
+
def real_path_type(path)
|
27
|
+
if path.file?
|
28
|
+
:file
|
29
|
+
elsif path.directory?
|
30
|
+
:directory
|
31
|
+
else
|
32
|
+
raise "Path \"#{path}\" is not a file nor a directory"
|
33
|
+
end
|
21
34
|
end
|
22
35
|
end
|
23
36
|
end
|
@@ -1,24 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/abstract/file'
|
4
5
|
require 'eac_templates/sources/fs_object'
|
5
|
-
require 'eac_templates/variables/file'
|
6
6
|
|
7
7
|
module EacTemplates
|
8
8
|
module Sources
|
9
|
-
class File < ::EacTemplates::
|
10
|
-
|
11
|
-
|
12
|
-
# @return [Class]
|
13
|
-
def applier_class
|
14
|
-
::EacTemplates::Variables::File
|
15
|
-
end
|
16
|
-
|
17
|
-
# @param path [Pathname]
|
18
|
-
# @return [Boolean]
|
19
|
-
def select_path?(path)
|
20
|
-
super && path.file?
|
21
|
-
end
|
9
|
+
class File < ::EacTemplates::Abstract::File
|
10
|
+
include ::EacTemplates::Sources::FsObject
|
22
11
|
end
|
23
12
|
end
|
24
13
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/abstract/not_found_error'
|
4
5
|
|
5
6
|
module EacTemplates
|
6
7
|
module Sources
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
module FsObject
|
9
|
+
PATH_FOR_SEARCH_PREFIX = ::Pathname.new('')
|
10
|
+
|
11
|
+
common_concern do
|
12
|
+
enable_abstract_methods
|
13
|
+
enable_simple_cache
|
12
14
|
end
|
13
15
|
|
14
16
|
# @return [Boolean]
|
@@ -16,20 +18,18 @@ module EacTemplates
|
|
16
18
|
real_paths.any?
|
17
19
|
end
|
18
20
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
def applier_class
|
23
|
-
raise_abstract_method __method__
|
21
|
+
# @return [Pathname]
|
22
|
+
def path
|
23
|
+
real_paths.first
|
24
24
|
end
|
25
25
|
|
26
|
-
# @return [
|
27
|
-
def
|
28
|
-
|
29
|
-
|
30
|
-
applier_class.new(real_paths.first)
|
26
|
+
# @return [Pathname]
|
27
|
+
def path_for_search_prefix
|
28
|
+
PATH_FOR_SEARCH_PREFIX
|
31
29
|
end
|
32
30
|
|
31
|
+
protected
|
32
|
+
|
33
33
|
# @return [Array<Pathname>]
|
34
34
|
def real_paths_uncached
|
35
35
|
source_set.included_paths.lazy.map { |source_single| source_single_search(source_single) }
|
@@ -39,13 +39,13 @@ module EacTemplates
|
|
39
39
|
# @param path [Pathname]
|
40
40
|
# @return [Boolean]
|
41
41
|
def select_path?(path)
|
42
|
-
path.present?
|
42
|
+
path.present? && path.send("#{type}?")
|
43
43
|
end
|
44
44
|
|
45
45
|
# @param source_single [EacTemplates::Sources::Single]
|
46
46
|
# @return [Pathname, nil]
|
47
47
|
def source_single_search(source_single)
|
48
|
-
r = source_single.search(
|
48
|
+
r = source_single.search(path_for_search)
|
49
49
|
select_path?(r) ? r : nil
|
50
50
|
end
|
51
51
|
end
|
@@ -4,6 +4,7 @@ require 'active_support/core_ext/object/blank'
|
|
4
4
|
require 'eac_templates/sources/directory'
|
5
5
|
require 'eac_templates/sources/file'
|
6
6
|
require 'eac_templates/sources/internal_set'
|
7
|
+
require 'eac_templates/abstract/not_found_error'
|
7
8
|
|
8
9
|
module EacTemplates
|
9
10
|
module Sources
|
@@ -17,16 +18,16 @@ module EacTemplates
|
|
17
18
|
# @param subpath [Pathname]
|
18
19
|
# @return [EacTemplates::Sources::Directory]
|
19
20
|
def directory(subpath)
|
20
|
-
::EacTemplates::Sources::Directory.
|
21
|
+
::EacTemplates::Sources::Directory.by_subpath(self, nil, subpath, source_set: self)
|
21
22
|
end
|
22
23
|
|
23
24
|
# @param subpath [Pathname]
|
24
25
|
# @return [EacTemplates::Sources::Directory]
|
25
26
|
def file(subpath)
|
26
|
-
::EacTemplates::Sources::File.
|
27
|
+
::EacTemplates::Sources::File.by_subpath(self, nil, subpath, source_set: self)
|
27
28
|
end
|
28
29
|
|
29
|
-
def template(subpath, required = true)
|
30
|
+
def template(subpath, required = true) # rubocop:disable Style/OptionalBooleanParameter
|
30
31
|
found_file = file(subpath)
|
31
32
|
return found_file if found_file.found?
|
32
33
|
|
@@ -46,8 +47,9 @@ module EacTemplates
|
|
46
47
|
private
|
47
48
|
|
48
49
|
def raise_template_not_found(subpath)
|
49
|
-
raise
|
50
|
-
|
50
|
+
raise ::EacTemplates::Abstract::NotFoundError,
|
51
|
+
'Template not found for subpath ' \
|
52
|
+
"\"#{subpath}\" (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/variables/providers'
|
5
|
+
|
6
|
+
module EacTemplates
|
7
|
+
module Variables
|
8
|
+
class Content
|
9
|
+
VARIABLE_DELIMITER = ::Regexp.quote('%%')
|
10
|
+
VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
|
11
|
+
|
12
|
+
class << self
|
13
|
+
# @param path [Pathname]
|
14
|
+
# @return [EacTemplates::Variables::Content]
|
15
|
+
def from_file(path)
|
16
|
+
new(path.to_pathname.read)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
enable_simple_cache
|
21
|
+
common_constructor :content
|
22
|
+
|
23
|
+
# +variables_provider+ A [Hash] or object which responds to +read_entry(entry_name)+.
|
24
|
+
def apply(variables_source)
|
25
|
+
variables_provider = ::EacTemplates::Variables::Providers.build(variables_source)
|
26
|
+
variables.inject(content) do |a, e|
|
27
|
+
a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def apply_to_file(variables_source, output_file_path)
|
32
|
+
output_file_path.to_pathname.write(apply(variables_source))
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def variables_uncached
|
38
|
+
content.scan(VARIABLE_PATTERN).map(&:first).to_set do |name| # rubocop:disable Style/MapToSet
|
39
|
+
sanitize_variable_name(name)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def sanitize_variable_name(variable_name)
|
44
|
+
variable_name.to_s.downcase
|
45
|
+
end
|
46
|
+
|
47
|
+
def variable_pattern(name)
|
48
|
+
/#{VARIABLE_DELIMITER}#{::Regexp.quote(name)}#{VARIABLE_DELIMITER}/i
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,16 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_templates/abstract/not_found_error'
|
4
|
+
require 'eac_templates/abstract/directory'
|
3
5
|
require 'eac_templates/variables/file'
|
4
6
|
require 'eac_templates/variables/fs_object'
|
5
7
|
|
6
8
|
module EacTemplates
|
7
9
|
module Variables
|
8
10
|
class Directory
|
9
|
-
|
10
|
-
|
11
|
-
def initialize(path)
|
12
|
-
@path = path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s)
|
11
|
+
common_constructor :abstract_directory do
|
12
|
+
self.abstract_directory = ::EacTemplates::Abstract::Directory.assert(abstract_directory)
|
13
13
|
end
|
14
|
+
delegate :path, to: :abstract_directory
|
14
15
|
|
15
16
|
def apply(variables_source, directory)
|
16
17
|
::EacTemplates::Variables::FsObject.new(self, '.', directory, variables_source).apply
|
@@ -21,7 +22,8 @@ module EacTemplates
|
|
21
22
|
return ::EacTemplates::Variables::File.new(child_path) if ::File.file?(child_path)
|
22
23
|
return ::EacTemplates::Variables::Directory.new(child_path) if ::File.directory?(child_path)
|
23
24
|
|
24
|
-
raise
|
25
|
+
raise ::EacTemplates::Abstract::NotFoundError,
|
26
|
+
"Child \"#{subpath}\" from \"#{path}\" not found"
|
25
27
|
end
|
26
28
|
|
27
29
|
def children
|
@@ -33,10 +35,9 @@ module EacTemplates
|
|
33
35
|
private
|
34
36
|
|
35
37
|
def apply_fs_object(source_relative, target)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
end
|
38
|
+
return unless ::File.directory?(source_absolute(source_relative))
|
39
|
+
|
40
|
+
apply_directory(source_relative, target)
|
40
41
|
end
|
41
42
|
|
42
43
|
def source_absolute(source_relative)
|
@@ -1,49 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/abstract/file'
|
5
|
+
require 'eac_templates/variables/content'
|
4
6
|
require 'eac_templates/variables/providers'
|
5
7
|
|
6
8
|
module EacTemplates
|
7
9
|
module Variables
|
8
10
|
class File
|
9
|
-
VARIABLE_DELIMITER = ::Regexp.quote('%%')
|
10
|
-
VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
|
11
|
-
|
12
11
|
enable_simple_cache
|
13
|
-
common_constructor :
|
14
|
-
self.
|
15
|
-
end
|
16
|
-
|
17
|
-
# +variables_provider+ A [Hash] or object which responds to +read_entry(entry_name)+.
|
18
|
-
def apply(variables_source)
|
19
|
-
variables_provider = ::EacTemplates::Variables::Providers.build(variables_source)
|
20
|
-
variables.inject(content) do |a, e|
|
21
|
-
a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
def apply_to_file(variables_source, output_file_path)
|
26
|
-
output_file_path.to_pathname.write(apply(variables_source))
|
12
|
+
common_constructor :abstract_file do
|
13
|
+
self.abstract_file = ::EacTemplates::Abstract::File.assert(abstract_file)
|
27
14
|
end
|
15
|
+
delegate :path, to: :abstract_file
|
16
|
+
delegate :apply, :apply_to_file, :content, :variables, to: :content_applier
|
28
17
|
|
29
18
|
private
|
30
19
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end.to_set
|
35
|
-
end
|
36
|
-
|
37
|
-
def content_uncached
|
38
|
-
path.read
|
39
|
-
end
|
40
|
-
|
41
|
-
def sanitize_variable_name(variable_name)
|
42
|
-
variable_name.to_s.downcase
|
43
|
-
end
|
44
|
-
|
45
|
-
def variable_pattern(name)
|
46
|
-
/#{VARIABLE_DELIMITER}#{::Regexp.quote(name)}#{VARIABLE_DELIMITER}/i
|
20
|
+
# @return [EacTemplates::Variables::Content]
|
21
|
+
def content_applier_uncached
|
22
|
+
::EacTemplates::Variables::Content.from_file(path)
|
47
23
|
end
|
48
24
|
end
|
49
25
|
end
|
@@ -15,7 +15,8 @@ module EacTemplates
|
|
15
15
|
def variable_value(name)
|
16
16
|
return variable_fetch(name) if variable_exist?(name)
|
17
17
|
|
18
|
-
raise
|
18
|
+
raise ::EacTemplates::Variables::NotFoundError,
|
19
|
+
"Variable \"#{name}\" not found in #{source}"
|
19
20
|
end
|
20
21
|
end
|
21
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Put here the authors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: eac_config
|
@@ -16,42 +16,48 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.14'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.14.1
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
29
|
+
version: '0.14'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.14.1
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: eac_ruby_utils
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - "~>"
|
32
38
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
39
|
+
version: '0.121'
|
34
40
|
type: :runtime
|
35
41
|
prerelease: false
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
37
43
|
requirements:
|
38
44
|
- - "~>"
|
39
45
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
46
|
+
version: '0.121'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: eac_ruby_gem_support
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.
|
53
|
+
version: '0.10'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
60
|
+
version: '0.10'
|
55
61
|
description:
|
56
62
|
email:
|
57
63
|
executables: []
|
@@ -59,6 +65,11 @@ extensions: []
|
|
59
65
|
extra_rdoc_files: []
|
60
66
|
files:
|
61
67
|
- lib/eac_templates.rb
|
68
|
+
- lib/eac_templates/abstract/directory.rb
|
69
|
+
- lib/eac_templates/abstract/file.rb
|
70
|
+
- lib/eac_templates/abstract/fs_object.rb
|
71
|
+
- lib/eac_templates/abstract/fs_object_by_pathname.rb
|
72
|
+
- lib/eac_templates/abstract/not_found_error.rb
|
62
73
|
- lib/eac_templates/core_ext.rb
|
63
74
|
- lib/eac_templates/interface_methods.rb
|
64
75
|
- lib/eac_templates/modules.rb
|
@@ -84,6 +95,7 @@ files:
|
|
84
95
|
- lib/eac_templates/sources/set.rb
|
85
96
|
- lib/eac_templates/sources/single.rb
|
86
97
|
- lib/eac_templates/variables.rb
|
98
|
+
- lib/eac_templates/variables/content.rb
|
87
99
|
- lib/eac_templates/variables/directory.rb
|
88
100
|
- lib/eac_templates/variables/file.rb
|
89
101
|
- lib/eac_templates/variables/fs_object.rb
|
@@ -106,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
118
|
requirements:
|
107
119
|
- - ">="
|
108
120
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
121
|
+
version: '2.7'
|
110
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
123
|
requirements:
|
112
124
|
- - ">="
|