nanoc-tidy.rb 0.2.2 → 0.4.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: 3dcf61d9f8cd7befb47dcf0f0f15d3e31b5b6dfa849f19d255c10e0ce0083fbc
4
- data.tar.gz: eca622d7fe8ac8dd883de3393225420efb9ca9f0ab0c5d39c1b8a3cab41ede3c
3
+ metadata.gz: d805396fd479848ce7e69377255fc4b646dd34bf35f4453337d79c3c2560bdce
4
+ data.tar.gz: '08f58910fda43532c3ab1161036cdabf810067a84dc1847211f07315e433dca5'
5
5
  SHA512:
6
- metadata.gz: 43cd2a510955f332b8aef7d06c884eeb8e958cfa9789a5f96880b9fe5ab744297d1c289b3b8fdcc027c5d8fc60df0a6ea9f03648d66fab47f068e037ec1bbe4d
7
- data.tar.gz: 3c03bef0d16ff6762522b00f9fb84763fe7cba1ea5bdc1496e3335d874aa2f0bc92a6ff31823f00649877855c567cf7af834db55c707196da3651b5d85458507
6
+ metadata.gz: 74c898f367043cf746d9d4a5b292d261b13ce551071232558215b9ea86573127590330534c960da49252a1ccd533008a7e9d89d133f4d9bd2b70b5391e038efc
7
+ data.tar.gz: 200c914a37b4fa14b350be967643dc3a5d97f95e7eb57169724b3450805f4462de03a66e593ebcbb0fad5f171a86103c78ac2335cd5857b006b1b26d33c14b10
data/README.md CHANGED
@@ -13,9 +13,8 @@ are often commonplace.
13
13
 
14
14
  __Defaults__
15
15
 
16
- The following is an example with the
17
- [default options](https://0x1eef.github.io/x/nanoc-tidy.rb/Nanoc/Tidy/Filter#default_options-class_method)
18
- being used:
16
+ The following is an example that uses the
17
+ [default options](https://0x1eef.github.io/x/nanoc-tidy.rb/Nanoc/Tidy/Filter#default_options-class_method):
19
18
 
20
19
  ``` ruby
21
20
  # Rules
@@ -30,7 +29,7 @@ end
30
29
 
31
30
  __Options__
32
31
 
33
- The following example forwards command-line options to
32
+ The following example forwards custom command-line options to
34
33
  [tidy-html5](https://github.com/htacg/tidy-html5):
35
34
 
36
35
  ```ruby
@@ -9,6 +9,11 @@ class Nanoc::Tidy::Filter < Nanoc::Filter
9
9
  type text: :text
10
10
 
11
11
  ##
12
+ # @example
13
+ # Nanoc::Tidy.default_options.merge!(
14
+ # "-upper" => true
15
+ # )
16
+ #
12
17
  # @return [{"-wrap" => 120, "-indent" => true}]
13
18
  # Returns the default options forwarded as command-line
14
19
  # arguments to tidy-html5.
@@ -17,18 +22,45 @@ class Nanoc::Tidy::Filter < Nanoc::Filter
17
22
  end
18
23
 
19
24
  def run(content, options = {})
20
- file = temporary_file_for(content)
21
- tidy file, self.class.default_options.merge(options)
25
+ tidy temporary_file(content),
26
+ self.class.default_options.merge(options)
22
27
  end
23
28
 
24
29
  private
25
30
 
31
+ def temporary_file(content)
32
+ dir = cwd
33
+ mkdir_p(dir) unless Dir.exist?(dir)
34
+ file = Tempfile.new(File.basename(item.identifier.to_s), dir)
35
+ file.write(content)
36
+ file.tap(&:flush)
37
+ end
38
+
39
+ ##
40
+ # tidy executable interface
41
+
26
42
  def tidy(file, options)
27
- system tidy_exe, "-modify", "-quiet", *tidy_args(options), file.path
43
+ Process.wait spawn(
44
+ tidy_exe, "-modify", "-quiet", *tidy_args(options), file.path,
45
+ spawn_options
46
+ )
28
47
  if $?.success?
29
48
  File.read(file.path).tap { file.tap(&:unlink).close }
30
49
  else
31
- raise Error, "tidy exited unsuccessfully (exit code: #{$?.exitstatus})", []
50
+ raise Error,
51
+ "tidy exited unsuccessfully " \
52
+ "(exit code: #{$?.exitstatus}, " \
53
+ "item: #{item.identifier}, " \
54
+ "log: #{log.gsub(Dir.getwd, '')[1..]})",
55
+ []
56
+ end
57
+ end
58
+
59
+ def tidy_exe
60
+ case
61
+ when system("which tidy > /dev/null 2>&1") then "tidy"
62
+ when system("which tidy5 > /dev/null 2>&1") then "tidy5"
63
+ else raise Error, "unable to find a tidy executable on $PATH"
32
64
  end
33
65
  end
34
66
 
@@ -42,19 +74,18 @@ class Nanoc::Tidy::Filter < Nanoc::Filter
42
74
  end
43
75
  end
44
76
 
45
- def tidy_exe
46
- case
47
- when system("which tidy > /dev/null 2>&1") then "tidy"
48
- when system("which tidy5 > /dev/null 2>&1") then "tidy5"
49
- else raise Error, "unable to find a tidy executable on $PATH"
50
- end
77
+ ##
78
+ # spawn-related methods
79
+
80
+ def spawn_options
81
+ { STDOUT => log, STDERR => log }
51
82
  end
52
83
 
53
- def temporary_file_for(content)
54
- dir = File.join(Dir.getwd, "tmp", "nanoc-tidy.rb")
55
- mkdir_p(dir) unless Dir.exist?(dir)
56
- file = Tempfile.new(File.basename(item.identifier.to_s), dir)
57
- file.write(content)
58
- file.tap(&:flush)
84
+ def log
85
+ File.join(cwd, "tidy.log")
86
+ end
87
+
88
+ def cwd
89
+ File.join(Dir.getwd, "tmp", "nanoc-tidy.rb")
59
90
  end
60
91
  end
@@ -1,5 +1,5 @@
1
1
  module Nanoc
2
2
  module Tidy
3
- VERSION = "0.2.2"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/lib/nanoc/tidy.rb CHANGED
@@ -4,4 +4,11 @@ require "nanoc"
4
4
  module Nanoc::Tidy
5
5
  require_relative "tidy/version"
6
6
  require_relative "tidy/filter"
7
+
8
+ ##
9
+ # @example (see Nanoc::Tidy::Filter.default_options)
10
+ # @return (see Nanoc::Tidy::Filter.default_options)
11
+ def self.default_options
12
+ Filter.default_options
13
+ end
7
14
  end
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.2.2
4
+ version: 0.4.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-01-30 00:00:00.000000000 Z
11
+ date: 2024-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard