middleman-spellcheck 0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +13 -0
- data/features/allowed.feature +6 -0
- data/features/only_tags.feature +6 -0
- data/features/page_params.feature +6 -0
- data/features/plain_app.feature +6 -0
- data/features/spelling_check.feature +11 -0
- data/features/support/env.rb +6 -0
- data/fixtures/allow_app/config.rb +1 -0
- data/fixtures/allow_app/source/index.html.erb +1 -0
- data/fixtures/correct_spelling_app/config.rb +1 -0
- data/fixtures/correct_spelling_app/source/index.html.erb +1 -0
- data/fixtures/incorrect_spelling_app/config.rb +1 -0
- data/fixtures/incorrect_spelling_app/source/index.html.erb +1 -0
- data/fixtures/only_tags_app/config.rb +1 -0
- data/fixtures/only_tags_app/source/index.html.erb +4 -0
- data/fixtures/plain_app/config.rb +0 -0
- data/fixtures/plain_app/source/index.html.erb +1 -0
- data/fixtures/spelling_path_app/config.rb +1 -0
- data/fixtures/spelling_path_app/source/check/index.html +1 -0
- data/fixtures/spelling_path_app/source/no_check/index.html +1 -0
- data/lib/middleman-spellcheck.rb +7 -0
- data/lib/middleman-spellcheck/extension.rb +84 -0
- data/lib/middleman-spellcheck/spellchecker.rb +47 -0
- data/lib/middleman-spellcheck/version.rb +5 -0
- data/lib/middleman_extension.rb +1 -0
- data/middleman-spellcheck.gemspec +26 -0
- metadata +130 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: af6acef72c4a8c1198d0af0035eeb3300ea7b522
|
4
|
+
data.tar.gz: 5d13b60d36b5fbcc3201a53bb1b9e04a75036e7f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a4278e8b1e7c25e82bab5b6bb127ce40fff257fe22e896aed4aaca5c972ee9fa8f0a5f03a9e60dece55f23a8a61b1ac916195b87c89091b073067152a45c1713
|
7
|
+
data.tar.gz: 2aef6a45b02d6ee5b9c5159cfacaeccb0b9854fd500c52f4a9a491b9b2b3ca3e558c5ab91ef60d925c06bfdeb88ed55315797e74ca4f2d9dcf89128636c6e8e3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ivan Zarea
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Middleman::Spellcheck
|
2
|
+
|
3
|
+
Run a spell checker job after the app is built. Requires 'aspell'.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'middleman-spellcheck'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Add the following to middleman's `config.rb`:
|
16
|
+
|
17
|
+
activate :spellcheck
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You can spellcheck only some resources using a regex with the URL:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
activate :spellcheck, page: "documentation/*" # you can use regexes, too, e.g. /post_[1-9]/
|
25
|
+
```
|
26
|
+
|
27
|
+
You can limit which tags the spell checker will only run through:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
activate :spellcheck, tags: :p # pass an array of tags if you have more!
|
31
|
+
```
|
32
|
+
|
33
|
+
If there are some words that you would like to be allowed
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
activate :spellcheck, allow: ["Gooby", "pls"]
|
37
|
+
```
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
|
+
exempt_tags = ""
|
8
|
+
exempt_tags << "--tags ~@nojava " if RUBY_PLATFORM == "java"
|
9
|
+
t.cucumber_opts = "--color --tags ~@wip #{exempt_tags} --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}"
|
10
|
+
end
|
11
|
+
|
12
|
+
task :test => ["cucumber"]
|
13
|
+
task :default => :test
|
@@ -0,0 +1,6 @@
|
|
1
|
+
Feature: Building an application with the spell checker enabled for some paths
|
2
|
+
|
3
|
+
Scenario: The spelling errors in the parameters that do not match the path are ignored
|
4
|
+
Given a fixture app "spelling_path_app"
|
5
|
+
When I run `middleman build`
|
6
|
+
Then the exit status should be 0
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Feature: Building an application with the spell checker enabled
|
2
|
+
|
3
|
+
Scenario: When the spelling is correct
|
4
|
+
Given a fixture app "correct_spelling_app"
|
5
|
+
When I run `middleman build`
|
6
|
+
Then the exit status should be 0
|
7
|
+
|
8
|
+
Scenario: When the spelling is incorrect
|
9
|
+
Given a fixture app "incorrect_spelling_app"
|
10
|
+
When I run `middleman build`
|
11
|
+
Then the exit status should be 1
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :spellcheck, allow: ["dolan"]
|
@@ -0,0 +1 @@
|
|
1
|
+
Dolan walks into a park. dolan feels good.
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :spellcheck
|
@@ -0,0 +1 @@
|
|
1
|
+
No spelling issues found here!
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :spellcheck
|
@@ -0,0 +1 @@
|
|
1
|
+
Some speling isuses here!
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :spellcheck, tags: :p
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello, <%= "TEST".downcase %>
|
@@ -0,0 +1 @@
|
|
1
|
+
activate :spellcheck, page: "[^no_]check/*"
|
@@ -0,0 +1 @@
|
|
1
|
+
There are no spelling errors here
|
@@ -0,0 +1 @@
|
|
1
|
+
Theer are soome splelling erors her! Gooby pls.
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'middleman-spellcheck/spellchecker'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module Spellcheck
|
6
|
+
class SpellcheckExtension < Extension
|
7
|
+
option :page, "/*", "Run only pages that match the regex through the spellchecker"
|
8
|
+
option :tags, [], "Run spellcheck only on some tags from the output"
|
9
|
+
option :allow, [], "Allow specific words to be misspelled"
|
10
|
+
|
11
|
+
def after_build(builder)
|
12
|
+
filtered = filter_resources(app, options.page)
|
13
|
+
total_misspelled = []
|
14
|
+
|
15
|
+
filtered.each do |resource|
|
16
|
+
builder.say_status :spellcheck, "Running spell checker for #{resource.url}", :blue
|
17
|
+
current_misspelled = run_check(select_content(resource))
|
18
|
+
current_misspelled.each do |misspell|
|
19
|
+
builder.say_status :misspell, error_message(misspell), :red
|
20
|
+
end
|
21
|
+
total_misspelled += current_misspelled
|
22
|
+
end
|
23
|
+
|
24
|
+
unless total_misspelled.empty?
|
25
|
+
raise Thor::Error, "Build failed. There are spelling errors."
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def select_content(resource)
|
30
|
+
rendered_resource = resource.render(layout: false)
|
31
|
+
doc = Nokogiri::HTML(rendered_resource)
|
32
|
+
|
33
|
+
if options.tags.empty?
|
34
|
+
doc.text
|
35
|
+
else
|
36
|
+
select_tagged_content(doc, option_tags)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def option_tags
|
41
|
+
if options.tags.is_a? Array
|
42
|
+
options.tags
|
43
|
+
else
|
44
|
+
[options.tags]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def select_tagged_content(doc, tags)
|
49
|
+
tags.map { |tag| texts_for_tag(doc, tag.to_s) }.flatten.join(' ')
|
50
|
+
end
|
51
|
+
|
52
|
+
def texts_for_tag(doc, tag)
|
53
|
+
doc.css(tag).map(&:text)
|
54
|
+
end
|
55
|
+
|
56
|
+
def filter_resources(app, pattern)
|
57
|
+
app.sitemap.resources.select { |resource| resource.url.match(pattern) }
|
58
|
+
end
|
59
|
+
|
60
|
+
def run_check(text, dictionary="en")
|
61
|
+
results = Spellchecker.check(text, dictionary)
|
62
|
+
results = exclude_allowed(results)
|
63
|
+
results.reject { |entry| entry[:correct] }
|
64
|
+
end
|
65
|
+
|
66
|
+
def exclude_allowed(results)
|
67
|
+
results.reject { |entry| option_allowed.include? entry[:original].downcase }
|
68
|
+
end
|
69
|
+
|
70
|
+
def option_allowed
|
71
|
+
allowed = if options.allow.is_a? Array
|
72
|
+
options.allow
|
73
|
+
else
|
74
|
+
[options.allow]
|
75
|
+
end
|
76
|
+
allowed.map(&:downcase)
|
77
|
+
end
|
78
|
+
|
79
|
+
def error_message(misspell)
|
80
|
+
"The word '#{misspell[:original]}' is misspelled"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Spellchecker
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'rexml/document'
|
5
|
+
|
6
|
+
ASPELL_WORD_DATA_REGEX = Regexp.new(/\&\s\w+\s\d+\s\d+(.*)$/)
|
7
|
+
|
8
|
+
@@aspell_path = "aspell"
|
9
|
+
|
10
|
+
def self.aspell_path=(path)
|
11
|
+
@@aspell_path = path
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.aspell_path
|
15
|
+
@@aspell_path
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.check(text, lang='en')
|
19
|
+
tmp = Tempfile.new('spellchecker-tmp')
|
20
|
+
tmp << text
|
21
|
+
tmp.flush
|
22
|
+
tmp.close
|
23
|
+
spell_check_response = `cat "#{tmp.path}" | #{@@aspell_path} -a -l #{lang}`
|
24
|
+
if spell_check_response == ''
|
25
|
+
raise 'Aspell command not found'
|
26
|
+
elsif text == ''
|
27
|
+
return []
|
28
|
+
else
|
29
|
+
response = text.split(' ').collect { |original| {:original => original} }
|
30
|
+
results = spell_check_response.split("\n").slice(1..-1)
|
31
|
+
result_index = 0
|
32
|
+
response.each_with_index do |word_hash, index|
|
33
|
+
if word_hash[:original] =~ /[a-zA-z\[\]\?]/
|
34
|
+
if results[result_index] =~ ASPELL_WORD_DATA_REGEX
|
35
|
+
response[index].merge!(:correct => false, :suggestions => results[result_index].split(':')[1].strip.split(',').map(&:strip))
|
36
|
+
else
|
37
|
+
response[index].merge!(:correct => true)
|
38
|
+
end
|
39
|
+
result_index += 1
|
40
|
+
else
|
41
|
+
response[index].merge!(:correct => true)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
return response
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "middleman-spellcheck"
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'middleman-spellcheck/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "middleman-spellcheck"
|
8
|
+
spec.version = Middleman::Spellcheck::VERSION
|
9
|
+
spec.authors = ["Ivan Zarea"]
|
10
|
+
spec.email = ["zarea.ion@gmail.com"]
|
11
|
+
spec.description = %q{Run spell checks as a build phase in middleman}
|
12
|
+
spec.summary = %q{Run spell checks as a build phase in middleman}
|
13
|
+
spec.homepage = "https://www.github.com/minivan/middleman-spellcheck"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "middleman-core", ["~> 3.2"]
|
22
|
+
spec.add_runtime_dependency "nokogiri"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-spellcheck
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.2'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Zarea
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Run spell checks as a build phase in middleman
|
70
|
+
email:
|
71
|
+
- zarea.ion@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- features/allowed.feature
|
82
|
+
- features/only_tags.feature
|
83
|
+
- features/page_params.feature
|
84
|
+
- features/plain_app.feature
|
85
|
+
- features/spelling_check.feature
|
86
|
+
- features/support/env.rb
|
87
|
+
- fixtures/allow_app/config.rb
|
88
|
+
- fixtures/allow_app/source/index.html.erb
|
89
|
+
- fixtures/correct_spelling_app/config.rb
|
90
|
+
- fixtures/correct_spelling_app/source/index.html.erb
|
91
|
+
- fixtures/incorrect_spelling_app/config.rb
|
92
|
+
- fixtures/incorrect_spelling_app/source/index.html.erb
|
93
|
+
- fixtures/only_tags_app/config.rb
|
94
|
+
- fixtures/only_tags_app/source/index.html.erb
|
95
|
+
- fixtures/plain_app/config.rb
|
96
|
+
- fixtures/plain_app/source/index.html.erb
|
97
|
+
- fixtures/spelling_path_app/config.rb
|
98
|
+
- fixtures/spelling_path_app/source/check/index.html
|
99
|
+
- fixtures/spelling_path_app/source/no_check/index.html
|
100
|
+
- lib/middleman-spellcheck.rb
|
101
|
+
- lib/middleman-spellcheck/extension.rb
|
102
|
+
- lib/middleman-spellcheck/spellchecker.rb
|
103
|
+
- lib/middleman-spellcheck/version.rb
|
104
|
+
- lib/middleman_extension.rb
|
105
|
+
- middleman-spellcheck.gemspec
|
106
|
+
homepage: https://www.github.com/minivan/middleman-spellcheck
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - '>='
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubyforge_project:
|
126
|
+
rubygems_version: 2.1.10
|
127
|
+
signing_key:
|
128
|
+
specification_version: 4
|
129
|
+
summary: Run spell checks as a build phase in middleman
|
130
|
+
test_files: []
|