middleman-spellcheck 0.7.5 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc78078d67f2333e29a7b05751aa5bbf08d313d2
4
- data.tar.gz: cfd3822f1fccf0007a1336f94b4befe3c48cf794
3
+ metadata.gz: 8608b5d6fd9049afe93af7ef3f005566bb10e537
4
+ data.tar.gz: 00b148f8992c92b178992c485bea7a4275b80ea8
5
5
  SHA512:
6
- metadata.gz: 4d9077b0513f76faffc0d14f8a43548b86b53732520d457d6c60096307b4e317f2299ccdce3625e7dd7db3567e15e9765acf54b79af030338d8d2e9d0e9680ce
7
- data.tar.gz: 38d36abde02d9af11b31d6ad9e1fe62226be035e00097dde0ad57f5babba28a9922a88e351045e95bca54fcc552431f2e1417ac00b5d87346ae2984f1e1a829e
6
+ metadata.gz: d86956a715506d4924060b035a3c8edd1f595b154d54b7a6e40ac4ebbb39b72f23a40d31939246e2a561d0f90a05e358975ce929ac0eec14a9c6bd1f8ab21701
7
+ data.tar.gz: 376ba57130d2b77c563a2ee040adc564012e790ba964451d832d9ebe627e762bfcb0af4538da72bd70eff1496dcdb92e770302020e3dc36ee7e3dacf417225d0
data/README.md CHANGED
@@ -44,6 +44,39 @@ like to skip:
44
44
  activate :spellcheck, ignored_exts: [".xml", ".png"]
45
45
  ```
46
46
 
47
+ To select a dictionary used by a spellchecker, use lang: option. For
48
+ example, to use Polish dictionary, use:
49
+
50
+ ```ruby
51
+ activate :spellcheck, lang: "pl"
52
+ ```
53
+
54
+ Middleman-spellcheck can issue many warnings if you run it over a new
55
+ content. If you want to give yourself a chance to fix mistakes gradually and
56
+ not fail each time you build, use :dontfail flag:
57
+
58
+ ```ruby
59
+ activate :spellcheck, lang: en, dontfail: 1
60
+ ```
61
+
62
+ Advanced users wishing to invoke Middleman-spellcheck backend (Aspell) with
63
+ a custom command line may find cmdargs: useful. Please note that "-a" is a
64
+ mandatory flag which one must specify in order for middleman-spellcheck to
65
+ work. Other flags are up to the user. See Aspell's man page for more
66
+ details.
67
+
68
+ ```ruby
69
+ activate :spellcheck, cmdargs: "-a -l pl"
70
+ ```
71
+
72
+ For developers interested in extending Middleman-spellcheck and for those
73
+ who encountered issues, useful might be debug: option, which will turn on
74
+ extensive amount of debugging.
75
+
76
+ ```ruby
77
+ activate :spellcheck, debug: 1
78
+ ```
79
+
47
80
  ## Contributing
48
81
 
49
82
  1. Fork it
@@ -9,14 +9,20 @@ module Middleman
9
9
  option :tags, [], "Run spellcheck only on some tags from the output"
10
10
  option :allow, [], "Allow specific words to be misspelled"
11
11
  option :ignored_exts, [], "Ignore specific extensions (ex: '.xml')"
12
+ option :lang, "en", "Language for spellchecking"
13
+ option :cmdargs, "", "Pass alternative command line arguments"
14
+ option :debug, 0, "Enable debugging (for developers only)"
15
+ option :dontfail, 0, "Don't fail when misspelled words are found"
12
16
 
13
17
  def after_build(builder)
18
+ Spellchecker.cmdargs=(options.cmdargs)
19
+ Spellchecker.debug_enabled=(options.debug)
14
20
  filtered = filter_resources(app, options.page)
15
21
  total_misspelled = []
16
22
 
17
23
  filtered.each do |resource|
18
24
  builder.say_status :spellcheck, "Running spell checker for #{resource.url}", :blue
19
- current_misspelled = run_check(select_content(resource))
25
+ current_misspelled = run_check(select_content(resource), options.lang)
20
26
  current_misspelled.each do |misspell|
21
27
  builder.say_status :misspell, error_message(misspell), :red
22
28
  end
@@ -24,7 +30,13 @@ module Middleman
24
30
  end
25
31
 
26
32
  unless total_misspelled.empty?
27
- raise Thor::Error, "Build failed. There are spelling errors."
33
+ estr = "Build failed. There are spelling errors."
34
+ if options.dontfail
35
+ print "== :dontfail set! Will issue warning only, but not fail.\n"
36
+ print estr, "\n"
37
+ else
38
+ raise Thor::Error, estr
39
+ end
28
40
  end
29
41
  end
30
42
 
@@ -60,8 +72,8 @@ module Middleman
60
72
  .reject { |resource| option_ignored_exts.include? resource.ext }
61
73
  end
62
74
 
63
- def run_check(text, dictionary="en")
64
- results = Spellchecker.check(text, dictionary)
75
+ def run_check(text, lang)
76
+ results = Spellchecker.check(text, lang)
65
77
  results = exclude_allowed(results)
66
78
  results.reject { |entry| entry[:correct] }
67
79
  end
@@ -1,5 +1,7 @@
1
1
  class Spellchecker
2
2
  @@aspell_path = "aspell"
3
+ @@aspell_cmdargs = ""
4
+ @@debug_enabled = 0
3
5
 
4
6
  def self.aspell_path=(path)
5
7
  @@aspell_path = path
@@ -9,28 +11,79 @@ class Spellchecker
9
11
  @@aspell_path
10
12
  end
11
13
 
12
- def self.query(text, lang='en')
13
- result = `echo "#{text}" | #{@@aspell_path} -a -l #{lang}`
14
+ def self.cmdargs=(args)
15
+ @@aspell_cmdargs = args
16
+ end
17
+
18
+ def self.cmdargs
19
+ @@aspell_cmdargs
20
+ end
21
+
22
+ def self.debug_enabled=(args)
23
+ @@debug_enabled = args
24
+ end
25
+
26
+ def self.debug_enabled
27
+ @@debug_enabled
28
+ end
29
+
30
+ def self.sdbg(*args)
31
+ if @@debug_enabled <= 0
32
+ return
33
+ end
34
+ print "# DBG ", *args, "\n"
35
+ end
36
+
37
+ def self.query(words, lang)
38
+ args = "-a -l #{lang}"
39
+ if @@aspell_cmdargs != ""
40
+ args = @@aspell_cmdargs
41
+ end
42
+ cmd = %Q<#{@@aspell_path} #{args}>
43
+ result = []
44
+
45
+ sdbg "Starting aspell"
46
+ IO.popen(cmd, "a+", :err=>[:child, :out]) { |f|
47
+ val = f.gets.strip() # skip the Aspell's intro
48
+ sdbg "Expected Aspell intro, got #{val}"
49
+ words.each do |word|
50
+ sdbg "-> Writing word '#{word}'"
51
+ f.write(word + "\n")
52
+ f.flush
53
+
54
+ # should be * or &
55
+ word_check_res = f.gets.strip()
56
+ sdbg "<- got result '#{word_check_res}'"
57
+
58
+ # skip the empty line
59
+ val = f.gets()
60
+ sdbg "Expected empty line, got '#{val}'"
61
+
62
+ result << word_check_res
63
+ end
64
+ }
14
65
  raise 'Aspell command not found' unless result
