ehbrs-tools 0.27.0 → 0.28.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 -13
- data/lib/ehbrs/tools/runner/fs/selected.rb +1 -5
- data/lib/ehbrs/tools/runner/music/lyrics.rb +3 -4
- data/lib/ehbrs/tools/runner/music/lyrics_book.rb +41 -0
- data/lib/ehbrs/tools/runner/music/selected.rb +6 -6
- data/lib/ehbrs/tools/version.rb +1 -1
- data/lib/ehbrs/user_dirs.rb +2 -2
- data/spec/lib/ehbrs/tools/runner/fs/used_space_spec.rb +2 -1
- data/vendor/eac_fs/Gemfile +5 -0
- data/vendor/eac_fs/eac_fs.gemspec +20 -0
- data/vendor/{eac_ruby_utils/lib/eac_ruby_utils/filesystem_cache.rb → eac_fs/lib/eac_fs/cache.rb} +7 -2
- data/vendor/eac_fs/lib/eac_fs/file_info.rb +24 -0
- data/vendor/eac_fs/lib/eac_fs/patches/module/fs_cache.rb +10 -0
- data/vendor/eac_fs/lib/eac_fs/patches/module.rb +4 -0
- data/vendor/eac_fs/lib/eac_fs/patches/object/fs_cache.rb +10 -0
- data/vendor/eac_fs/lib/eac_fs/patches/object.rb +4 -0
- data/vendor/eac_fs/lib/eac_fs/patches/pathname/info.rb +12 -0
- data/vendor/eac_fs/lib/eac_fs/patches/pathname.rb +4 -0
- data/vendor/eac_fs/lib/eac_fs/patches.rb +4 -0
- data/vendor/eac_fs/lib/eac_fs/version.rb +5 -0
- data/vendor/eac_fs/lib/eac_fs.rb +7 -0
- data/vendor/{eac_ruby_utils/spec/lib/eac_ruby_utils/filesystem_cache_spec.rb → eac_fs/spec/lib/eac_fs/cache_spec.rb} +2 -2
- data/vendor/eac_fs/spec/rubocop_spec.rb +3 -0
- data/vendor/eac_fs/spec/spec_helper.rb +4 -0
- data/vendor/eac_ruby_base0/eac_ruby_base0.gemspec +2 -1
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/application.rb +3 -3
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/core_ext.rb +1 -0
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/runner.rb +16 -7
- data/vendor/eac_ruby_base0/lib/eac_ruby_base0/version.rb +1 -1
- data/vendor/eac_ruby_gems_utils/Gemfile +5 -0
- data/vendor/eac_ruby_gems_utils/LICENCE +16 -0
- data/vendor/eac_ruby_gems_utils/README.rdoc +3 -0
- data/vendor/eac_ruby_gems_utils/eac_ruby_gems_utils.gemspec +30 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/command.rb +33 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem/version_file.rb +41 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/gem.rb +97 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/base.rb +58 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/minitest.rb +25 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/decorated_gem.rb +48 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple/result.rb +25 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/multiple.rb +84 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests/rspec.rb +21 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/tests.rb +9 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils/version.rb +5 -0
- data/vendor/eac_ruby_gems_utils/lib/eac_ruby_gems_utils.rb +7 -0
- data/vendor/eac_ruby_gems_utils/spec/code/rubocop_check_spec.rb +3 -0
- data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec.rb +14 -0
- data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem/version_file_spec_files/a_version_file.rb +7 -0
- data/vendor/eac_ruby_gems_utils/spec/lib/eac_ruby_gems_utils/gem_spec.rb +20 -0
- data/vendor/eac_ruby_gems_utils/spec/spec_helper.rb +4 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/Gemfile +5 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/Gemfile.lock +19 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/Rakefile +14 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/exe/myrunner +5 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/lib/mygem/version.rb +5 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/lib/mygem.rb +5 -0
- data/vendor/eac_ruby_gems_utils/spec/support/mygem/mygem.gemspec +16 -0
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/version.rb +1 -1
- data/vendor/eac_templates/Gemfile +5 -0
- data/vendor/eac_templates/eac_templates.gemspec +19 -0
- data/vendor/eac_templates/lib/eac_templates/directory.rb +108 -0
- data/vendor/eac_templates/lib/eac_templates/file.rb +48 -0
- data/vendor/eac_templates/lib/eac_templates/patches/module/erb_template.rb +9 -0
- data/vendor/eac_templates/lib/eac_templates/patches/module/template.rb +10 -0
- data/vendor/eac_templates/lib/eac_templates/patches/module.rb +4 -0
- data/vendor/eac_templates/lib/eac_templates/patches/object/erb_template.rb +9 -0
- data/vendor/eac_templates/lib/eac_templates/patches/object/template.rb +9 -0
- data/vendor/eac_templates/lib/eac_templates/patches/object.rb +4 -0
- data/vendor/eac_templates/lib/eac_templates/patches.rb +4 -0
- data/vendor/eac_templates/lib/eac_templates/searcher.rb +53 -0
- data/vendor/eac_templates/lib/eac_templates/variable_not_found_error.rb +5 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/base.rb +21 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/config_reader.rb +27 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/entries_reader.rb +23 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/generic.rb +23 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers/hash.rb +27 -0
- data/vendor/eac_templates/lib/eac_templates/variable_providers.rb +23 -0
- data/vendor/eac_templates/lib/eac_templates/version.rb +5 -0
- data/vendor/eac_templates/lib/eac_templates.rb +7 -0
- data/vendor/eac_templates/spec/lib/eac_templates/file_spec.rb +35 -0
- data/vendor/eac_templates/spec/lib/eac_templates/file_spec_files/expected_content +2 -0
- data/vendor/eac_templates/spec/lib/eac_templates/file_spec_files/source.template +2 -0
- data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec.rb +30 -0
- data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path1/subdir1/file1.template +1 -0
- data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path1/subdir1/file2 +1 -0
- data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path2/subdir1/file3.template +1 -0
- data/vendor/eac_templates/spec/lib/object/template_spec.rb +23 -0
- data/vendor/eac_templates/spec/lib/object/template_spec_files/path/my_stub_with_template +1 -0
- data/vendor/eac_templates/spec/rubocop_spec.rb +3 -0
- data/vendor/eac_templates/spec/spec_helper.rb +4 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/core_ext.rb +5 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected/build.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected/build_file.rb +1 -1
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected.rb +2 -2
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/album.rb +42 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/resource.rb +64 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book/song.rb +68 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/music/lyrics_book.rb +65 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/patches/object.rb +4 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/patches.rb +4 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/version.rb +1 -1
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/album/inner.html.erb +3 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/custom_style.css +11 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/index.html.erb +14 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/main.html.erb +24 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/resource/main.html.erb +8 -0
- data/vendor/ehbrs_ruby_utils/template/ehbrs_ruby_utils/music/lyrics_book/song/inner.html.erb +5 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider.rb +4 -0
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/provider_search.rb +1 -1
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/providers_data.xml +2 -1
- data/vendor/ultimate_lyrics/lib/ultimate_lyrics/version.rb +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__michael_jackson_thriller.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/encyclopaedia_metallum__milton_nascimento_rouxinol.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__michael_jackson_thriller.source.html +18 -18
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__michael_jackson_thriller.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__milton_nascimento_rouxinol.source.html +18 -18
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/hindilyrics_net_bollywood_songs__milton_nascimento_rouxinol.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyrics_com__milton_nascimento_rouxinol.target.yaml +1 -3
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__michael_jackson_thriller.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsplugin_com__milton_nascimento_rouxinol.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsreg_com__milton_nascimento_rouxinol.source.html +3 -3
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/lyricsreg_com__milton_nascimento_rouxinol.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__michael_jackson_thriller.source.html +3 -3
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__michael_jackson_thriller.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__milton_nascimento_rouxinol.source.html +3 -3
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/mp3lyrics_org__milton_nascimento_rouxinol.target.yaml +1 -1
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/songlyrics_com__michael_jackson_thriller.source.html +15 -12
- data/vendor/ultimate_lyrics/spec/lib/ultimate_lyrics/parser_spec_files/songlyrics_com__michael_jackson_thriller.target.yaml +1 -1
- metadata +92 -7
- data/lib/ehbrs/patches/module/erb_template.rb +0 -11
- data/lib/ehbrs/patches/object/erb_template.rb +0 -9
- data/vendor/eac_ruby_utils/lib/eac_ruby_utils/fs_cache.rb +0 -12
@@ -0,0 +1,108 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/file'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
class Directory
|
7
|
+
TEMPLATE_EXTNAME = '.template'
|
8
|
+
|
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
|
+
TemplateNode.new(self, '.', directory, variables_source).apply
|
17
|
+
end
|
18
|
+
|
19
|
+
def child(subpath)
|
20
|
+
child_path = ::File.join(path, subpath)
|
21
|
+
return ::EacTemplates::File.new(child_path) if ::File.file?(child_path)
|
22
|
+
return ::EacTemplates::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
|
+
|
46
|
+
class TemplateNode
|
47
|
+
attr_reader :source_directory, :source_relative, :target_root_directory, :variables_source
|
48
|
+
|
49
|
+
def initialize(source_directory, source_relative, target_root_directory, variables_source)
|
50
|
+
@source_directory = source_directory
|
51
|
+
@source_relative = source_relative
|
52
|
+
@target_root_directory = target_root_directory
|
53
|
+
@variables_source = variables_source
|
54
|
+
end
|
55
|
+
|
56
|
+
def apply
|
57
|
+
if file?
|
58
|
+
apply_file
|
59
|
+
elsif directory?
|
60
|
+
apply_directory
|
61
|
+
else
|
62
|
+
raise "Unknown filesystem type: #{source_absolute}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def apply_directory
|
69
|
+
::FileUtils.mkdir_p(target_absolute)
|
70
|
+
Dir.entries(source_absolute).each do |entry|
|
71
|
+
child(entry).apply unless %w[. ..].include?(entry)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def apply_file
|
76
|
+
if ::File.extname(source_absolute) == TEMPLATE_EXTNAME
|
77
|
+
::EacTemplates::File.new(source_absolute).apply_to_file(
|
78
|
+
variables_source, target_absolute
|
79
|
+
)
|
80
|
+
else
|
81
|
+
::FileUtils.cp(source_absolute, target_absolute)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def child(entry)
|
86
|
+
TemplateNode.new(source_directory, ::File.join(source_relative, entry),
|
87
|
+
target_root_directory, variables_source)
|
88
|
+
end
|
89
|
+
|
90
|
+
def file?
|
91
|
+
::File.file?(source_absolute)
|
92
|
+
end
|
93
|
+
|
94
|
+
def directory?
|
95
|
+
::File.directory?(source_absolute)
|
96
|
+
end
|
97
|
+
|
98
|
+
def source_absolute
|
99
|
+
::File.expand_path(source_relative, source_directory.path)
|
100
|
+
end
|
101
|
+
|
102
|
+
def target_absolute
|
103
|
+
::File.expand_path(source_relative, target_root_directory)
|
104
|
+
.gsub(/#{::Regexp.quote(TEMPLATE_EXTNAME)}\z/, '')
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
require 'eac_templates/variable_providers'
|
5
|
+
|
6
|
+
module EacTemplates
|
7
|
+
class File
|
8
|
+
VARIABLE_DELIMITER = ::Regexp.quote('%%')
|
9
|
+
VARIABLE_PATTERN = /#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze
|
10
|
+
|
11
|
+
enable_simple_cache
|
12
|
+
common_constructor :path do
|
13
|
+
self.path = path.to_pathname
|
14
|
+
end
|
15
|
+
|
16
|
+
# +variables_provider+ A [Hash] or object which responds to +read_entry(entry_name)+.
|
17
|
+
def apply(variables_source)
|
18
|
+
variables_provider = ::EacTemplates::VariableProviders.build(variables_source)
|
19
|
+
variables.inject(content) do |a, e|
|
20
|
+
a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def apply_to_file(variables_source, output_file_path)
|
25
|
+
output_file_path.to_pathname.write(apply(variables_source))
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def variables_uncached
|
31
|
+
content.scan(VARIABLE_PATTERN).map(&:first).map do |name|
|
32
|
+
sanitize_variable_name(name)
|
33
|
+
end.to_set
|
34
|
+
end
|
35
|
+
|
36
|
+
def content_uncached
|
37
|
+
path.read
|
38
|
+
end
|
39
|
+
|
40
|
+
def sanitize_variable_name(variable_name)
|
41
|
+
variable_name.to_s.downcase
|
42
|
+
end
|
43
|
+
|
44
|
+
def variable_pattern(name)
|
45
|
+
/#{VARIABLE_DELIMITER}#{::Regexp.quote(name)}#{VARIABLE_DELIMITER}/i
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/core_ext/object/blank'
|
4
|
+
require 'eac_templates/directory'
|
5
|
+
require 'eac_templates/file'
|
6
|
+
|
7
|
+
module EacTemplates
|
8
|
+
class Searcher
|
9
|
+
class << self
|
10
|
+
def default
|
11
|
+
@default ||= new
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def template(subpath, required = true)
|
16
|
+
path = template_path(subpath)
|
17
|
+
if path.blank?
|
18
|
+
return nil unless required
|
19
|
+
|
20
|
+
raise_template_not_found(subpath)
|
21
|
+
end
|
22
|
+
return ::EacTemplates::File.new(path) if ::File.file?(path)
|
23
|
+
return ::EacTemplates::Directory.new(path) if ::File.directory?(path)
|
24
|
+
|
25
|
+
raise 'Invalid branching'
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return The absolute path of template if found, +nil+ otherwise.
|
29
|
+
def template_path(subpath)
|
30
|
+
included_paths.each do |included_path|
|
31
|
+
r = search_template_in_included_path(included_path, subpath)
|
32
|
+
return r if r
|
33
|
+
end
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def included_paths
|
38
|
+
@included_paths ||= ::Set.new
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def raise_template_not_found(subpath)
|
44
|
+
raise "Template not found for subpath \"#{subpath}\"" \
|
45
|
+
" (Included paths: #{included_paths.to_a.join(::File::PATH_SEPARATOR)})"
|
46
|
+
end
|
47
|
+
|
48
|
+
def search_template_in_included_path(included_path, subpath)
|
49
|
+
path = ::File.join(included_path, subpath)
|
50
|
+
::File.exist?(path) ? path : nil
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/variable_not_found_error'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
module VariableProviders
|
7
|
+
class Base
|
8
|
+
attr_reader :source
|
9
|
+
|
10
|
+
def initialize(source)
|
11
|
+
@source = source
|
12
|
+
end
|
13
|
+
|
14
|
+
def variable_value(name)
|
15
|
+
return variable_fetch(name) if variable_exist?(name)
|
16
|
+
|
17
|
+
raise VariableNotFoundError, "Variable \"#{name}\" not found in #{source}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/node'
|
4
|
+
require 'eac_templates/variable_providers/base'
|
5
|
+
|
6
|
+
module EacTemplates
|
7
|
+
module VariableProviders
|
8
|
+
class ConfigReader < ::EacTemplates::VariableProviders::Base
|
9
|
+
class << self
|
10
|
+
def accept?(variables_source)
|
11
|
+
return false unless variables_source.respond_to?(:entry)
|
12
|
+
|
13
|
+
entry = variables_source.entry(:any_value)
|
14
|
+
entry.respond_to?(:value) && entry.respond_to?(:found?)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def variable_exist?(name)
|
19
|
+
source.entry(name).found?
|
20
|
+
end
|
21
|
+
|
22
|
+
def variable_fetch(name)
|
23
|
+
source.entry(name).value
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/variable_providers/base'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
module VariableProviders
|
7
|
+
class EntriesReader < ::EacTemplates::VariableProviders::Base
|
8
|
+
class << self
|
9
|
+
def accept?(variables_source)
|
10
|
+
variables_source.respond_to?(:read_entry)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def variable_exist?(_name)
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def variable_fetch(name)
|
19
|
+
source.read_entry(name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/variable_providers/base'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
module VariableProviders
|
7
|
+
class Generic < ::EacTemplates::VariableProviders::Base
|
8
|
+
class << self
|
9
|
+
def accept?(variables_source)
|
10
|
+
variables_source.is_a?(::Object)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def variable_exist?(name)
|
15
|
+
source.respond_to?(name)
|
16
|
+
end
|
17
|
+
|
18
|
+
def variable_fetch(name)
|
19
|
+
source.send(name)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/variable_providers/base'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
module VariableProviders
|
7
|
+
class Hash < ::EacTemplates::VariableProviders::Base
|
8
|
+
class << self
|
9
|
+
def accept?(variables_source)
|
10
|
+
variables_source.is_a?(::Hash)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(source)
|
15
|
+
super(source.with_indifferent_access)
|
16
|
+
end
|
17
|
+
|
18
|
+
def variable_exist?(name)
|
19
|
+
source.key?(name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def variable_fetch(name)
|
23
|
+
source.fetch(name)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
5
|
+
module EacTemplates
|
6
|
+
module VariableProviders
|
7
|
+
require_sub __FILE__
|
8
|
+
|
9
|
+
PROVIDERS = %w[config_reader entries_reader hash generic].map do |name|
|
10
|
+
"eac_templates/variable_providers/#{name}".camelize.constantize
|
11
|
+
end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def build(variables_source)
|
15
|
+
PROVIDERS.each do |provider|
|
16
|
+
return provider.new(variables_source) if provider.accept?(variables_source)
|
17
|
+
end
|
18
|
+
|
19
|
+
raise "Variables provider not found for #{variables_source}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_config/old_configs'
|
4
|
+
require 'eac_templates/file'
|
5
|
+
|
6
|
+
RSpec.describe ::EacTemplates::File do
|
7
|
+
let(:files_dir) { ::File.join(__dir__, 'file_spec_files') }
|
8
|
+
let(:source_path) { ::File.join(files_dir, 'source.template') }
|
9
|
+
let(:instance) { described_class.new(source_path) }
|
10
|
+
let(:expected_content) { ::File.read(::File.join(files_dir, 'expected_content')) }
|
11
|
+
|
12
|
+
describe '#apply' do
|
13
|
+
context 'when config is a hash' do
|
14
|
+
let(:config) { { name: 'Fulano de Tal', age: 33 } }
|
15
|
+
|
16
|
+
it { expect(instance.apply(config)).to eq(expected_content) }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'when config responds to read_entry' do
|
20
|
+
let(:config) { ::EacConfig::OldConfigs.new('rspec_describe_eac_ruby_utils_templates_file') }
|
21
|
+
|
22
|
+
before do
|
23
|
+
config.clear
|
24
|
+
config['name'] = 'Fulano de Tal'
|
25
|
+
config['age'] = '33'
|
26
|
+
end
|
27
|
+
|
28
|
+
it { expect(instance.apply(config)).to eq(expected_content) }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#variables' do
|
33
|
+
it { expect(instance.variables).to eq(::Set.new(%w[name age])) }
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/searcher'
|
4
|
+
|
5
|
+
RSpec.describe ::EacTemplates::Searcher do
|
6
|
+
let(:files_dir) { ::File.join(__dir__, 'searcher_spec_files') }
|
7
|
+
let(:instance) do
|
8
|
+
r = described_class.new
|
9
|
+
r.included_paths << ::File.join(files_dir, 'path1')
|
10
|
+
r.included_paths << ::File.join(files_dir, 'path2')
|
11
|
+
r
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#template' do
|
15
|
+
{
|
16
|
+
::EacTemplates::Directory => %w[subdir1],
|
17
|
+
::EacTemplates::File => %w[subdir1/file1.template subdir1/file2
|
18
|
+
subdir1/file3.template],
|
19
|
+
::NilClass => %w[does_not_exist]
|
20
|
+
}.each do |klass, subpaths|
|
21
|
+
subpaths.each do |subpath|
|
22
|
+
context "when subpath is \"#{subpath}\"" do
|
23
|
+
it "returns a #{klass}'s instance" do
|
24
|
+
expect(instance.template(subpath, false)).to be_a(klass)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path1/subdir1/file1.template
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/vendor/eac_templates/spec/lib/eac_templates/searcher_spec_files/path2/subdir1/file3.template
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_templates/patches/object/template'
|
4
|
+
|
5
|
+
RSpec.describe ::Object do
|
6
|
+
class MyStubWithTemplate # rubocop:disable RSpec/LeakyConstantDeclaration
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:instance) { ::MyStubWithTemplate.new }
|
10
|
+
let(:templates_path) { ::File.join(__dir__, 'template_spec_files', 'path') }
|
11
|
+
|
12
|
+
before do
|
13
|
+
::EacTemplates::Searcher.default.included_paths.add(templates_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
::EacTemplates::Searcher.default.included_paths.delete(templates_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#template' do
|
21
|
+
it { expect(instance.template).to be_a(::EacTemplates::File) }
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -7,7 +7,7 @@ module EhbrsRubyUtils
|
|
7
7
|
module Fs
|
8
8
|
class Selected
|
9
9
|
class Build
|
10
|
-
DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |
|
10
|
+
DEFAULT_TARGET_BASENAME_PROC = ::Proc.new { |path| path.basename.to_path }
|
11
11
|
|
12
12
|
attr_reader :selected, :target_dir, :target_basename_proc
|
13
13
|
|
@@ -16,8 +16,8 @@ module EhbrsRubyUtils
|
|
16
16
|
self.options = self.class.lists.option.hash_keys_validate!(options)
|
17
17
|
end
|
18
18
|
|
19
|
-
def build(target_dir)
|
20
|
-
::EhbrsRubyUtils::Fs::Selected::Build.new(self, target_dir)
|
19
|
+
def build(target_dir, &directory_target_basename)
|
20
|
+
::EhbrsRubyUtils::Fs::Selected::Build.new(self, target_dir, &directory_target_basename)
|
21
21
|
end
|
22
22
|
|
23
23
|
def filename
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'ehbrs_ruby_utils/core_ext'
|
4
|
+
require 'ehbrs_ruby_utils/music/lyrics_book/resource'
|
5
|
+
|
6
|
+
module EhbrsRubyUtils
|
7
|
+
module Music
|
8
|
+
class LyricsBook
|
9
|
+
class Album < ::EhbrsRubyUtils::Music::LyricsBook::Resource
|
10
|
+
enable_simple_cache
|
11
|
+
|
12
|
+
def book
|
13
|
+
parent
|
14
|
+
end
|
15
|
+
|
16
|
+
def first_previous
|
17
|
+
previous.if_present { |v| v.songs.last }
|
18
|
+
end
|
19
|
+
|
20
|
+
def valid?
|
21
|
+
songs.any?
|
22
|
+
end
|
23
|
+
|
24
|
+
def header_title
|
25
|
+
"#{songs.first.number}-#{songs.last.number} | #{artist} | #{title}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def artist
|
29
|
+
songs.lazy.map { |v| v.tag.artist }.find(&:present?)
|
30
|
+
end
|
31
|
+
|
32
|
+
def title
|
33
|
+
songs.lazy.map { |v| v.tag.album }.find(&:present?)
|
34
|
+
end
|
35
|
+
|
36
|
+
def songs_uncached
|
37
|
+
::EhbrsRubyUtils::Music::LyricsBook::Song.create_list(self, path.children)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|