middleman-spellcheck 0.3 → 0.4

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: 6aa4111fb86107b945fe10d5837d57a04420d148
4
- data.tar.gz: 77d631034f260e1d24936e197446e352f68566fc
3
+ metadata.gz: 8f20644e3c44323dd91dac085904b37ce7b6708d
4
+ data.tar.gz: 228fb426cf5b1d252192658ce2e930c40644def9
5
5
  SHA512:
6
- metadata.gz: 835e8c476a4988f9f609e7f20191761c645617ffcea5488db25f080f8d4be8c3e0acc9f9d51c219bf30bc632392257df51248f5a3add0694faf03dd4b8bc5896
7
- data.tar.gz: 5b70712eb2453f1a74109f4dd94516edf344c8d51ab11d3ea978f6078aededa02ddb90aedf26d3fd81093f3de3b492dd7744fab13833a0d9b945f88f81778b1e
6
+ metadata.gz: 7f3c2a98e49576566577d81a3baa6cee41f37e9850ec9832fbdd9b68701f5bb798e30bd10c0e9dda5d2302ce8fd3c551aaa13d52e3f127eb86c511dfa7393935
7
+ data.tar.gz: 3fa0f89b06c19be3d9a61bcd9a5d3d9d88e2096006f538a4c9506d5155c076d4df814fb94382222a92eeb789812a138bd36c1ea8c7ee3a6c40dc9ac4fa23aee0
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -66,7 +66,7 @@ module Middleman
66
66
  end
67
67
 
68
68
  def exclude_allowed(results)
69
- results.reject { |entry| option_allowed.include? entry[:original].downcase }
69
+ results.reject { |entry| option_allowed.include? entry[:word].downcase }
70
70
  end
71
71
 
72
72
  def option_allowed
@@ -79,7 +79,7 @@ module Middleman
79
79
  end
80
80
 
81
81
  def error_message(misspell)
82
- "The word '#{misspell[:original]}' is misspelled"
82
+ "The word '#{misspell[:word]}' is misspelled"
83
83
  end
84
84
  end
85
85
  end
@@ -1,10 +1,4 @@
1
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
2
  @@aspell_path = "aspell"
9
3
 
10
4
  def self.aspell_path=(path)
@@ -15,33 +9,22 @@ class Spellchecker
15
9
  @@aspell_path
16
10
  end
17
11
 
12
+ def self.query(text, lang='en')
13
+ result = `echo "#{text}" | #{@@aspell_path} -a -l #{lang}`
14
+ raise 'Aspell command not found' unless result
15
+ result.split("\n")[1..-1]
16
+ end
17
+
18
+ def self.correct?(result_string)
19
+ result_string == "*"
20
+ end
21
+
18
22
  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
23
+ words = text.split(/\W+/)
24
+ results = query(text, lang).map do |query_result|
25
+ correct?(query_result)
45
26
  end
27
+
28
+ words.zip(results).map {|word, correctness| { word: word, correct: correctness } }
46
29
  end
47
30
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Spellcheck
3
- VERSION = "0.3"
3
+ VERSION = "0.4"
4
4
  end
5
5
  end
@@ -0,0 +1,14 @@
1
+ require 'rspec'
2
+ require_relative '../../../lib/middleman-spellcheck/spellchecker'
3
+
4
+ describe Spellchecker do
5
+ let(:text) { "hello, world! of txet" }
6
+ let(:result) { Spellchecker.check(text) }
7
+
8
+ it "can spell check words" do
9
+ result.should == [{ word: "hello", correct: true },
10
+ { word: "world", correct: true },
11
+ { word: "of", correct: true },
12
+ { word: "txet", correct: false }]
13
+ end
14
+ 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.3'
4
+ version: '0.4'
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-01-27 00:00:00.000000000 Z
11
+ date: 2014-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: middleman-core
@@ -74,6 +74,7 @@ extensions: []
74
74
  extra_rdoc_files: []
75
75
  files:
76
76
  - .gitignore
77
+ - .rspec
77
78
  - Gemfile
78
79
  - LICENSE.txt
79
80
  - README.md
@@ -104,6 +105,7 @@ files:
104
105
  - lib/middleman-spellcheck/version.rb
105
106
  - lib/middleman_extension.rb
106
107
  - middleman-spellcheck.gemspec
108
+ - spec/lib/middleman-spellcheck/spellcheck_spec.rb
107
109
  homepage: https://www.github.com/minivan/middleman-spellcheck
108
110
  licenses:
109
111
  - MIT
@@ -128,4 +130,5 @@ rubygems_version: 2.1.10
128
130
  signing_key:
129
131
  specification_version: 4
130
132
  summary: Run spell checks as a build phase in middleman
131
- test_files: []
133
+ test_files:
134
+ - spec/lib/middleman-spellcheck/spellcheck_spec.rb