ehbrs-tools 0.26.0 → 0.28.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +51 -31
- data/lib/ehbrs/tools/runner/fs/selected.rb +18 -25
- 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/lib/ehbrs/videos/extract/package.rb +2 -2
- data/lib/ehbrs/videos/extract/package_file.rb +0 -1
- data/spec/lib/ehbrs/tools/runner/fs/used_space_spec.rb +2 -1
- data/vendor/eac_cli/lib/eac_cli/config.rb +6 -3
- data/vendor/eac_cli/lib/eac_cli/definition/argument_option.rb +1 -1
- data/vendor/eac_cli/lib/eac_cli/definition/base_option.rb +9 -1
- data/vendor/eac_cli/lib/eac_cli/definition/boolean_option.rb +6 -0
- data/vendor/eac_cli/lib/eac_cli/runner_with/help/builder.rb +3 -3
- data/vendor/eac_cli/lib/eac_cli/version.rb +1 -1
- data/vendor/eac_cli/spec/lib/eac_cli/runner_spec.rb +6 -5
- 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/cached_download.rb +39 -0
- data/vendor/eac_fs/lib/eac_fs/file_info.rb +29 -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 +15 -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 +4 -4
- 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/ehbrs_ruby_utils.gemspec +2 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/core_ext.rb +5 -0
- data/{lib/ehbrs → vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils}/fs/compressed_package.rb +3 -3
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected/build.rb +41 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected/build_file.rb +27 -0
- data/vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils/fs/selected.rb +35 -0
- data/{lib/ehbrs → vendor/ehbrs_ruby_utils/lib/ehbrs_ruby_utils}/fs.rb +2 -1
- 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 +15 -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 +9 -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
- data/vendor/ultimate_lyrics/ultimate_lyrics.gemspec +4 -2
- metadata +98 -9
- 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,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_gems_utils/tests/minitest'
|
4
|
+
require 'eac_ruby_gems_utils/tests/rspec'
|
5
|
+
require 'eac_ruby_utils/core_ext'
|
6
|
+
|
7
|
+
module EacRubyGemsUtils
|
8
|
+
module Tests
|
9
|
+
class Multiple
|
10
|
+
require_sub __FILE__
|
11
|
+
enable_speaker
|
12
|
+
enable_simple_cache
|
13
|
+
common_constructor :gems, :options, default: [{}]
|
14
|
+
set_callback :initialize, :after, :run
|
15
|
+
|
16
|
+
def ok?
|
17
|
+
failed_tests.none?
|
18
|
+
end
|
19
|
+
|
20
|
+
def only
|
21
|
+
options[:only]
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def all_tests_uncached
|
27
|
+
decorated_gems.flat_map(&:tests)
|
28
|
+
end
|
29
|
+
|
30
|
+
def clear_logs
|
31
|
+
all_tests.each do |test|
|
32
|
+
test.logs.remove_all
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def prepare_all_gems
|
37
|
+
infom 'Preparing all gems...'
|
38
|
+
decorated_gems.each(&:prepare)
|
39
|
+
end
|
40
|
+
|
41
|
+
def decorated_gems_uncached
|
42
|
+
r = gems
|
43
|
+
r = r.select { |gem| only.include?(gem.name) } if only.present?
|
44
|
+
r.map { |gem| DecoratedGem.new(gem) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def failed_tests_uncached
|
48
|
+
all_tests.select { |r| r.result == ::EacRubyGemsUtils::Tests::Base::RESULT_FAILED }
|
49
|
+
end
|
50
|
+
|
51
|
+
def final_results_banner
|
52
|
+
if failed_tests.any?
|
53
|
+
warn 'Some test did not pass:'
|
54
|
+
failed_tests.each do |test|
|
55
|
+
infov ' * Test', test
|
56
|
+
info test.logs.truncate_all
|
57
|
+
end
|
58
|
+
else
|
59
|
+
success 'All tests passed'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def run
|
64
|
+
start_banner
|
65
|
+
prepare_all_gems
|
66
|
+
test_all_gems
|
67
|
+
final_results_banner
|
68
|
+
ensure
|
69
|
+
clear_logs
|
70
|
+
end
|
71
|
+
|
72
|
+
def start_banner
|
73
|
+
infov 'Gems to test', decorated_gems.count
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_all_gems
|
77
|
+
infom 'Running tests...'
|
78
|
+
all_tests.each do |test|
|
79
|
+
infov test, Result.new(test.result).tag
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_gems_utils/tests/base'
|
4
|
+
|
5
|
+
module EacRubyGemsUtils
|
6
|
+
module Tests
|
7
|
+
class Rspec < ::EacRubyGemsUtils::Tests::Base
|
8
|
+
def bundle_exec_args
|
9
|
+
%w[rspec]
|
10
|
+
end
|
11
|
+
|
12
|
+
def dependency_gem
|
13
|
+
'rspec-core'
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_directory
|
17
|
+
'spec'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_gems_utils/gem'
|
4
|
+
|
5
|
+
::RSpec.describe ::EacRubyGemsUtils::Gem::VersionFile do
|
6
|
+
let(:stubs_dir) { ::Pathname.new(__dir__).join('version_file_spec_files') }
|
7
|
+
let(:stub_file) { stubs_dir.join('a_version_file.rb') }
|
8
|
+
let(:instance) { described_class.new(stub_file) }
|
9
|
+
let(:target_version) { ::Gem::Version.new('0.69.1') }
|
10
|
+
|
11
|
+
describe '#value' do
|
12
|
+
it { expect(instance.value).to eq(target_version) }
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'eac_ruby_gems_utils/gem'
|
4
|
+
|
5
|
+
::RSpec.describe ::EacRubyGemsUtils::Gem do
|
6
|
+
let(:mygem_path) { ::Pathname.new(__dir__).expand_path.parent.parent.join('support', 'mygem') }
|
7
|
+
let(:mygem) { described_class.new(mygem_path) }
|
8
|
+
|
9
|
+
describe '#bundle' do
|
10
|
+
specify do
|
11
|
+
expect(mygem.bundle('exec', 'myrunner').execute!).to include('My Runner')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#rake' do
|
16
|
+
specify do
|
17
|
+
expect(mygem.rake('mygem:stub').execute!).to include('Stub!')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'bundler/setup'
|
5
|
+
rescue LoadError
|
6
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
namespace :mygem do
|
10
|
+
desc 'A stub task.'
|
11
|
+
task :stub do
|
12
|
+
puts 'Stub!'
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('lib', __dir__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'mygem'
|
7
|
+
s.version = '1.0.0'
|
8
|
+
s.authors = ['Esquilo Azul Company']
|
9
|
+
s.summary = 'Stub gem.'
|
10
|
+
|
11
|
+
s.files = Dir['{exe,lib}/**/*', 'Gemfile', 'Rakefile']
|
12
|
+
s.bindir = 'exe'
|
13
|
+
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
14
|
+
|
15
|
+
s.add_dependency 'rake'
|
16
|
+
end
|
@@ -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.5'
|
16
|
+
s.add_dependency 'eac_ruby_utils', '~> 0.64'
|
17
|
+
|
18
|
+
s.add_development_dependency 'eac_ruby_gem_support', '~> 0.2'
|
19
|
+
end
|
@@ -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
|