nanoc-tidy.rb 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 133f30c53d54b2f5cea16c3877fa597d86b5db84bb240214459eee5e6a8c4f07
4
- data.tar.gz: 8d054b51e4f6fbd7351fac5eb78ddcae57bcf175ebfea062c588daf9d5358c56
3
+ metadata.gz: '0898b9a7ec2f3c137c9fa5233313a88102ea13ad27f8b6093f258c1f0f096e66'
4
+ data.tar.gz: 344d471e7428617674f06a759da09dcde5807ccdbc811ee76ab0a8e3d5d01083
5
5
  SHA512:
6
- metadata.gz: 95b712fefeaf461ec57efe23fbcfada16a9be99498ee923affd4db983ffa522157f95b2659a4fd726d626296a515a6cb1631ca1ae890af7caa5e8ef82949716a
7
- data.tar.gz: d83de9881073f9a53818fec78482c7a98023acc1bc798137b78a766b96f343cec659b54e06425cda3cd78c611d32a2b606c9f15cca466859ca3b95257e9cb4ef
6
+ metadata.gz: dd18a0e8598f6cfd2fe27a2294deed691d8e671110ea1efa3521fbb7c0005a17e43178251c9a90a331a0a8bbfdea46fb728982b78debb49a8c8699d7eb0a1fd7
7
+ data.tar.gz: 84471209421d20f88c6a6b36e05ed51f11c85cfebb623ad63c93ba35cf92a53335461cf518ea1ed56a32f4295e07d0924e91a5ad2be06ccf52dfbca9667c4d8a
data/README.md CHANGED
@@ -32,7 +32,8 @@ end
32
32
  __Option: argv__
33
33
 
34
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):
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):
36
37
 
37
38
  ```ruby
38
39
  # Rules
@@ -45,6 +46,23 @@ compile "/index.html.erb" do
45
46
  end
46
47
  ```
47
48
 
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
+
48
66
  ## Install
49
67
 
50
68
  **Rubygems.org**
@@ -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
@@ -14,7 +14,8 @@ module Nanoc::Tidy
14
14
  # @param [Array<String>] argv
15
15
  # An array of command line arguments
16
16
  #
17
- # @return [void]
17
+ # @return [Integer]
18
+ # Returns the exit code of the spawned process
18
19
  def spawn(exe, argv)
19
20
  r = cmd(exe, *argv)
20
21
  ##
@@ -29,8 +30,8 @@ module Nanoc::Tidy
29
30
  "#{File.basename(exe)} exited unsuccessfully\n" \
30
31
  "(item: #{item.identifier})\n" \
31
32
  "(exit code: #{r.exit_status})\n" \
32
- "(stdout:\n#{r.stdout})\n" \
33
- "(stderr:\n#{r.stderr})\n",
33
+ "(stdout: #{r.stdout&.chomp})\n" \
34
+ "(stderr: #{r.stderr&.chomp})\n",
34
35
  []
35
36
  end
36
37
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Nanoc
4
4
  module Tidy
5
- VERSION = "0.8.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,7 +10,7 @@ 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
15
  gem.add_runtime_dependency "test-cmd.rb", "~> 0.12.2"
16
16
  gem.add_development_dependency "yard", "~> 0.9"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nanoc-tidy.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.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-06-14 00:00:00.000000000 Z
11
+ date: 2024-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test-cmd.rb
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0.6'
139
- description: nanoc + tidy-html5
139
+ description: nanoc-tidy.rb = nanoc + tidy-html5
140
140
  email:
141
141
  - 0x1eef@protonmail.com
142
142
  executables: []
@@ -180,5 +180,5 @@ requirements: []
180
180
  rubygems_version: 3.5.9
181
181
  signing_key:
182
182
  specification_version: 4
183
- summary: nanoc + tidy-html5
183
+ summary: nanoc-tidy.rb = nanoc + tidy-html5
184
184
  test_files: []