Skip to content

Commit 5497129

Browse files
committed
Use Make for spell checking.
1 parent 42f9cda commit 5497129

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+90
-70
lines changed

.gems

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
batch -v 1.0.4
2+
redcarpet -v 3.3.2

.travis.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ addons:
77
- aspell-en
88

99
rvm:
10-
- 1.9.3
10+
- 2.2
11+
12+
script: make
1113

1214
gemfile:
1315
- .travis/Gemfile

.travis/Gemfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ source "https://rubygems.org"
22

33
gem "rake"
44
gem "batch"
5-
gem "rdiscount"
5+
gem "redcarpet"

README.md

+9-18

Rakefile

+3-46
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,12 @@
1-
task :default => [:parse, :spellcheck]
1+
task :default => [:parse]
22

33
task :parse do
44
require "json"
55
require "batch"
6-
require "rdiscount"
76

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
14-
end
15-
end
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-
words = JSON.parse(File.read("commands.json")).
24-
keys.
25-
map { |str| str.split(/[ -]/) }.
26-
flatten(1)
27-
28-
io.puts(words.join("\n"))
29-
io.puts(File.read("wordlist"))
7+
Batch.each(Dir["**/*.json"]) do |file|
8+
JSON.parse(File.read(file))
309
end
31-
32-
errors = false
33-
34-
Dir["**/*.md"].each do |file|
35-
command = %q{
36-
ruby -pe 'gsub /^ .*$/, ""' |
37-
ruby -pe 'gsub /`[^`]+`/, ""' |
38-
ruby -e 'puts $stdin.read.gsub(/\[([^\]]+)\]\(([^\)]+)\)/m, "\\1").gsub(/^```.*```/m, "")' |
39-
aspell --lang=en -H -a --extra-dicts=./tmp/dict 2>/dev/null
40-
}
41-
42-
words = `cat '#{file}' | #{command}`.lines.map do |line|
43-
line[/^& ([^ ]+)/, 1]
44-
end.compact
45-
46-
if words.size > 0
47-
errors = true
48-
puts("#{file}: #{words.uniq.sort.join(" ")}")
49-
end
50-
end
51-
52-
abort("Spelling errors found.") if errors
5310
end
5411

5512
namespace :format do

bin/text

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env ruby
2+
3+
require "redcarpet"
4+
require "redcarpet/render_strip"
5+
6+
class Renderer < Redcarpet::Render::StripDown
7+
def link(link, title, content)
8+
content
9+
end
10+
11+
def image(link, title, content)
12+
content
13+
end
14+
15+
def block_code(*args)
16+
""
17+
end
18+
19+
def codespan(*args)
20+
""
21+
end
22+
23+
def block_html(*args)
24+
""
25+
end
26+
27+
def raw_html(*args)
28+
""
29+
end
30+
end
31+
32+
engine = Redcarpet::Markdown.new(
33+
Renderer.new,
34+
no_intra_emphasis: true,
35+
fenced_code_blocks: true,
36+
superscript: true
37+
)
38+
39+
puts(engine.render(File.read(ARGV[0])))

commands/geohash.md

+1-1

makefile

+32-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,33 @@
1-
clients: .PHONY
2-
ruby -rjson -r./utils/clients -e 'Clients.check(JSON.parse(File.read("clients.json"), symbolize_names: true))'
1+
MD_FILES:=$(shell find {commands,topics} -name '*.md')
2+
TEXT_FILES:=$(patsubst %.md,tmp/%.txt,$(MD_FILES))
3+
SPELL_FILES:=$(patsubst %.txt,%.spell,$(TEXT_FILES))
34

4-
.PHONY:
5+
spell: tmp/commands tmp/topics $(SPELL_FILES)
6+
find tmp -name '*.spell' | xargs cat > tmp/all.spell
7+
cat tmp/all.spell
8+
test -s tmp/all.spell && exit 1
9+
10+
$(TEXT_FILES): tmp/%.txt: %.md
11+
./bin/text $< > $@
12+
13+
$(SPELL_FILES): %.spell: %.txt tmp/dict
14+
aspell -a --extra-dicts=./tmp/dict 2>/dev/null < $< | \
15+
awk -v FILE=$(patsubst tmp/%.spell,%.md,$@) '/^\&/ { print FILE, $$2 }' | \
16+
sort -f | uniq > $@
17+
18+
tmp/commands:
19+
mkdir -p tmp/commands
20+
21+
tmp/topics:
22+
mkdir -p tmp/topics
23+
24+
tmp/commands.txt: commands.json
25+
ruby -rjson -e 'puts JSON.parse(File.read("$<")).keys.map { |str| str.split(/[ -]/) }.flatten(1)' > $@
26+
27+
tmp/dict: wordlist tmp/commands.txt
28+
cat $^ | aspell --lang=en create master ./$@
29+
30+
clean:
31+
rm -rf tmp/*
32+
33+
.PHONY: clean

0 commit comments

Comments
 (0)