dpickett-tiny_rack_spellchecker 0.1.3

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Dan Pickett
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = tiny_rack_spellchecker
2
+
3
+ A Rack Application that processes tinyMCE spell check requests
4
+
5
+ Point tinyMCE to this application like so:
6
+ <pre>
7
+ tinyMCE.init({
8
+ "plugins" : "spellchecker",
9
+ "theme_advanced_buttons3_add" : "spellchecker",
10
+ "spellchecker_languages" : "+English=en",
11
+ "spellchecker_rpc_url" : "/spell_checker",
12
+ "theme_advanced_buttons1_add" : "spellchecker",
13
+ });
14
+ </pre>
15
+ == Copyright
16
+
17
+ Copyright (c) 2009 Dan Pickett. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tiny_rack_spellchecker"
8
+ gem.summary = %Q{A Rack Application that processes tinyMCE spell check requests}
9
+ gem.email = "dpickett@enlightsolutions.com"
10
+ gem.homepage = "http://github.com/dpickett/tiny_rack_spellchecker"
11
+ gem.authors = ["Dan Pickett"]
12
+ gem.add_dependency("raspell", ">= 1.1")
13
+ gem.add_dependency("json", ">= 1.1.4")
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/*_test.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'cucumber'
30
+ require 'cucumber/rake/task'
31
+
32
+ Cucumber::Rake::Task.new(:features) do |t|
33
+ t.cucumber_opts = "features --format pretty" # Any valid command line option can go here.
34
+ end
35
+
36
+ rescue LoadError
37
+ puts "Cucumber not installed. You will not be able to run features"
38
+ end
39
+
40
+ begin
41
+ require 'rcov/rcovtask'
42
+ Rcov::RcovTask.new do |test|
43
+ test.libs << 'test'
44
+ test.pattern = 'test/**/*_test.rb'
45
+ test.verbose = true
46
+ end
47
+ rescue LoadError
48
+ task :rcov do
49
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
50
+ end
51
+ end
52
+
53
+
54
+ task :default => :test
55
+
56
+ require 'rake/rdoctask'
57
+ Rake::RDocTask.new do |rdoc|
58
+ if File.exist?('VERSION.yml')
59
+ config = YAML.load(File.read('VERSION.yml'))
60
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
61
+ else
62
+ version = ""
63
+ end
64
+
65
+ rdoc.rdoc_dir = 'rdoc'
66
+ rdoc.title = "tiny_rack_spellchecker #{version}"
67
+ rdoc.rdoc_files.include('README*')
68
+ rdoc.rdoc_files.include('lib/**/*.rb')
69
+ end
70
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.4
@@ -0,0 +1,16 @@
1
+ Feature: Spell Checking
2
+ In order to provide quality content and a richer experience for users of TinyMCE
3
+ They should be able to perform spell checking on their content
4
+
5
+ Scenario: I perform spell checking with a mispelled word
6
+ Given I have supplied the content 'Sally sells shesells down by the seashore'
7
+ When I do a spellcheck
8
+ Then I should get a response
9
+ And there should be 1 error
10
+
11
+ Scenario: I perform spell checking with perfect spelling
12
+ Given I have supplied the content 'Sally sells seashells down by the seashore'
13
+ When I do a spellcheck
14
+ Then I should get a response
15
+ And there should be 0 errors
16
+
@@ -0,0 +1,21 @@
1
+ Given /^I have supplied the content '(.*)'$/ do |content|
2
+ @params ||= {}
3
+ @params["params"] ||= ["en"]
4
+ @params["method"] = "checkWords"
5
+ @params["params"] << content.split(" ")
6
+ end
7
+
8
+
9
+ When /^I do a spellcheck$/ do
10
+ post '/spell_checker', @params.to_json
11
+ end
12
+
13
+ Then /^I should get a response$/ do
14
+ assert last_response.ok?
15
+ end
16
+
17
+ Then /^there should be (\d*) errors?$/ do |error_count|
18
+ json_hash = JSON.parse(last_response.body)
19
+ assert_equal error_count.to_i, json_hash["result"].size
20
+ end
21
+
@@ -0,0 +1,26 @@
1
+ Given /^I have entered the word '(.*)'$/ do |word|
2
+ @params = {}
3
+ @params["params"] = ["en"]
4
+ @params["params"] << word
5
+ @params["id"] = "c0"
6
+ end
7
+
8
+ When /^I request possible replacements$/ do
9
+ @params["method"] = "getSuggestions"
10
+ post "/spell_checker", @params.to_json
11
+ @json_hash = JSON.parse(last_response.body)
12
+ @result = @json_hash["result"]
13
+ end
14
+
15
+ Then /^I should get an array of results$/ do
16
+ assert_instance_of Array, @result
17
+ end
18
+
19
+ Then /^I should see '(.*)' as a replacement option$/ do |word|
20
+ assert @result.include?(word)
21
+ end
22
+
23
+ Then /^I should get a position identifier so I can perform a valid replacement$/ do
24
+ assert_equal @params["id"], @json_hash["id"]
25
+ end
26
+
@@ -0,0 +1,20 @@
1
+ Feature: Mispelled Replacement Suggestion
2
+ In order to provide quality content
3
+ and a richer experience for users of the TinyMCE editor
4
+ They should be able to get a list of suggested replacements for
5
+ a misspelled word
6
+
7
+ Scenario: I request replacement suggestions for a mispelled word
8
+ Given I have entered the word 'shesells'
9
+ When I request possible replacements
10
+ Then I should get a response
11
+ And I should get an array of results
12
+ And I should see 'seashells' as a replacement option
13
+ And I should get a position identifier so I can perform a valid replacement
14
+
15
+ Scenario: I request replacement suggestions for a properly spelled word
16
+ Given I have entered the word 'seashells'
17
+ When I request possible replacements
18
+ Then I should get a response
19
+ And I should get an array of results
20
+
@@ -0,0 +1,17 @@
1
+ require "test/unit/assertions"
2
+
3
+ require "tiny_rack_spellchecker"
4
+ require "rack/test"
5
+
6
+ module TinyRackSpellchecker
7
+ module WorldOfCucumber
8
+ def app
9
+ TinyRackSpellchecker::RackApplication.new
10
+ end
11
+
12
+ include Test::Unit::Assertions
13
+ include Rack::Test::Methods
14
+ end
15
+ end
16
+
17
+ World(TinyRackSpellchecker::WorldOfCucumber)
@@ -0,0 +1,6 @@
1
+ require "raspell"
2
+ require "json"
3
+
4
+ require "tiny_rack_spellchecker/rack_application"
5
+ require "tiny_rack_spellchecker/request_controller"
6
+
@@ -0,0 +1,18 @@
1
+ module TinyRackSpellchecker
2
+ class RackApplication
3
+ def initialize(app = nil, message = "")
4
+ @app = app
5
+ @message = message
6
+ end
7
+
8
+ def call(env)
9
+ if env["PATH_INFO"] =~ /^\/spell_checker/
10
+ req = JSON.parse(env["rack.input"].read)
11
+ results = RequestController.handle(req)
12
+ [200, {"Content-Type" => "text/javascript"}, [results.to_json]]
13
+ else
14
+ @app.call(env) unless app.nil?
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,40 @@
1
+ module TinyRackSpellchecker
2
+ class RequestController
3
+ class << self
4
+ def handle(req)
5
+ if req["method"] == "getSuggestions"
6
+ suggest_alternatives_for(req["params"][1], req["id"])
7
+ else
8
+ check(req["params"][1])
9
+ end
10
+ end
11
+
12
+ def check(content)
13
+ speller = Aspell.new("en_US")
14
+ bad_words = []
15
+ content.each do |word|
16
+ unless speller.check(word)
17
+ bad_words << word
18
+ end
19
+ end
20
+
21
+ {
22
+ "id" => nil,
23
+ "error" => nil,
24
+ "result" => bad_words.uniq
25
+ }
26
+ end
27
+
28
+ def suggest_alternatives_for(word, position_id)
29
+ speller = Aspell.new("en_US")
30
+ {
31
+ "id" => position_id,
32
+ "error" => nil,
33
+ "result" => speller.suggest(word)[0..8]
34
+ }
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'tiny_rack_spellchecker'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class TinyRackSpellcheckerTest < Test::Unit::TestCase
4
+ should "run cucumber features" do
5
+ flunk "all the good stuff is in the cucumber features - it's a rack app!"
6
+ end
7
+ end
@@ -0,0 +1,60 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{tiny_rack_spellchecker}
5
+ s.version = "0.1.3"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Dan Pickett"]
9
+ s.date = %q{2009-05-16}
10
+ s.email = %q{dpickett@enlightsolutions.com}
11
+ s.extra_rdoc_files = [
12
+ "LICENSE",
13
+ "README.rdoc"
14
+ ]
15
+ s.files = [
16
+ ".document",
17
+ ".gitignore",
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "Rakefile",
21
+ "VERSION",
22
+ "features/spell_checking.feature",
23
+ "features/step_definitions/spell_checking_steps.rb",
24
+ "features/step_definitions/suggest_replacement_steps.rb",
25
+ "features/suggest_replacements.feature",
26
+ "features/support/env.rb",
27
+ "lib/tiny_rack_spellchecker.rb",
28
+ "lib/tiny_rack_spellchecker/rack_application.rb",
29
+ "lib/tiny_rack_spellchecker/request_controller.rb",
30
+ "test/test_helper.rb",
31
+ "test/tiny_rack_spellchecker_test.rb",
32
+ "tiny_rack_spellchecker.gemspec"
33
+ ]
34
+ s.has_rdoc = true
35
+ s.homepage = %q{http://github.com/dpickett/tiny_rack_spellchecker}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.2}
39
+ s.summary = %q{A Rack Application that processes tinyMCE spell check requests}
40
+ s.test_files = [
41
+ "test/test_helper.rb",
42
+ "test/tiny_rack_spellchecker_test.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ s.add_runtime_dependency(%q<raspell>, [">= 1.1"])
51
+ s.add_runtime_dependency(%q<json>, [">= 1.1.4"])
52
+ else
53
+ s.add_dependency(%q<raspell>, [">= 1.1"])
54
+ s.add_dependency(%q<json>, [">= 1.1.4"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<raspell>, [">= 1.1"])
58
+ s.add_dependency(%q<json>, [">= 1.1.4"])
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dpickett-tiny_rack_spellchecker
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Dan Pickett
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: raspell
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "1.1"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.4
34
+ version:
35
+ description:
36
+ email: dpickett@enlightsolutions.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.rdoc
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.rdoc
49
+ - Rakefile
50
+ - VERSION
51
+ - features/spell_checking.feature
52
+ - features/step_definitions/spell_checking_steps.rb
53
+ - features/step_definitions/suggest_replacement_steps.rb
54
+ - features/suggest_replacements.feature
55
+ - features/support/env.rb
56
+ - lib/tiny_rack_spellchecker.rb
57
+ - lib/tiny_rack_spellchecker/rack_application.rb
58
+ - lib/tiny_rack_spellchecker/request_controller.rb
59
+ - test/test_helper.rb
60
+ - test/tiny_rack_spellchecker_test.rb
61
+ - tiny_rack_spellchecker.gemspec
62
+ has_rdoc: true
63
+ homepage: http://github.com/dpickett/tiny_rack_spellchecker
64
+ post_install_message:
65
+ rdoc_options:
66
+ - --charset=UTF-8
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: "0"
74
+ version:
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ requirements: []
82
+
83
+ rubyforge_project:
84
+ rubygems_version: 1.2.0
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: A Rack Application that processes tinyMCE spell check requests
88
+ test_files:
89
+ - test/test_helper.rb
90
+ - test/tiny_rack_spellchecker_test.rb