15
- new_result = result.split("\n")
16
- new_result[1..-1] || []
66
+ result || []
17
67
  end
18
68
 
19
69
  def self.correct?(result_string)
20
70
  result_string == "*"
21
71
  end
22
72
 
23
- def self.check(text, lang='en')
24
- # join then re-split the word list to get a consistent word count,
25
- # because sometimes there's a "" (blank) word in the array that gets lost,
26
- # which makes the maps not equal, leading to an off by one type issue, where
27
- # the reported mispelled word is actually a correct word.
28
- # see: https://github.com/minivan/middleman-spellcheck/issues/7
29
- words = text.split(/[^A-Za-z’']+/).join(" ")
73
+ def self.check(text, lang)
74
+ # do -> ' for aspell. Otherwise 's' is passed as a word to aspell.
75
+ text.gsub! '’', '\''
76
+ sdbg "self.check got raw text:\n#{text}\n"
77
+
78
+ words = text.split(/[^A-Za-z']+/).select { |s|
79
+ s != "" and s != "'s" and s != "'"
80
+ }
81
+ sdbg "self.check word array:\n#{words}\n"
82
+
30
83
  results = query(words, lang).map do |query_result|
31
84
  correct?(query_result)
32
85
  end
33
86
 
34
- words.split(" ").zip(results).map {|word, correctness| { word: word, correct: correctness } }
87
+ words.zip(results).map {|word, correctness| { word: word, correct: correctness } }
35
88
  end
36
89
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Spellcheck
3
- VERSION = "0.7.5"
3
+ VERSION = "0.8.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-spellcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Zarea
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-25 00:00:00.000000000 Z
11
+ date: 2015-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core