moonshard 0.2.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/moonshard.rb +31 -69
- data/moonshard.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d18c56c8d60d654600cf9681405d9abf4420e430c98eaff816861c7eadece4ae
|
|
4
|
+
data.tar.gz: 3da4545e60a4fdefd3a2be759eadacae9d9fa6e415eba6f899ed69472709bf1e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8eafa7bd31a734ba77b4a5b1d3fe46c268c3eef1b188c23f0b748ca3e9da923b57e4e721869b31b46b25ce79628ec8faa15532d2938621819324dcff29185be9
|
|
7
|
+
data.tar.gz: 949cde414a606d182d34955bf719621684f4e00b44cb066e343a23d9d48d63d7870b5aa071a696adcb5dbe76378ebcb220450cc7c52c0679ef16425de114cfeb
|
data/lib/moonshard.rb
CHANGED
|
@@ -29,7 +29,7 @@ module Moonshard
|
|
|
29
29
|
|
|
30
30
|
original_files.each do |file, content|
|
|
31
31
|
begin
|
|
32
|
-
File.
|
|
32
|
+
File.write(file, content)
|
|
33
33
|
puts "Restored: #{file}"
|
|
34
34
|
rescue => e
|
|
35
35
|
warn "Warning: cannot restore #{file}: #{e.message}"
|
|
@@ -54,89 +54,51 @@ module Moonshard
|
|
|
54
54
|
next if File.expand_path(file) == backup_file
|
|
55
55
|
|
|
56
56
|
begin
|
|
57
|
-
|
|
58
|
-
# invalid UTF-8 errors.
|
|
59
|
-
content = File.binread(file)
|
|
57
|
+
content = File.read(file)
|
|
60
58
|
rescue => e
|
|
61
59
|
warn "Warning: cannot read #{file}: #{e.message}"
|
|
62
60
|
next
|
|
63
61
|
end
|
|
64
62
|
|
|
65
|
-
#
|
|
66
|
-
next unless content.
|
|
63
|
+
# Only process files containing ##{...}
|
|
64
|
+
next unless content.match?(/##\{[^}]+\}/)
|
|
67
65
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# Skip files that aren't valid UTF-8.
|
|
71
|
-
text = content.force_encoding(Encoding::UTF_8)
|
|
72
|
-
|
|
73
|
-
unless text.valid_encoding?
|
|
74
|
-
warn "Skipping binary/non-UTF-8 file: #{file}"
|
|
75
|
-
next
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
# Save original content before replacement.
|
|
79
|
-
original_files[file] = text
|
|
66
|
+
# Save original content before replacement
|
|
67
|
+
original_files[file] = content
|
|
80
68
|
|
|
81
|
-
|
|
69
|
+
file_dir = File.dirname(file)
|
|
82
70
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
referenced_path = File.expand_path(
|
|
88
|
-
referenced_file,
|
|
89
|
-
file_dir
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
unless File.file?(referenced_path)
|
|
93
|
-
warn "Warning: file not found: #{referenced_path} " \
|
|
94
|
-
"(referenced from #{file})"
|
|
95
|
-
|
|
96
|
-
next Regexp.last_match(0)
|
|
97
|
-
end
|
|
71
|
+
replaced = content.gsub(/^([ \t]*)##\{([^}]+)\}[ \t]*$/) do
|
|
72
|
+
indentation = Regexp.last_match(1)
|
|
73
|
+
referenced_file = Regexp.last_match(2)
|
|
98
74
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
next Regexp.last_match(0)
|
|
104
|
-
end
|
|
75
|
+
referenced_path = File.expand_path(
|
|
76
|
+
referenced_file,
|
|
77
|
+
file_dir
|
|
78
|
+
)
|
|
105
79
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
)
|
|
80
|
+
unless File.file?(referenced_path)
|
|
81
|
+
warn "Warning: file not found: #{referenced_path} (referenced from #{file})"
|
|
82
|
+
next Regexp.last_match(0)
|
|
83
|
+
end
|
|
109
84
|
|
|
110
|
-
|
|
111
|
-
warn "Warning: referenced file is not valid UTF-8: " \
|
|
112
|
-
"#{referenced_path}"
|
|
85
|
+
inserted_content = File.read(referenced_path).chomp
|
|
113
86
|
|
|
114
|
-
|
|
87
|
+
# Apply the indentation of ##{...}
|
|
88
|
+
# to every non-empty line.
|
|
89
|
+
inserted_content.lines.map do |line|
|
|
90
|
+
if line.strip.empty?
|
|
91
|
+
line
|
|
92
|
+
else
|
|
93
|
+
indentation + line
|
|
115
94
|
end
|
|
95
|
+
end.join
|
|
96
|
+
end
|
|
116
97
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
# Apply the indentation from ##{...}
|
|
120
|
-
# to every non-empty line.
|
|
121
|
-
inserted_content.lines.map do |line|
|
|
122
|
-
if line.strip.empty?
|
|
123
|
-
line
|
|
124
|
-
else
|
|
125
|
-
indentation + line
|
|
126
|
-
end
|
|
127
|
-
end.join
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
next if replaced == text
|
|
131
|
-
|
|
132
|
-
File.binwrite(file, replaced)
|
|
98
|
+
next if replaced == content
|
|
133
99
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
warn "Warning: cannot process #{file}: #{e.message}"
|
|
137
|
-
rescue => e
|
|
138
|
-
warn "Warning: cannot process #{file}: #{e.message}"
|
|
139
|
-
end
|
|
100
|
+
File.write(file, replaced)
|
|
101
|
+
puts "Updated: #{file}"
|
|
140
102
|
end
|
|
141
103
|
|
|
142
104
|
File.write(
|
data/moonshard.gemspec
CHANGED