eac_tools 0.60.2 → 0.61.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +34 -29
- data/lib/eac_tools/version.rb +1 -1
- data/sub/avm/avm.gemspec +1 -1
- data/sub/avm/lib/avm/version.rb +1 -1
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/header_lines.rb +1 -1
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/pre_process_line.rb +16 -4
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document.rb +23 -1
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/base.rb +21 -0
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/breadcrumbs.rb +55 -0
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs/document_builder.rb +63 -0
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/child_docs.rb +35 -0
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros/default_body.rb +21 -0
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/macros.rb +13 -0
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/sources/base.rb +5 -1
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/version.rb +1 -1
- data/sub/avm-eac_ruby_base1/avm-eac_ruby_base1.gemspec +2 -2
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/source_generators/base.rb +2 -2
- data/sub/avm-eac_ruby_base1/lib/avm/eac_ruby_base1/version.rb +1 -1
- data/sub/avm-eac_ubuntu_base0/Gemfile +3 -0
- data/sub/avm-eac_ubuntu_base0/avm-eac_ubuntu_base0.gemspec +1 -1
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/docker_image.rb +1 -1
- data/sub/avm-eac_ubuntu_base0/lib/avm/eac_ubuntu_base0/version.rb +1 -1
- data/sub/avm-files/avm-files.gemspec +5 -5
- data/sub/avm-files/lib/avm/files/appendable/templatized_directory.rb +2 -2
- data/sub/avm-files/lib/avm/files/version.rb +1 -1
- data/sub/eac_templates/Gemfile +8 -0
- data/sub/eac_templates/eac_templates.gemspec +19 -0
- data/sub/eac_templates/lib/eac_templates/core_ext.rb +4 -0
- data/sub/eac_templates/lib/eac_templates/interface_methods.rb +12 -0
- data/sub/eac_templates/lib/eac_templates/modules/ancestor/directory.rb +15 -0
- data/sub/eac_templates/lib/eac_templates/modules/ancestor/file.rb +15 -0
- data/sub/eac_templates/lib/eac_templates/modules/ancestor/fs_object.rb +32 -0
- data/sub/eac_templates/lib/eac_templates/modules/ancestor.rb +48 -0
- data/sub/eac_templates/lib/eac_templates/modules/base.rb +35 -0
- data/sub/eac_templates/lib/eac_templates/modules.rb +9 -0
- data/sub/eac_templates/lib/eac_templates/patches/module/erb_template.rb +9 -0
- data/sub/eac_templates/lib/eac_templates/patches/module/template.rb +9 -0
- data/sub/eac_templates/lib/eac_templates/patches/module.rb +4 -0
- data/sub/eac_templates/lib/eac_templates/patches/object/erb_template.rb +9 -0
- data/sub/eac_templates/lib/eac_templates/patches/object/template.rb +9 -0
- data/sub/eac_templates/lib/eac_templates/patches/object.rb +4 -0
- data/sub/eac_templates/lib/eac_templates/patches.rb +4 -0
- data/sub/eac_templates/lib/eac_templates/sources/directory.rb +24 -0
- data/sub/eac_templates/lib/eac_templates/sources/file.rb +24 -0
- data/sub/eac_templates/lib/eac_templates/sources/from_all_gems.rb +4 -0
- data/sub/eac_templates/lib/eac_templates/sources/from_gem.rb +37 -0
- data/sub/eac_templates/lib/eac_templates/sources/fs_object.rb +53 -0
- data/sub/eac_templates/lib/eac_templates/sources/internal_set.rb +22 -0
- data/sub/eac_templates/lib/eac_templates/sources/set.rb +54 -0
- data/sub/eac_templates/lib/eac_templates/sources/single.rb +29 -0
- data/sub/eac_templates/lib/eac_templates/sources.rb +9 -0
- data/sub/eac_templates/lib/eac_templates/variables/directory.rb +47 -0
- data/sub/eac_templates/lib/eac_templates/variables/file.rb +50 -0
- data/sub/eac_templates/lib/eac_templates/variables/fs_object.rb +65 -0
- data/sub/eac_templates/lib/eac_templates/variables/not_found_error.rb +7 -0
- data/sub/eac_templates/lib/eac_templates/variables/providers/base.rb +23 -0
- data/sub/eac_templates/lib/eac_templates/variables/providers/config_reader.rb +29 -0
- data/sub/eac_templates/lib/eac_templates/variables/providers/entries_reader.rb +25 -0
- data/sub/eac_templates/lib/eac_templates/variables/providers/generic.rb +25 -0
- data/sub/eac_templates/lib/eac_templates/variables/providers/hash.rb +29 -0
- data/sub/eac_templates/lib/eac_templates/variables/providers.rb +25 -0
- data/sub/eac_templates/lib/eac_templates/variables.rb +9 -0
- data/sub/eac_templates/lib/eac_templates/version.rb +5 -0
- data/sub/eac_templates/lib/eac_templates.rb +7 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec.rb +120 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/a_module/a/a_a +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/a_module/b +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/super_class/a/a_b +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path1/super_class/b +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/a/a_b +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/b +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/a_module/c +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/sub_class/b +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/super_class/a/a_b +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/module/template_spec_files/path2/super_class/b +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/object/template_spec.rb +26 -0
- data/sub/eac_templates/spec/lib/eac_templates/patches/object/template_spec_files/path/my_stub_with_template +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/sources/set_spec.rb +42 -0
- data/sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path1/subdir1/file1.template +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path1/subdir1/file2 +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/sources/set_spec_files/path2/subdir1/file3.template +1 -0
- data/sub/eac_templates/spec/lib/eac_templates/variables/file_spec.rb +35 -0
- data/sub/eac_templates/spec/lib/eac_templates/variables/file_spec_files/expected_content +2 -0
- data/sub/eac_templates/spec/lib/eac_templates/variables/file_spec_files/source.template +2 -0
- data/sub/eac_templates/spec/rubocop_spec.rb +3 -0
- data/sub/eac_templates/spec/spec_helper.rb +4 -0
- metadata +79 -14
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/breadcrumbs_macro_value.rb +0 -59
- data/sub/avm-eac_asciidoctor_base0/lib/avm/eac_asciidoctor_base0/instances/build/document/child_docs_macro_value.rb +0 -49
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
require 'eac_templates/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = 'eac_templates'
|
9
|
+
s.version = EacTemplates::VERSION
|
10
|
+
s.authors = ['Put here the authors']
|
11
|
+
s.summary = 'Put here de description.'
|
12
|
+
|
13
|
+
s.files = Dir['{lib}/**/*']
|
14
|
+
|
15
|
+
s.add_dependency 'eac_config', '~> 0.12'
|
16
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.112'
|
17
|
+
|
18
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.5.1'
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module EacTemplates
|
4
|
+
module InterfaceMethods
|
5
|
+
COMMON = %w[apply path].freeze
|
6
|
+
ONLY_DIRECTORY = %w[child children].freeze
|
7
|
+
DIRECTORY = COMMON + ONLY_DIRECTORY
|
8
|
+
ONLY_FILE = %w[apply_to_file content variables].freeze
|
9
|
+
FILE = COMMON + ONLY_FILE
|
10
|
+
ALL = COMMON + ONLY_DIRECTORY + ONLY_FILE
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/interface_methods'
|
5
|
+
require 'eac_templates/modules/ancestor/fs_object'
|
6
|
+
|
7
|
+
module EacTemplates
|
8
|
+
module Modules
|
9
|
+
class Ancestor
|
10
|
+
class Directory < ::EacTemplates::Modules::Ancestor::FsObject
|
11
|
+
delegate(*::EacTemplates::InterfaceMethods::ONLY_DIRECTORY, to: :source_object)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/interface_methods'
|
5
|
+
require 'eac_templates/modules/ancestor/fs_object'
|
6
|
+
|
7
|
+
module EacTemplates
|
8
|
+
module Modules
|
9
|
+
class Ancestor
|
10
|
+
class File < ::EacTemplates::Modules::Ancestor::FsObject
|
11
|
+
delegate(*::EacTemplates::InterfaceMethods::ONLY_FILE, to: :source_object)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/interface_methods'
|
5
|
+
|
6
|
+
module EacTemplates
|
7
|
+
module Modules
|
8
|
+
class Ancestor
|
9
|
+
class FsObject
|
10
|
+
enable_simple_cache
|
11
|
+
common_constructor :base
|
12
|
+
delegate(*::EacTemplates::InterfaceMethods::COMMON, :found?, to: :source_object)
|
13
|
+
|
14
|
+
# @return [Symbol]
|
15
|
+
def object_type
|
16
|
+
self.class.name.demodulize.underscore.to_sym
|
17
|
+
end
|
18
|
+
|
19
|
+
# @return [Pathname, nil]
|
20
|
+
def path
|
21
|
+
source_object.found? ? source_object.send(:real_paths).first : nil
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def source_object_uncached
|
27
|
+
base.source_set.send(object_type, base.path_for_search)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/interface_methods'
|
5
|
+
|
6
|
+
module EacTemplates
|
7
|
+
module Modules
|
8
|
+
class Ancestor
|
9
|
+
class << self
|
10
|
+
# @param a_module [Module]
|
11
|
+
# @return [Pathname]
|
12
|
+
def path_for_search(a_module)
|
13
|
+
a_module.name.underscore.to_pathname
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
common_constructor :base, :ancestor
|
18
|
+
delegate :subpath, :source_set, to: :base
|
19
|
+
delegate(*::EacTemplates::InterfaceMethods::ALL, to: :source_object)
|
20
|
+
|
21
|
+
# @return [EacTemplates::Modules::Directory]
|
22
|
+
def directory
|
23
|
+
::EacTemplates::Modules::Ancestor::Directory.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [EacTemplates::Modules::File]
|
27
|
+
def file
|
28
|
+
@file ||= ::EacTemplates::Modules::Ancestor::File.new(self)
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Pathname]
|
32
|
+
def path_for_search
|
33
|
+
r = self.class.path_for_search(ancestor)
|
34
|
+
subpath.if_present(r) { |v| r.join(v) }
|
35
|
+
end
|
36
|
+
|
37
|
+
# @return [EacTemplates::Modules::Ancestor::FsObject]
|
38
|
+
def source_object
|
39
|
+
return file if file.found?
|
40
|
+
return directory if directory.found?
|
41
|
+
|
42
|
+
raise "No template found: #{path_for_search}"
|
43
|
+
end
|
44
|
+
|
45
|
+
require_sub __FILE__
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/interface_methods'
|
5
|
+
require 'eac_templates/modules/ancestor'
|
6
|
+
require 'eac_templates/sources/set'
|
7
|
+
|
8
|
+
module EacTemplates
|
9
|
+
module Modules
|
10
|
+
class Base
|
11
|
+
enable_listable
|
12
|
+
lists.add_symbol :option, :source_set, :subpath
|
13
|
+
common_constructor :the_module, :options, default: [{}] do
|
14
|
+
self.options = self.class.lists.option.hash_keys_validate!(options)
|
15
|
+
end
|
16
|
+
delegate(*::EacTemplates::InterfaceMethods::ALL, :path_for_search, :source_object,
|
17
|
+
to: :self_ancestor)
|
18
|
+
|
19
|
+
# @return [EacTemplates::Modules::Ancestor]
|
20
|
+
def self_ancestor
|
21
|
+
@self_ancestor ||= ::EacTemplates::Modules::Ancestor.new(self, the_module)
|
22
|
+
end
|
23
|
+
|
24
|
+
# @return [EacTemplates::SourceSet]
|
25
|
+
def source_set
|
26
|
+
options[OPTION_SOURCE_SET] || ::EacTemplates::Sources::Set.default
|
27
|
+
end
|
28
|
+
|
29
|
+
# @return [Pathname, nil]
|
30
|
+
def subpath
|
31
|
+
options[OPTION_SUBPATH].if_present(&:to_pathname)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/sources/fs_object'
|
5
|
+
require 'eac_templates/variables/directory'
|
6
|
+
|
7
|
+
module EacTemplates
|
8
|
+
module Sources
|
9
|
+
class Directory < ::EacTemplates::Sources::FsObject
|
10
|
+
delegate :apply, :child, :children, :path, to: :applier
|
11
|
+
|
12
|
+
# @return [Class]
|
13
|
+
def applier_class
|
14
|
+
::EacTemplates::Variables::Directory
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param path [Pathname]
|
18
|
+
# @return [Boolean]
|
19
|
+
def select_path?(path)
|
20
|
+
super && path.directory?
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/sources/fs_object'
|
5
|
+
require 'eac_templates/variables/file'
|
6
|
+
|
7
|
+
module EacTemplates
|
8
|
+
module Sources
|
9
|
+
class File < ::EacTemplates::Sources::FsObject
|
10
|
+
delegate :apply, :apply_to_file, :content, :path, :variables, to: :applier
|
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
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/sources/set'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
module Sources
|
7
|
+
class FromGem
|
8
|
+
class << self
|
9
|
+
def include_all(searcher = nil)
|
10
|
+
::Gem::Specification.each { |gemspec| new(gemspec, searcher).include }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
TEMPLATES_DIR_SUBPATH = 'template'
|
15
|
+
|
16
|
+
common_constructor :gemspec, :searcher, default: [nil] do
|
17
|
+
self.searcher ||= ::EacTemplates::Sources::Set.default
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Boolean]
|
21
|
+
delegate :exist?, to: :path
|
22
|
+
|
23
|
+
# @return [Pathname]
|
24
|
+
def include
|
25
|
+
return nil unless exist?
|
26
|
+
|
27
|
+
searcher.included_paths << path
|
28
|
+
path
|
29
|
+
end
|
30
|
+
|
31
|
+
# @return [Pathname]
|
32
|
+
def path
|
33
|
+
gemspec.gem_dir.to_pathname.join(TEMPLATES_DIR_SUBPATH)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
module Sources
|
7
|
+
class FsObject
|
8
|
+
enable_abstract_methods
|
9
|
+
enable_simple_cache
|
10
|
+
common_constructor :source_set, :subpath do
|
11
|
+
self.subpath = subpath.to_pathname
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Boolean]
|
15
|
+
def found?
|
16
|
+
real_paths.any?
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
# @return [Class]
|
22
|
+
def applier_class
|
23
|
+
raise_abstract_method __method__
|
24
|
+
end
|
25
|
+
|
26
|
+
# @return [EacTemplates::Variables::SourceFile]
|
27
|
+
def applier_uncached
|
28
|
+
raise "No #{self.class.name.downcase} found for \"#{subpath}\"" unless found?
|
29
|
+
|
30
|
+
applier_class.new(real_paths.first)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @return [Array<Pathname>]
|
34
|
+
def real_paths_uncached
|
35
|
+
source_set.included_paths.lazy.map { |source_single| source_single_search(source_single) }
|
36
|
+
.select(&:present?)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param path [Pathname]
|
40
|
+
# @return [Boolean]
|
41
|
+
def select_path?(path)
|
42
|
+
path.present?
|
43
|
+
end
|
44
|
+
|
45
|
+
# @param source_single [EacTemplates::Sources::Single]
|
46
|
+
# @return [Pathname, nil]
|
47
|
+
def source_single_search(source_single)
|
48
|
+
r = source_single.search(subpath)
|
49
|
+
select_path?(r) ? r : nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/sources/single'
|
5
|
+
|
6
|
+
module EacTemplates
|
7
|
+
module Sources
|
8
|
+
class InternalSet < ::Set
|
9
|
+
# @param single [EacTemplates::Sources::Single]
|
10
|
+
# @return [self]
|
11
|
+
def add(single)
|
12
|
+
super(::EacTemplates::Sources::Single.assert(single))
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param single [EacTemplates::Sources::Single]
|
16
|
+
# @return [self]
|
17
|
+
def <<(single)
|
18
|
+
add(single)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'eac_templates/sources/directory'
|
5
|
+
require 'eac_templates/sources/file'
|
6
|
+
require 'eac_templates/sources/internal_set'
|
7
|
+
|
8
|
+
module EacTemplates
|
9
|
+
module Sources
|
10
|
+
class Set
|
11
|
+
class << self
|
12
|
+
def default
|
13
|
+
@default ||= new
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# @param subpath [Pathname]
|
18
|
+
# @return [EacTemplates::Sources::Directory]
|
19
|
+
def directory(subpath)
|
20
|
+
::EacTemplates::Sources::Directory.new(self, subpath)
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param subpath [Pathname]
|
24
|
+
# @return [EacTemplates::Sources::Directory]
|
25
|
+
def file(subpath)
|
26
|
+
::EacTemplates::Sources::File.new(self, subpath)
|
27
|
+
end
|
28
|
+
|
29
|
+
def template(subpath, required = true)
|
30
|
+
found_file = file(subpath)
|
31
|
+
return found_file if found_file.found?
|
32
|
+
|
33
|
+
found_directory = directory(subpath)
|
34
|
+
return found_directory if found_directory.found?
|
35
|
+
|
36
|
+
return nil unless required
|
37
|
+
|
38
|
+
raise_template_not_found(subpath)
|
39
|
+
end
|
40
|
+
|
41
|
+
# @return [EacTemplates::Sources::InternalSet]
|
42
|
+
def included_paths
|
43
|
+
@included_paths ||= ::EacTemplates::Sources::InternalSet.new
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def raise_template_not_found(subpath)
|
49
|
+
raise "Template not found for subpath \"#{subpath}\"" \
|
50
|
+
" (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
module Sources
|
7
|
+
class Single
|
8
|
+
class << self
|
9
|
+
# @param object [EacTemplates::Sources::Single, Pathname]
|
10
|
+
# @return [EacTemplates::Sources::Single]
|
11
|
+
def assert(object)
|
12
|
+
return object if object.is_a?(self)
|
13
|
+
|
14
|
+
new(object.to_pathname)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
common_constructor :path do
|
19
|
+
self.path = path.to_pathname.expand_path
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Pathname, nil]
|
23
|
+
def search(subpath)
|
24
|
+
r = path.join(subpath)
|
25
|
+
r.exist? ? r : nil
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/variables/file'
|
4
|
+
require 'eac_templates/variables/fs_object'
|
5
|
+
|
6
|
+
module EacTemplates
|
7
|
+
module Variables
|
8
|
+
class Directory
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
def initialize(path)
|
12
|
+
@path = path.is_a?(::Pathname) ? path : ::Pathname.new(path.to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def apply(variables_source, directory)
|
16
|
+
::EacTemplates::Variables::FsObject.new(self, '.', directory, variables_source).apply
|
17
|
+
end
|
18
|
+
|
19
|
+
def child(subpath)
|
20
|
+
child_path = ::File.join(path, subpath)
|
21
|
+
return ::EacTemplates::Variables::File.new(child_path) if ::File.file?(child_path)
|
22
|
+
return ::EacTemplates::Variables::Directory.new(child_path) if ::File.directory?(child_path)
|
23
|
+
|
24
|
+
raise "Child \"#{subpath}\" from \"#{path}\" not found"
|
25
|
+
end
|
26
|
+
|
27
|
+
def children
|
28
|
+
path.children.map do |path_child|
|
29
|
+
child(path_child.basename.to_path)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def apply_fs_object(source_relative, target)
|
36
|
+
if ::File.directory?(source_absolute(source_relative))
|
37
|
+
apply_directory(source_relative, target)
|
38
|
+
elsif ::File.file?(source_absolute(source_relative))
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def source_absolute(source_relative)
|
43
|
+
::File.expand_path(source_relative, path)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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 File
|
9
|
+
VARIABLE_DELIMITER = ::Regexp.quote('%%')
|
10
|
+
VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
|
11
|
+
|
12
|
+
enable_simple_cache
|
13
|
+
common_constructor :path do
|
14
|
+
self.path = path.to_pathname
|
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))
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def variables_uncached
|
32
|
+
content.scan(VARIABLE_PATTERN).map(&:first).map do |name|
|
33
|
+
sanitize_variable_name(name)
|
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
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|