nanoc-tidy.rb 0.3.0 → 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 +4 -4
- data/lib/nanoc/tidy/filter.rb +42 -16
- data/lib/nanoc/tidy/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d805396fd479848ce7e69377255fc4b646dd34bf35f4453337d79c3c2560bdce
|
4
|
+
data.tar.gz: '08f58910fda43532c3ab1161036cdabf810067a84dc1847211f07315e433dca5'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74c898f367043cf746d9d4a5b292d261b13ce551071232558215b9ea86573127590330534c960da49252a1ccd533008a7e9d89d133f4d9bd2b70b5391e038efc
|
7
|
+
data.tar.gz: 200c914a37b4fa14b350be967643dc3a5d97f95e7eb57169724b3450805f4462de03a66e593ebcbb0fad5f171a86103c78ac2335cd5857b006b1b26d33c14b10
|
data/lib/nanoc/tidy/filter.rb
CHANGED
@@ -22,18 +22,45 @@ class Nanoc::Tidy::Filter < Nanoc::Filter
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def run(content, options = {})
|
25
|
-
|
26
|
-
|
25
|
+
tidy temporary_file(content),
|
26
|
+
self.class.default_options.merge(options)
|
27
27
|
end
|
28
28
|
|
29
29
|
private
|
30
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
|
+
|
31
42
|
def tidy(file, options)
|
32
|
-
|
43
|
+
Process.wait spawn(
|
44
|
+
tidy_exe, "-modify", "-quiet", *tidy_args(options), file.path,
|
45
|
+
spawn_options
|
46
|
+
)
|
33
47
|
if $?.success?
|
34
48
|
File.read(file.path).tap { file.tap(&:unlink).close }
|
35
49
|
else
|
36
|
-
raise Error,
|
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"
|
37
64
|
end
|
38
65
|
end
|
39
66
|
|
@@ -47,19 +74,18 @@ class Nanoc::Tidy::Filter < Nanoc::Filter
|
|
47
74
|
end
|
48
75
|
end
|
49
76
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
end
|
77
|
+
##
|
78
|
+
# spawn-related methods
|
79
|
+
|
80
|
+
def spawn_options
|
81
|
+
{ STDOUT => log, STDERR => log }
|
56
82
|
end
|
57
83
|
|
58
|
-
def
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
84
|
+
def log
|
85
|
+
File.join(cwd, "tidy.log")
|
86
|
+
end
|
87
|
+
|
88
|
+
def cwd
|
89
|
+
File.join(Dir.getwd, "tmp", "nanoc-tidy.rb")
|
64
90
|
end
|
65
91
|
end
|
data/lib/nanoc/tidy/version.rb
CHANGED
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.
|
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-02-
|
11
|
+
date: 2024-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|