diff options
author | Alex Legler <a3li@gentoo.org> | 2011-10-24 00:23:39 +0200 |
---|---|---|
committer | Alex Legler <a3li@gentoo.org> | 2011-10-24 00:23:39 +0200 |
commit | e88a8a4e30cbb017a39a47f1dd87be86117c3e7a (patch) | |
tree | 119e7cc7676ee663d020830401e26b16069f04a1 /lib | |
parent | Merge branch 'master' of git+ssh://git.overlays.gentoo.org/proj/glsamaker (diff) | |
download | glsamaker-e88a8a4e30cbb017a39a47f1dd87be86117c3e7a.tar.gz glsamaker-e88a8a4e30cbb017a39a47f1dd87be86117c3e7a.tar.bz2 glsamaker-e88a8a4e30cbb017a39a47f1dd87be86117c3e7a.zip |
Add spell-checking using runspell/hunspell.
For now, we're bundling english dictionaries with modifications for our needs.
When there is a better non-ffi API for ruby available, we can switch to multiple dictionaries and split our changes
Diffstat (limited to 'lib')
-rw-r--r-- | lib/glsamaker.rb | 1 | ||||
-rw-r--r-- | lib/glsamaker/spelling.rb | 48 |
2 files changed, 49 insertions, 0 deletions
diff --git a/lib/glsamaker.rb b/lib/glsamaker.rb index d55bc81..6f4cb61 100644 --- a/lib/glsamaker.rb +++ b/lib/glsamaker.rb @@ -15,4 +15,5 @@ require 'glsamaker/diff' require 'glsamaker/xml' require 'glsamaker/bugs' require 'glsamaker/mail' +require 'glsamaker/spelling' # require 'glsamaker/helpers' DO NOT REQUIRE or else the rake tasks will blow up diff --git a/lib/glsamaker/spelling.rb b/lib/glsamaker/spelling.rb new file mode 100644 index 0000000..0d06310 --- /dev/null +++ b/lib/glsamaker/spelling.rb @@ -0,0 +1,48 @@ +# ===GLSAMaker v2 +# Copyright (C) 2009-2011 Alex Legler <a3li@gentoo.org> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# For more information, see the LICENSE file. + +module Glsamaker + class Spelling + class << self + def init + dic = File.join(Rails.root, 'vendor', 'dictionaries', 'en_US.dic') + aff = File.join(Rails.root, 'vendor', 'dictionaries', 'en_US.aff') + + @runspell = Runspell.new(aff, dic) + end + + def check(word) + init if @runspell.nil? + @runspell.check(word) + end + + def suggest(word) + init if @runspell.nil? + @runspell.suggest(word) + end + + # Checks a string for spelling, <tt>before_marker</tt> and <tt>after_maker</tt> are put around the misspelled words + def check_string(string, before_marker, after_marker) + result = [] + string.split(/\b/).each do |word| + if word =~ /^[\s,.-:(){}\[\]<>]*$/ + result << word + elsif check(word) + result << word + else + result << before_marker.html_safe + word + after_marker.html_safe + end + end + + result.join + end + end + end +end
\ No newline at end of file |