nanoc-tidy.rb 0.6.2 → 0.8.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
2
  SHA256:
3
- metadata.gz: fc9b28f3f15fbbf7cfa46c1111b7d8c5a0b6c31f6363a7c90d74e08ce6894d8b
4
- data.tar.gz: b57bd052f6d65a3c04edf7f145ee53ec60594df0caa8cd3c4f1b8f0259fd7449
3
+ metadata.gz: 133f30c53d54b2f5cea16c3877fa597d86b5db84bb240214459eee5e6a8c4f07
4
+ data.tar.gz: 8d054b51e4f6fbd7351fac5eb78ddcae57bcf175ebfea062c588daf9d5358c56
5
5
  SHA512:
6
- metadata.gz: 26938031e1f797cbdcdc7ccada9b57c516c80c5ef9250c23dd36d4791b68e01e3f9f9262b37345f5cf76c89092c43730efd15f1546028b185e6a7d5e34ef36fd
7
- data.tar.gz: 4e64a7be6793e07884f54455a3a447793ec1eb35852ffb2e96e058f345156a902107472aeeb1b852b3d12ecf4c303c3bf54639b8fe02901dbe08e14c707f8973
6
+ metadata.gz: 95b712fefeaf461ec57efe23fbcfada16a9be99498ee923affd4db983ffa522157f95b2659a4fd726d626296a515a6cb1631ca1ae890af7caa5e8ef82949716a
7
+ data.tar.gz: d83de9881073f9a53818fec78482c7a98023acc1bc798137b78a766b96f343cec659b54e06425cda3cd78c611d32a2b606c9f15cca466859ca3b95257e9cb4ef
data/README.md CHANGED
@@ -14,8 +14,9 @@ build process.
14
14
 
15
15
  __Defaults__
16
16
 
