Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 83 lines (64 sloc) 1.74 kB
d94afe3 @djanowski Typos.
djanowski authored
1 task :default => [:parse, :spellcheck]
51b97ca Add a simple task to sanity-check JSON files.
Michel Martens & Damian Janowski authored
2
3 task :parse do
4 require "json"
5 require "batch"
74c8420 @djanowski Sanity check Markdowns.
djanowski authored
6 require "rdiscount"
51b97ca Add a simple task to sanity-check JSON files.
Michel Martens & Damian Janowski authored
7
74c8420 @djanowski Sanity check Markdowns.
djanowski authored
8 Batch.each(Dir["**/*.json"] + Dir["**/*.md"]) do |file|
9 if File.extname(file) == ".md"
10 RDiscount.new(File.read(file)).to_html
11 else
12 JSON.parse(File.read(file))
13 end
51b97ca Add a simple task to sanity-check JSON files.
Michel Martens & Damian Janowski authored
14 end
15 end
d94afe3 @djanowski Typos.
djanowski authored
16
17 task :spellcheck do
18 require "json"
19
20 `mkdir -p tmp`
21
22 IO.popen("aspell --lang=en create master ./tmp/dict", "w") do |io|
23 io.puts(JSON.parse(File.read("commands.json")).keys.map(&:split).flatten.join("\n"))
24 io.puts(File.read("wordlist"))
25 end
26
27 Dir["**/*.md"].each do |file|
28 command = %q{
29 ruby -pe 'gsub /^ .*$/, ""' |
30 ruby -pe 'gsub /`[^`]+`/, ""' |
31 ruby -e 'puts $stdin.read.gsub /\[([^\]]+)\]\(([^\)]+)\)/m, "\\1"' |
32 aspell -H -a --extra-dicts=./tmp/dict 2>/dev/null
33 }
34
35 words = `cat '#{file}' | #{command}`.lines.map do |line|
36 line[/^& ([^ ]+)/, 1]
37 end.compact
38
39 puts "#{file}: #{words.uniq.sort.join(" ")}" if words.any?
40 end
41 end
066c91d @pietern The universe is 80 characters wide...
pietern authored
42
43 namespace :format do
44
bf4cb61 @pietern Reformat command documentation
pietern authored
45 require "./remarkdown"
46
066c91d @pietern The universe is 80 characters wide...
pietern authored
47 def format(file)
48 return unless File.exist?(file)
49
50 STDOUT.print "formatting #{file}..."
51 STDOUT.flush
52
bf4cb61 @pietern Reformat command documentation
pietern authored
53 body = File.read(file)
54 body = ReMarkdown.new(body).to_s
55 body = body.gsub(/^\s+$/, "")
066c91d @pietern The universe is 80 characters wide...
pietern authored
56
57 File.open(file, "w") do |f|
58 f.print body
59 end
60
61 STDOUT.puts
62 end
63
815c0cc @pietern Add descriptions to reformat tasks
pietern authored
64 desc "Reformat single file"
066c91d @pietern The universe is 80 characters wide...
pietern authored
65 task :file, :path do |t, args|
66 format(args[:path])
67 end
68
815c0cc @pietern Add descriptions to reformat tasks
pietern authored
69 desc "Reformat changes staged for commit"
b340d58 @pietern Add task to format files that have been cached
pietern authored
70 task :cached do
71 `git diff --cached --name-only -- commands/`.split.each do |path|
72 format(path)
73 end
74 end
75
815c0cc @pietern Add descriptions to reformat tasks
pietern authored
76 desc "Reformat everything"
066c91d @pietern The universe is 80 characters wide...
pietern authored
77 task :all do
78 Dir["commands/*.md"].each do |path|
79 format(path)
80 end
81 end
82 end
Something went wrong with that request. Please try again.