middleman-language_tool 0.0.1
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/.rspec +1 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +2 -0
- data/lib/middleman-language_tool.rb +7 -0
- data/lib/middleman-language_tool/extension.rb +96 -0
- data/lib/middleman-language_tool/version.rb +5 -0
- data/lib/middleman-spellcheck.rb +7 -0
- data/lib/middleman_extension.rb +1 -0
- data/middleman-language_tool.gemspec +27 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 65347858f176ae1672776a9266ff2a6d394566ad
|
4
|
+
data.tar.gz: 3009bb0648d39777f35729f3abacb2b241438ce4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 304f434de828483ef626a104308b93bf1fce56acc483d7992a4c7c787ff3f88df8a85f6d0b59a77f86073a55a0e961633db2e24e44e9912b0a25984a96694f9d
|
7
|
+
data.tar.gz: d6f69026a5c4de35b9ca953ef0e7ef06aeb356dd3a8602e3f705cc4fe2d461d707be55fa04d38179dd751056ff1a17afc7034a7e07e4da122be615f07e362fdb
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
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,49 @@
|
|
1
|
+
# Middleman-LanguageTooler
|
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
|
46
|
+
|
47
|
+
## Thanks
|
48
|
+
|
49
|
+
Special thanks to [Readbeard-Tech](https://rubygems.org/profiles/redbeard-tech) for the [spellchecker](https://rubygems.org/gems/spellchecker) gem, which this code is based upon.
|
data/Rakefile
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'language_tool'
|
3
|
+
|
4
|
+
module Middleman
|
5
|
+
module LanguageTool
|
6
|
+
class LanguageToolExtension < Extension
|
7
|
+
REJECTED_EXTS = %w(.css .js .coffee)
|
8
|
+
option :page, "/*", "Run only pages that match the regex through the spellchecker"
|
9
|
+
option :tags, [], "Run spellcheck only on some tags from the output"
|
10
|
+
option :allow, [], "Allow specific words to be misspelled"
|
11
|
+
|
12
|
+
def after_build(builder)
|
13
|
+
language_tool = ::LanguageTool::Process.new
|
14
|
+
language_tool.start!
|
15
|
+
spellchecker = ::LanguageTool::ErrorParser.new(language_tool)
|
16
|
+
|
17
|
+
filtered = filter_resources(app, options.page)
|
18
|
+
total_misspelled = []
|
19
|
+
|
20
|
+
filtered.each do |resource|
|
21
|
+
builder.say_status :spellcheck, "Running spell checker for #{resource.url}", :blue
|
22
|
+
current_misspelled = run_check(spellchecker, select_content(resource))
|
23
|
+
current_misspelled.each do |misspell|
|
24
|
+
builder.say_status :misspell, error_message(misspell), :red
|
25
|
+
end
|
26
|
+
total_misspelled += current_misspelled
|
27
|
+
end
|
28
|
+
|
29
|
+
unless total_misspelled.empty?
|
30
|
+
raise Thor::Error, "Build failed. There are spelling errors."
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def select_content(resource)
|
35
|
+
rendered_resource = resource.render(layout: false)
|
36
|
+
doc = Nokogiri::HTML(rendered_resource)
|
37
|
+
|
38
|
+
if options.tags.empty?
|
39
|
+
doc.text
|
40
|
+
else
|
41
|
+
select_tagged_content(doc, option_tags)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def option_tags
|
46
|
+
if options.tags.is_a? Array
|
47
|
+
options.tags
|
48
|
+
else
|
49
|
+
[options.tags]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def select_tagged_content(doc, tags)
|
54
|
+
tags.map { |tag| texts_for_tag(doc, tag.to_s) }.flatten.join(' ')
|
55
|
+
end
|
56
|
+
|
57
|
+
def texts_for_tag(doc, tag)
|
58
|
+
doc.css(tag).map(&:text)
|
59
|
+
end
|
60
|
+
|
61
|
+
def filter_resources(app, pattern)
|
62
|
+
app.sitemap.resources.select { |resource| resource.url.match(pattern) }
|
63
|
+
.reject { |resource| REJECTED_EXTS.include? resource.ext }
|
64
|
+
end
|
65
|
+
|
66
|
+
def run_check(spellchecker, text)
|
67
|
+
errors = spellchecker.find_errors(text)
|
68
|
+
errors.reject { |e| e.ruleId == "WHITESPACE_RULE" }
|
69
|
+
#results = exclude_allowed(results)
|
70
|
+
#results.reject { |entry| entry[:correct] }
|
71
|
+
end
|
72
|
+
|
73
|
+
def exclude_allowed(results)
|
74
|
+
results.reject { |entry| option_allowed.include? entry[:word].downcase }
|
75
|
+
end
|
76
|
+
|
77
|
+
def option_allowed
|
78
|
+
allowed = if options.allow.is_a? Array
|
79
|
+
options.allow
|
80
|
+
else
|
81
|
+
[options.allow]
|
82
|
+
end
|
83
|
+
allowed.map(&:downcase)
|
84
|
+
end
|
85
|
+
|
86
|
+
def error_message(misspell)
|
87
|
+
"Category: #{misspell.category}\n" \
|
88
|
+
"Message: #{misspell.msg}\n" \
|
89
|
+
"Context: #{misspell.context}\n" \
|
90
|
+
"Replacements: #{misspell.replacements.split('#').join(' ')}\n" \
|
91
|
+
|
92
|
+
#"The word '#{misspell[:word]}' is misspelled"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "middleman-spellcheck"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'middleman-language_tool/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "middleman-language_tool"
|
8
|
+
spec.version = Middleman::LanguageTool::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/skade/middleman-language_tool"
|
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
|
+
spec.add_runtime_dependency "language_tool"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
26
|
+
spec.add_development_dependency "rake"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-language_tool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ivan Zarea
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-02 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: language_tool
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Run spell checks as a build phase in middleman
|
84
|
+
email:
|
85
|
+
- zarea.ion@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/middleman-language_tool.rb
|
97
|
+
- lib/middleman-language_tool/extension.rb
|
98
|
+
- lib/middleman-language_tool/version.rb
|
99
|
+
- lib/middleman-spellcheck.rb
|
100
|
+
- lib/middleman_extension.rb
|
101
|
+
- middleman-language_tool.gemspec
|
102
|
+
homepage: https://www.github.com/skade/middleman-language_tool
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.2.0
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Run spell checks as a build phase in middleman
|
126
|
+
test_files: []
|