xembly 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 6f023a77c3eafd5c14209b1ecdfe52a0beb9d467
4
- data.tar.gz: dd79f3a64463a63e27e70a0ff6e0ab59d8702609
2
+ SHA256:
3
+ metadata.gz: fc7bc216b94a2958fd5e606eeb05998280317b19294bb243914da4ff0bc88f54
4
+ data.tar.gz: 7cabfc0600484c9f201b9c188b0b740f36040bfb64c2e0f71a0f5d99f9161882
5
5
  SHA512:
6
- metadata.gz: 0b07c1a59c84b1a68db7b983baf62a2e0df51fc557725b4e7aceec123b1de2658062bc79e76e5bc3271d0f257239c9e04820dfd2c7a74e510ad6310ca1ff21fa
7
- data.tar.gz: 6579da7b021d569cb5e110675763fbd8980cb36f2980f49e86d42e47d404a4232723a79cfa4bb6fa97f127eb410e027bb122199ade26e360fcf2084b1174fcb4
6
+ metadata.gz: f37de6ab8d6093803de32605df1b014ffb7f181ef6a83f8cea9d2f7204bc9036764d9f457aa99eb84eb443c1e3061469d7455c3b5ccd23e6e1719e43d1ec2015
7
+ data.tar.gz: 3f24551da450d598e87a1fba24b6341582ecc409733687e1f3e22e6af26554bf3f3a20873bcd509d3bd37d318d2fbb4d1f8a3d186a4e46babced6bea42780d71
data/.0pdd.yml ADDED
@@ -0,0 +1,9 @@
1
+ errors:
2
+ - yegor256@gmail.com
3
+ # alerts:
4
+ # github:
5
+ # - yegor256
6
+
7
+ tags:
8
+ - pdd
9
+ - bug
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: codecov
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ jobs:
8
+ codecov:
9
+ runs-on: ubuntu-22.04
10
+ steps:
11
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
12
+ - uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 3.3
15
+ - run: bundle update
16
+ - run: bundle exec rake
17
+ - uses: codecov/codecov-action@v4.0.0-beta.3
18
+ with:
19
+ token: ${{ secrets.CODECOV_TOKEN }}
20
+ file: coverage/.resultset.json
21
+ fail_ci_if_error: true
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: pdd
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ pdd:
12
+ runs-on: ubuntu-22.04
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ - uses: volodya-lombrozo/pdd-action@master
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: rake
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+ pull_request:
8
+ branches:
9
+ - master
10
+ jobs:
11
+ rake:
12
+ name: test
13
+ strategy:
14
+ matrix:
15
+ os: [ubuntu-22.04, macos-12]
16
+ ruby: [3.3]
17
+ runs-on: ${{ matrix.os }}
18
+ steps:
19
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
20
+ - uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - run: bundle update
24
+ - run: bundle exec rake
@@ -0,0 +1,11 @@
1
+ ---
2
+ name: xcop
3
+ on:
4
+ push:
5
+ pull_request:
6
+ jobs:
7
+ xcop:
8
+ runs-on: ubuntu-22.04
9
+ steps:
10
+ - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
11
+ - uses: g4s8/xcop-action@master
data/.pdd ADDED
@@ -0,0 +1,7 @@
1
+ --source=.
2
+ --verbose
3
+ --exclude target/**/*
4
+ --exclude src/main/resources/images/**/*
5
+ --rule min-words:20
6
+ --rule min-estimate:15
7
+ --rule max-estimate:90
data/.rubocop.yml CHANGED
@@ -1,6 +1,18 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Exclude:
4
+ - 'assets/**/*'
5
+ DisplayCopNames: true
6
+ TargetRubyVersion: '2.5'
7
+ SuggestExtensions: false
8
+
1
9
  MethodLength:
2
10
  Max: 50
3
11
  Style/ClassLength:
4
12
  Max: 150
5
13
  Style/CyclomaticComplexity:
6
14
  Max: 20
15
+ Metrics/BlockLength:
16
+ Max: 30
17
+ Metrics/AbcSize:
18
+ Max: 30
data/.rultor.yml CHANGED
@@ -1,28 +1,20 @@
1
+ docker:
2
+ image: yegor256/rultor-image:1.22.0
1
3
  assets:
2
4
  rubygems.yml: yegor256/home#assets/rubygems.yml
3
- s3cfg: yegor256/home#assets/s3cfg
4
5
  install: |
5
- sudo apt-get update
6
- sudo gem install pdd
6
+ pdd -f /dev/null
7
+ bundle install --no-color
7
8
  release:
