forked from redis/redis-doc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
82 lines (64 loc) · 1.7 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
task :default => [:parse, :spellcheck]
task :parse do
require "json"
require "batch"
require "rdiscount"
Batch.each(Dir["**/*.json"] + Dir["**/*.md"]) do |file|
if File.extname(file) == ".md"
RDiscount.new(File.read(file)).to_html
else
JSON.parse(File.read(file))
end
end
end
task :spellcheck do
require "json"
`mkdir -p tmp`
IO.popen("aspell --lang=en create master ./tmp/dict", "w") do |io|
io.puts(JSON.parse(File.read("commands.json")).keys.map(&:split).flatten.join("\n"))
io.puts(File.read("wordlist"))
end
Dir["**/*.md"].each do |file|
command = %q{
ruby -pe 'gsub /^ .*$/, ""' |
ruby -pe 'gsub /`[^`]+`/, ""' |
ruby -e 'puts $stdin.read.gsub /\[([^\]]+)\]\(([^\)]+)\)/m, "\\1"' |
aspell -H -a --extra-dicts=./tmp/dict 2>/dev/null
}
words = `cat '#{file}' | #{command}`.lines.map do |line|
line[/^& ([^ ]+)/, 1]
end.compact
puts "#{file}: #{words.uniq.sort.join(" ")}" if words.any?
end
end
namespace :format do
require "./remarkdown"
def format(file)
return unless File.exist?(file)
STDOUT.print "formatting #{file}..."
STDOUT.flush
body = File.read(file)
body = ReMarkdown.new(body).to_s
body = body.gsub(/^\s+$/, "")
File.open(file, "w") do |f|
f.print body
end
STDOUT.puts
end
desc "Reformat single file"
task :file, :path do |t, args|
format(args[:path])
end
desc "Reformat changes staged for commit"
task :cached do
`git diff --cached --name-only -- commands/`.split.each do |path|
format(path)
end
end
desc "Reformat everything"
task :all do
Dir["commands/*.md"].each do |path|
format(path)
end
end
end