17
- The following example uses the
18
- [default command line arguments](https://0x1eef.github.io/x/nanoc-tidy.rb/Nanoc/Tidy/Filter#default_argv-class_method):
17
+ The following example executes tidy with the default settings. <br>
18
+ See [Nanoc::Tidy.default_argv](https://0x1eef.github.io/x/nanoc-tidy.rb/Nanoc/Tidy/Filter#default_argv-class_method)
19
+ for more details:
19
20
 
20
21
  ``` ruby
21
22
  # Rules
@@ -28,9 +29,10 @@ compile "/index.html.erb" do
28
29
  end
29
30
  ```
30
31
 
31
- __Options__
32
+ __Option: argv__
32
33
 
33
- The following example forwards a command line argument:
34
+ The following example sets the "argv" filter option. <br>
35
+ The filter option is combined with [Nanoc::Tidy.default_argv](https://0x1eef.github.io/x/nanoc-tidy.rb/Nanoc/Tidy/Filter#default_argv-class_method):
34
36
 
35
37
  ```ruby
36
38
  # Rules
@@ -43,7 +45,7 @@ compile "/index.html.erb" do
43
45
  end
44
46
  ```
45
47
 
46
- ## <a id='install'>Install</a>
48
+ ## Install
47
49
 
48
50
  **Rubygems.org**
49
51
 
@@ -58,6 +60,6 @@ nanoc-tidy.rb can be installed via rubygems.org:
58
60
 
59
61
  ## License
60
62
 
61
- [BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
63
+ [BSD Zero Clause](https://choosealicense.com/licenses/0bsd/)
62
64
  <br>
63
- See [LICENSE](./LICENSE).
65
+ See [LICENSE](./LICENSE)
data/Rakefile.rb CHANGED
@@ -1,5 +1,11 @@
1
1
  require "rake/testtask"
2
2
 
3
+ desc "Run CI tasks"
4
+ task :ci do
5
+ sh "rake test"
6
+ sh "bundle exec rubocop"
7
+ end
8
+
3
9
  Rake::TestTask.new do |t|
4
10
  t.test_files = FileList['test/*_test.rb']
5
11
  t.verbose = true
@@ -4,6 +4,7 @@ module Nanoc::Tidy
4
4
  class Filter < Nanoc::Filter
5
5
  require "fileutils"
6
6
  require_relative "spawn"
7
+
7
8
  include Spawn
8
9
  include FileUtils
9
10
 
@@ -34,14 +35,15 @@ module Nanoc::Tidy
34
35
  # @return [String]
35
36
  # Returns HTML content (modified)
36
37
  def run(content, options = {})
37
- path = temporary_file(content).path
38
+ file = temporary_file(
39
+ File.basename(item.identifier.to_s),
40
+ content
41
+ )
38
42
  spawn tidy,
39
- [*default_argv, *(options[:argv] || []), "-modify", path],
40
- err: File.join(tmpdir, "stderr"),
41
- out: File.join(tmpdir, "stdout")
42
- File.read(path)
43
+ [*default_argv, *(options[:argv] || []), "-modify", file.path]
44
+ File.read(file.path)
43
45
  ensure
44
- rm(path) if File.exist?(path)
46
+ file&.unlink
45
47
  end
46
48
 
47
49
  private
@@ -50,23 +52,25 @@ module Nanoc::Tidy
50
52
  self.class.default_argv
51
53
  end
52
54
 
53
- def temporary_file(content)
54
- mkdir_p(tmpdir)
55
- file = Tempfile.new(File.basename(item.identifier.to_s), tmpdir)
56
- file.write(content)
57
- file.tap(&:flush)
55
+ def temporary_file(basename, content)
56
+ tempname = [
57
+ ".nanoc.tidy.#{basename}.#{object_id}",
58
+ SecureRandom.alphanumeric(3)
59
+ ]
60
+ Tempfile.new(tempname).tap do
61
+ _1.write(content)
62
+ _1.flush
63
+ end
58
64
  end
59
65
 
60
66
  def tidy
61
- case
62
- when system("which tidy > /dev/null 2>&1") then "tidy"
63
- when system("which tidy5 > /dev/null 2>&1") then "tidy5"
64
- else nil
67
+ if system("which tidy > /dev/null 2>&1")
68
+ "tidy"
69
+ elsif system("which tidy5 > /dev/null 2>&1")
70
+ "tidy5"
71
+ else
72
+ raise Nanoc::Tidy::Error, "tidy executable not found on $PATH"
65
73
  end
66
74
  end
67
-
68
- def tmpdir
69
- File.join(Dir.getwd, "tmp", "tidy-html5")
70
- end
71
75
  end
72
76
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nanoc::Tidy
2
4
  module Spawn
3
- require "securerandom"
4
5
  require "fileutils"
5
- Error = Class.new(RuntimeError)
6
+ require "test-cmd"
6
7
 
7
8
  ##
8
9
  # Spawns a process
@@ -13,45 +14,25 @@ module Nanoc::Tidy
13
14
  # @param [Array<String>] argv
14
15
  # An array of command line arguments
15
16
  #
16
- # @param [String] err
17
- # A path where stderr is redirected to
18
- #
19
- # @param [String] out
20
- # A path where stdout is redirected to
21
- #
22
17
  # @return [void]
23
- def spawn(exe, argv, err:, out:)
24
- id = SecureRandom.hex
25
- err = "#{err}+#{id}"
26
- out = "#{out}+#{id}"
27
- Kernel.spawn(
28
- exe, *argv, { STDERR => err, STDOUT => out }
29
- )
30
- Process.wait
31
- status = $?
18
+ def spawn(exe, argv)
19
+ r = cmd(exe, *argv)
32
20
  ##
33
21
  # exit codes
34
22
  # * 0: no warnings, no errors
35
23
  # * 1: has warnings
36
24
  # * 2: has errors
37
- return if [0, 1].include?(status.exitstatus)
38
-
39
- msgs = [err, out].map do
40
- FileUtils.touch(_1)
41
- [_1.gsub(Dir.getwd, ''), ":", "\n", File.binread(_1)].join
42
- end.join("\n")
43
- raise Error,
44
- "#{File.basename(exe)} exited unsuccessfully " \
45
- "(" \
46
- "exit code: #{status.exitstatus}, " \
47
- "item: #{item.identifier}" \
48
- ")" \
49
- "\n#{msgs}",
50
- []
51
- ensure
52
- [err, out]
53
- .select { File.exist?(_1) }
54
- .each { FileUtils.rm(_1) }
25
+ if [0, 1].include?(r.exit_status)
26
+ r.exit_status
27
+ else
28
+ raise Nanoc::Tidy::Error,
29
+ "#{File.basename(exe)} exited unsuccessfully\n" \
30
+ "(item: #{item.identifier})\n" \
31
+ "(exit code: #{r.exit_status})\n" \
32
+ "(stdout:\n#{r.stdout})\n" \
33
+ "(stderr:\n#{r.stderr})\n",
34
+ []
35
+ end
55
36
  end
56
37
  end
57
38
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nanoc
2
4
  module Tidy
3
- VERSION = "0.6.2"
5
+ VERSION = "0.8.0"
4
6
  end
5
7
  end
data/lib/nanoc/tidy.rb CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  require "nanoc"
4
4
  module Nanoc::Tidy
5
+ ##
6
+ # Generic error
7
+ Error = Class.new(RuntimeError)
8
+
9
+ require "securerandom"
5
10
  require_relative "tidy/version"
6
11
  require_relative "tidy/filter"
7
12
 
data/lib/nanoc-tidy.rb CHANGED
@@ -1,2 +1,3 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require_relative "nanoc/tidy"
@@ -10,8 +10,9 @@ Gem::Specification.new do |gem|
10
10
  gem.licenses = ["0BSD"]
11
11
  gem.files = `git ls-files`.split($/).reject { _1.start_with?(".") }
12
12
  gem.require_paths = ["lib"]
13
- gem.summary = "nanoc-tidy.rb integrates tidy-html5 into nanoc"
13
+ gem.summary = "nanoc + tidy-html5"
14
14
  gem.description = gem.summary
15
+ gem.add_runtime_dependency "test-cmd.rb", "~> 0.12.2"
15
16
  gem.add_development_dependency "yard", "~> 0.9"
16
17
  gem.add_development_dependency "redcarpet", "~> 3.5"
17
18
  gem.add_development_dependency "test-unit", "~> 3.6"
@@ -1,14 +1,16 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "setup"
2
4
 
3
5
  class FilterTest < Test::Unit::TestCase
4
6
  def test_default_options
5
- options = { argv: ["--tidy-mark", "false"] }
7
+ options = {argv: ["--tidy-mark", "false"]}
6
8
  assert_equal read_result("default_options.html"),
7
9
  filter_for("fixture.html").run(html, options)
8
10
  end
9
11
 
10
12
  def test_upper_option
11
- options = { argv: ["-upper", "--tidy-mark", "false"] }
13
+ options = {argv: ["-upper", "--tidy-mark", "false"]}
12
14
  assert_equal read_result("upper_option.html"),
13
15
  filter_for("fixture.html").run(html, options)
14
16
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-tidy.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-29 00:00:00.000000000 Z
11
+ date: 2024-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: test-cmd.rb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.12.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.12.2
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: yard
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,7 +136,7 @@ dependencies:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0.6'
125
- description: nanoc-tidy.rb integrates tidy-html5 into nanoc
139
+ description: nanoc + tidy-html5
126
140
  email:
127
141
  - 0x1eef@protonmail.com
128
142
  executables: []
@@ -166,5 +180,5 @@ requirements: []
166
180
  rubygems_version: 3.5.9
167
181
  signing_key:
168
182
  specification_version: 4
169
- summary: nanoc-tidy.rb integrates tidy-html5 into nanoc
183
+ summary: nanoc + tidy-html5
170
184
  test_files: []