9
+ pre: false
8
10
  script: |-
9
- sudo bundle install
10
- rake
11
- rm -rf *.gem
11
+ bundle exec rake clean test rubocop copyright
12
12
  sed -i "s/1\.0\.snapshot/${tag}/g" lib/xembly/version.rb
13
13
  git add lib/xembly/version.rb
14
14
  git commit -m "version set to ${tag}"
15
15
  gem build xembly.gemspec
16
16
  chmod 0600 ../rubygems.yml
17
17
  gem push *.gem --config-file ../rubygems.yml
18
- sudo gem install xembly
19
- pdd --source=$(pwd) --verbose --file=xembly-gem.xml -e=test/** -e=features/** -e=README.md
20
- s3cmd --no-progress put xembly-gem.xml --config=../s3cfg s3://pdd.teamed.io/xembly-gem.xml
21
- commanders:
22
- - yegor256
23
- architect:
24
- - yegor256
25
- - davvd
26
18
  merge:
27
- commanders: []
28
- deploy: {}
19
+ script: |-
20
+ bundle exec rake clean test rubocop copyright
data/.simplecov CHANGED
@@ -1,6 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
- # Copyright (c) 2016 Yegor Bugayenko
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
4
5
  #
5
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -20,24 +21,21 @@
20
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
22
  # SOFTWARE.
22
23
 
23
- require 'coveralls'
24
-
25
- if Gem.win_platform? then
24
+ if Gem.win_platform?
26
25
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
27
26
  SimpleCov::Formatter::HTMLFormatter
28
27
  ]
29
28
  SimpleCov.start do
30
- add_filter "/test/"
31
- add_filter "/features/"
29
+ add_filter '/test/'
30
+ add_filter '/features/'
32
31
  end
33
32
  else
34
33
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new [
35
- SimpleCov::Formatter::HTMLFormatter,
36
- Coveralls::SimpleCov::Formatter
34
+ SimpleCov::Formatter::HTMLFormatter
37
35
  ]
38
36
  SimpleCov.start do
39
- add_filter "/test/"
40
- add_filter "/features/"
37
+ add_filter '/test/'
38
+ add_filter '/features/'
41
39
  minimum_coverage 90
42
40
  end
43
41
  end
data/Gemfile CHANGED
@@ -1,6 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
- # Copyright (c) 2016 Yegor Bugayenko
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
4
5
  #
5
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -22,3 +23,10 @@
22
23
 
23
24
  source 'https://rubygems.org'
24
25
  gemspec
26
+ gem 'cucumber', '9.1.2', require: false
27
+ gem 'minitest', '5.22.2', require: false
28
+ gem 'rdoc', '6.6.2', require: false
29
+ gem 'rspec-rails', '6.1.1', require: false
30
+ gem 'rubocop', '1.60.2', require: false
31
+ gem 'rubocop-rspec', '2.26.1', require: false
32
+ gem 'simplecov', '0.22.0', require: false
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2016 Yegor Bugayenko
3
+ Copyright (c) 2016-2024 Yegor Bugayenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the 'Software'), to deal
data/README.md CHANGED
@@ -1,37 +1,30 @@
1
- [![Made By Teamed.io](http://img.teamed.io/btn.svg)](http://www.teamed.io)
1
+ <img src="https://www.xembly.org/logo.png" width="64px" height="64px" />
2
+
2
3
  [![DevOps By Rultor.com](http://www.rultor.com/b/yegor256/xembly-gem)](http://www.rultor.com/p/yegor256/xembly-gem)
3
- [![We recommend RubyMine](http://img.teamed.io/rubymine-recommend.svg)](https://www.jetbrains.com/ruby/)
4
+ [![We recommend RubyMine](https://www.elegantobjects.org/rubymine.svg)](https://www.jetbrains.com/ruby/)
4
5
 
5
- [![Build Status](https://travis-ci.org/yegor256/xembly-gem.svg)](https://travis-ci.org/yegor256/xembly-gem)
6
- [![Build status](https://ci.appveyor.com/api/projects/status/8e5dsjjemymfg510?svg=true)](https://ci.appveyor.com/project/yegor256/xembly-gem)
7
6
  [![Gem Version](https://badge.fury.io/rb/xembly.svg)](http://badge.fury.io/rb/xembly)
8
- [![Dependency Status](https://gemnasium.com/yegor256/xembly-gem.svg)](https://gemnasium.com/yegor256/xembly-gem)
9
- [![Code Climate](http://img.shields.io/codeclimate/github/yegor256/xembly-gem.svg)](https://codeclimate.com/github/yegor256/xembly-gem)
10
- [![Coverage Status](https://img.shields.io/coveralls/yegor256/xembly-gem.svg)](https://coveralls.io/r/yegor256/xembly-gem)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/f26349e81b04628d8bf7/maintainability)](https://codeclimate.com/github/yegor256/xembly-gem/maintainability)
8
+ [![Test Coverage](https://img.shields.io/codecov/c/github/yegor256/xembly-gem.svg)](https://codecov.io/github/yegor256/xembly-gem?branch=master)
11
9
 
12
- ## Assembly for XML
10
+ Xembly is assembly for XML.
13
11
 
14
12
  Read this [blog post](http://www.yegor256.com/2014/04/09/xembly-intro.html)
15
13
  and check this project: [yegor256/xembly](https://github.com/yegor256/xembly)
16
14
 
17
- ## How to Install?
18
-
19
- You will need Ruby 2.0+:
15
+ To install, you will need Ruby 2.0+:
20
16
 
21
17
  ```bash
22
18
  $ gem install xembly
23
19
  ```
24
20
 
25
- ## How to Run?
26
-
27
- Run it locally and read its output:
21
+ Then, run it and read its output:
28
22
 
29
23
  ```bash
30
24
  $ xembly --help
31
25
  ```
32
26
 
33
- Say, you want to modify an existing XML document, which is
34
- in file `doc.xml`:
27
+ Say, you want to modify an existing XML document, which is in the file `doc.xml`:
35
28
 
36
29
  ```xml
37
30
  <books>
@@ -53,5 +46,5 @@ $ xembly --xml doc.xml 'XPATH "/books"; ADD "book"; ATTR "isbn", "0201379430"; S
53
46
 
54
47
  Simple as that!
55
48
 
56
- Full specification of Xembly language is
49
+ The full specification of Xembly language is
57
50
  [here](https://github.com/yegor256/xembly).
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
- # Copyright (c) 2016 Yegor Bugayenko
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
4
5
  #
5
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -33,7 +34,7 @@ def version
33
34
  Gem::Specification.load(Dir['*.gemspec'].first).version
34
35
  end
35
36
 
36
- task default: [:clean, :test, :features, :rubocop, :copyright]
37
+ task default: %i[clean test features rubocop copyright]
37
38
 
38
39
  require 'rake/testtask'
39
40
  desc 'Run all unit tests'
@@ -65,12 +66,12 @@ Cucumber::Rake::Task.new(:features) do |t|
65
66
  Rake::Cleaner.cleanup_files(['coverage'])
66
67
  t.profile = 'travis'
67
68
  end
68
- Cucumber::Rake::Task.new(:"features:html") do |t|
69
+ Cucumber::Rake::Task.new(:'features:html') do |t|
69
70
  t.profile = 'html_report'
70
71
  end
71
72
 
72
73
  task :copyright do
73
- sh "grep -q -r '#{Date.today.strftime('%Y')}' \
74
+ sh "grep -q -r '2016-#{Date.today.strftime('%Y')}' \
74
75
  --include '*.rb' \
75
76
  --include '*.txt' \
76
77
  --include 'Rakefile' \
data/bin/xembly CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
3
4
  #
4
- # Copyright (c) 2016 Yegor Bugayenko
5
+ # Copyright (c) 2016-2024 Yegor Bugayenko
5
6
  #
6
7
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
8
  # of this software and associated documentation files (the 'Software'), to deal
@@ -21,11 +22,11 @@
21
22
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
23
  # SOFTWARE.
23
24
 
24
- STDOUT.sync = true
25
+ $stdout.sync = true
25
26
 
26
- require 'xembly'
27
- require 'xembly/version'
28
27
  require 'slop'
28
+ require_relative '../lib/xembly'
29
+ require_relative '../lib/xembly/version'
29
30
 
30
31
  opts = Slop.parse(ARGV, strict: true, help: true) do |o|
31
32
  o.banner = "Usage (#{Xembly::VERSION}): xembly [options] [directives]"
@@ -58,10 +59,10 @@ opts = Slop.parse(ARGV, strict: true, help: true) do |o|
58
59
  )
59
60
  end
60
61
 
61
- fail '-f is mandatory when using -v' if opts.verbose? && !opts.file?
62
+ raise '-f is mandatory when using -v' if opts.verbose? && !opts.file?
62
63
 
63
64
  Encoding.default_external = Encoding::UTF_8
64
65
  Encoding.default_internal = Encoding::UTF_8
65
66
  output = Xembly::Base.new(opts).xml
66
- file = opts.file? ? File.new(opts[:file], 'w') : STDOUT
67
+ file = opts.file? ? File.new(opts[:file], 'w') : $stdout
67
68
  file << output
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
- # Copyright (c) 2016 TechnoPark Corp.
4
- # Copyright (c) 2016 Yegor Bugayenko
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -21,66 +21,61 @@
21
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
22
  # SOFTWARE.
23
23
 
24
- require 'xembly'
25
24
  require 'nokogiri'
26
25
  require 'tmpdir'
27
26
  require 'slop'
28
27
  require 'English'
28
+ require_relative '../../lib/xembly'
29
29
 
30
30
  Before do
31
31
  @cwd = Dir.pwd
32
32
  @dir = Dir.mktmpdir('test')
33
- FileUtils.mkdir_p(@dir) unless File.exist?(@dir)
33
+ FileUtils.mkdir_p(@dir)
34
34
  Dir.chdir(@dir)
35
35
  end
36
36
 
37
37
  After do
38
38
  Dir.chdir(@cwd)
39
- FileUtils.rm_rf(@dir) if File.exist?(@dir)
39
+ FileUtils.rm_rf(@dir)
40
40
  end
41
41
 
42
42
  Given(/^I have a "([^"]*)" file with content:$/) do |file, text|
43
43
  FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(file)
44
- File.open(file, 'w') do |f|
45
- f.write(text.gsub(/\\xFF/, "\xFF"))
46
- end
44
+ File.write(file, text.gsub('\\xFF', 0xff.chr))
47
45
  end
48
46
 
49
47
  Then(/^XML matches "([^"]+)"$/) do |xpath|
50
- fail "XML doesn't match \"#{xpath}\":\n#{@xml}" if @xml.xpath(xpath).empty?
48
+ raise "XML doesn't match \"#{xpath}\":\n#{@xml}" if @xml.xpath(xpath).empty?
51
49
  end
52
50
 
53
- When(/^I run bin\/xembly with "([^"]*)"$/) do |arg|
51
+ When(%r{^I run bin/xembly with "([^"]*)"$}) do |arg|
54
52
  home = File.join(File.dirname(__FILE__), '../..')
55
53
  @stdout = `ruby -I#{home}/lib #{home}/bin/xembly #{arg}`
56
54
  @exitstatus = $CHILD_STATUS.exitstatus
57
55
  end
58
56
 
59
57
  Then(/^Stdout contains "([^"]*)"$/) do |txt|
60
- unless @stdout.include?(txt)
61
- fail "STDOUT doesn't contain '#{txt}':\n#{@stdout}"
62
- end
58
+ raise "STDOUT doesn't contain '#{txt}':\n#{@stdout}" unless @stdout.include?(txt)
63
59
  end
64
60
 
65
61
  Then(/^Stdout is empty$/) do
66
- fail "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
62
+ raise "STDOUT is not empty:\n#{@stdout}" unless @stdout == ''
67
63
  end
68
64
 
69
65
  Then(/^XML file "([^"]+)" matches "((?:[^"]|\\")+)"$/) do |file, xpath|
70
- fail "File #{file} doesn't exit" unless File.exist?(file)
66
+ raise "File #{file} doesn't exit" unless File.exist?(file)
67
+
71
68
  xml = Nokogiri::XML.parse(File.read(file))
72
69
  xml.remove_namespaces!
73
- if xml.xpath(xpath.gsub(/\\"/, '"')).empty?
74
- fail "XML file #{file} doesn't match \"#{xpath}\":\n#{xml}"
75
- end
70
+ raise "XML file #{file} doesn't match \"#{xpath}\":\n#{xml}" if xml.xpath(xpath.gsub('\\"', '"')).empty?
76
71
  end
77
72
 
78
73
  Then(/^Exit code is zero$/) do
79
- fail "Non-zero exit code #{@exitstatus}" unless @exitstatus == 0
74
+ raise "Non-zero exit code #{@exitstatus}" unless @exitstatus.zero?
80
75
  end
81
76
 
82
77
  Then(/^Exit code is not zero$/) do
83
- fail 'Zero exit code' if @exitstatus == 0
78
+ raise 'Zero exit code' if @exitstatus.zero?
84
79
  end
85
80
 
86
81
  When(/^I run bash with$/) do |text|
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
- # Copyright (c) 2016 TechnoPark Corp.
4
- # Copyright (c) 2016 Yegor Bugayenko
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
5
5
  #
6
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -22,4 +22,4 @@
22
22
  # SOFTWARE.
23
23
 
24
24
  require 'simplecov'
25
- require 'xembly'
25
+ require_relative '../../lib/xembly'
data/lib/xembly/add.rb CHANGED
@@ -1,6 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
- # Copyright (c) 2016 Yegor Bugayenko
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
4
5
  #
5
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -20,8 +21,8 @@
20
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
22
  # SOFTWARE.
22
23
 
23
- require 'xembly'
24
24
  require 'nokogiri'
25
+ require_relative '../xembly/base'
25
26
 
26
27
  module Xembly
27
28
  # ADD directive
data/lib/xembly/addif.rb CHANGED
@@ -1,6 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
- # Copyright (c) 2016 Yegor Bugayenko
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
4
5
  #
5
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -20,8 +21,8 @@
20
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
22
  # SOFTWARE.
22
23
 
23
- require 'xembly'
24
24
  require 'nokogiri'
25
+ require_relative '../xembly/base'
25
26
 
26
27
  module Xembly
27
28
  # ADDIF directive
@@ -35,7 +36,7 @@ module Xembly
35
36
  def exec(dom, cursor)
36
37
  after = []
37
38
  cursor.each do |node|
38
- if !node.element_children.any? { |e| e.name == @name }
39
+ if node.element_children.none? { |e| e.name == @name }
39
40
  child = Nokogiri::XML::Node.new(@name, dom)
40
41
  node.add_child(child)
41
42
  after.push(child)
data/lib/xembly/attr.rb CHANGED
@@ -1,6 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
+
2
3
  #
3
- # Copyright (c) 2016 Yegor Bugayenko
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
4
5
  #
5
6
  # Permission is hereby granted, free of charge, to any person obtaining a copy
6
7
  # of this software and associated documentation files (the 'Software'), to deal
@@ -20,7 +21,7 @@
20
21
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
22
  # SOFTWARE.
22
23
 
23
- require 'xembly'
24
+ require_relative '../xembly/base'
24
25
 
25
26
  module Xembly
26
27
  # ATTR directive
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ #
4
+ # Copyright (c) 2016-2024 Yegor Bugayenko
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ # of this software and associated documentation files (the 'Software'), to deal
8
+ # in the Software without restriction, including without limitation the rights
9
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ # copies of the Software, and to permit persons to whom the Software is
11
+ # furnished to do so, subject to the following conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be included in all
14
+ # copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFINGEMENT. IN NO EVENT SHALL THE
19
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ # SOFTWARE.
23
+
24
+ require 'nokogiri'
25
+ require 'logger'
26
+ require 'time'
27
+
28
+ # Xembly main module.
29
+ # Author:: Yegor Bugayenko (yegor256@gmail.com)
30
+ # Copyright:: Copyright (c) 2016-2024 Yegor Bugayenko
31
+ # License:: MIT
32
+ module Xembly
33
+ # Get logger.
34
+ def self.log
35
+ unless @logger
36
+ @logger = Logger.new($stdout)
37
+ @logger.formatter = proc { |severity, _, _, msg|
38
+ "#{severity}: #{msg.dump}\n"
39
+ }
40
+ @logger.level = Logger::ERROR
41
+ end
42
+ @logger
43
+ end
44
+
45
+ class << self
46
+ attr_writer :logger
47
+ end
48
+
49
+ # Code base abstraction
50
+ class Base
51
+ # Ctor.
52
+ # +opts+:: Options
53
+ def initialize(opts)
54
+ @opts = opts
55
+ Xembly.log.level = Logger::INFO if @opts.verbose?
56
+ Xembly.log.info "my version is #{Xembly::VERSION}"
57
+ Xembly.log.info "Ruby version is #{RUBY_VERSION} at #{RUBY_PLATFORM}"
58
+ end
59
+
60
+ # Generate XML.
61
+ def xml
62
+ if @opts.xml?
63
+ xml = File.read(@opts[:xml])
64
+ Xembly.log.info "reading #{@opts[:xml]}"
65
+ else
66
+ xml = $stdin.read
67
+ Xembly.log.info 'reading STDIN'
68
+ end
69
+ if @opts.dirs?
70
+ Xembly.log.info "reading directives from #{@opts[:dirs]}"
71
+ dirs = File.read(@opts[:dirs])
72
+ else
73
+ Xembly.log.info "#{@opts.arguments.length} directives in command line"
74
+ dirs = @opts.arguments.join
75
+ end
76
+ Xembler.new(Directives.new(dirs)).apply(xml).to_xml
77
+ end
78
+ end
79
+ end