nanoc-tidy.rb 0.7.0 → 0.8.1

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: baa9bd78c6f407c7050903ec46fe89c19a702dc788eb556438078d43f10c2adf
4
- data.tar.gz: 5bd8b9fd26eb7eb0a6831eaee86d0da38e02ceee4589cfbdef4881f29f52b6a7
3
+ metadata.gz: '0898b9a7ec2f3c137c9fa5233313a88102ea13ad27f8b6093f258c1f0f096e66'
4
+ data.tar.gz: 344d471e7428617674f06a759da09dcde5807ccdbc811ee76ab0a8e3d5d01083
5
5
  SHA512:
6
- metadata.gz: 3acb6eb29a332c6013cdaa878f54327abfc96ec87fbd36c8a439afe153469b724713cea1a77572ab02b069c24e6f3dac25c1b05e00aeac146e304f9637c6766e
7
- data.tar.gz: 83f346f2273873f02015065cc8701d8693e6cfd8a26686a767789a9dcd2f4cd46b084b452b928807758141ac4e3f312afb0f80d63bc6f355cdbd1663db9ab03d
6
+ metadata.gz: dd18a0e8598f6cfd2fe27a2294deed691d8e671110ea1efa3521fbb7c0005a17e43178251c9a90a331a0a8bbfdea46fb728982b78debb49a8c8699d7eb0a1fd7
7
+ data.tar.gz: 84471209421d20f88c6a6b36e05ed51f11c85cfebb623ad63c93ba35cf92a53335461cf518ea1ed56a32f4295e07d0924e91a5ad2be06ccf52dfbca9667c4d8a
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,11 @@ 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
36
+ [Nanoc::Tidy.default_argv](https://0x1eef.github.io/x/nanoc-tidy.rb/Nanoc/Tidy/Filter#default_argv-class_method):
34
37
 
35
38
  ```ruby
36
39
  # Rules
@@ -43,7 +46,24 @@ compile "/index.html.erb" do
43
46
  end
44
47
  ```
45
48
 
46
- ## <a id='install'>Install</a>
49
+ __Option: exe__
50
+
51
+ The "exe" option can be used to change the default executable
52
+ from "tidy5" to something else, the most common alternative
53
+ might be "tidy":
54
+
55
+ ```ruby
56
+ # Rules
57
+ require "nanoc-tidy"
58
+ compile "/index.html.erb" do
59
+ layout("/default.*")
60
+ filter(:erb)
61
+ filter(:tidy, exe: "tidy")
62
+ write("/index.html")
63
+ end
64
+ ```
65
+
66
+ ## Install
47
67
 
48
68
  **Rubygems.org**
49
69
 
@@ -58,6 +78,6 @@ nanoc-tidy.rb can be installed via rubygems.org:
58
78
 
59
79
  ## License
60
80
 
61
- [BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
81
+ [BSD Zero Clause](https://choosealicense.com/licenses/0bsd/)
62
82
  <br>
63
- See [LICENSE](./LICENSE).
83
+ See [LICENSE](./LICENSE)
@@ -4,7 +4,6 @@ module Nanoc::Tidy
4
4
  class Filter < Nanoc::Filter
5
5
  require "fileutils"
6
6
  require_relative "spawn"
7
-
8
7
  include Spawn
9
8
  include FileUtils
10
9
 
@@ -39,11 +38,11 @@ module Nanoc::Tidy
39
38
  File.basename(item.identifier.to_s),
40
39
  content
41
40
  )
42
- spawn tidy,
41
+ spawn options[:exe] || "tidy5",
43
42
  [*default_argv, *(options[:argv] || []), "-modify", file.path]
44
43
  File.read(file.path)
45
44
  ensure
46
- file&.unlink
45
+ file ? file.tap(&:unlink).close : nil
47
46
  end
48
47
 
49
48
  private
@@ -53,24 +52,14 @@ module Nanoc::Tidy
53
52
  end
54
53
 
55
54
  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
64
- end
65
-
66
- def tidy
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"
73
- end
55
+ tmpdir = File.join(Dir.getwd, "tmp", "tidy")
56
+ name = item.identifier.to_s
57
+ file = Tempfile.new(
58
+ [ File.basename(name), File.extname(name) ],
59
+ mkdir_p(tmpdir).last
60
+ )
61
+ file.write(content)
62
+ file.tap(&:flush)
74
63
  end
75
64
  end
76
65
  end
@@ -3,6 +3,7 @@
3
3
  module Nanoc::Tidy
4
4
  module Spawn
5
5
  require "fileutils"
6
+ require "test-cmd"
6
7
 
7
8
  ##
8
9
  # Spawns a process
@@ -13,29 +14,26 @@ module Nanoc::Tidy
13
14
  # @param [Array<String>] argv
14
15
  # An array of command line arguments
15
16
  #
16
- # @return [void]
17
- def spawn(exe, argv, workdir: File.join(Dir.getwd, "tmp"))
18
- logfile = File.join(workdir, ".#{Process.pid}.tidy")
19
- Kernel.spawn(exe, *argv, {STDERR => logfile, STDOUT => logfile})
20
- Process.wait
21
- status = $?
17
+ # @return [Integer]
18
+ # Returns the exit code of the spawned process
19
+ def spawn(exe, argv)
20
+ r = cmd(exe, *argv)
22
21
  ##
23
22
  # exit codes
24
23
  # * 0: no warnings, no errors
25
24
  # * 1: has warnings
26
25
  # * 2: has errors
27
- if [0, 1].include?(status.exitstatus)
28
- status.exitstatus
26
+ if [0, 1].include?(r.exit_status)
27
+ r.exit_status
29
28
  else
30
29
  raise Nanoc::Tidy::Error,
31
30
  "#{File.basename(exe)} exited unsuccessfully\n" \
32
31
  "(item: #{item.identifier})\n" \
33
- "(exit code: #{status.exitstatus})\n" \
34
- "output:\n#{File.binread(logfile)}\n",
32
+ "(exit code: #{r.exit_status})\n" \
33
+ "(stdout: #{r.stdout&.chomp})\n" \
34
+ "(stderr: #{r.stderr&.chomp})\n",
35
35
  []
36
36
  end
37
- ensure
38
- File.exist?(logfile) ? FileUtils.rm(logfile) : nil
39
37
  end
40
38
  end
41
39
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Tidy
5
- VERSION = "0.7.0"
5
+ VERSION = "0.8.1"
6
6
  end
7
7
  end
data/lib/nanoc/tidy.rb CHANGED
@@ -6,7 +6,6 @@ module Nanoc::Tidy
6
6
  # Generic error
7
7
  Error = Class.new(RuntimeError)
8
8
 
9
- require "securerandom"
10
9
  require_relative "tidy/version"
11
10
  require_relative "tidy/filter"
12
11
 
@@ -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-html5"
13
+ gem.summary = "nanoc-tidy.rb = 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"
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.7.0
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-24 00:00:00.000000000 Z
11
+ date: 2024-06-15 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-html5
139
+ description: nanoc-tidy.rb = 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-html5
183
+ summary: nanoc-tidy.rb = nanoc + tidy-html5
170
184
  test_files: []