Created
March 5, 2012 13:26
-
-
Save smileart/1978294 to your computer and use it in GitHub Desktop.
Spell check plugin for earthquake.gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: UTF-8 | |
# Spell check plugin for earthquake.gem | |
# | |
# written by Smile @rT, https://github.com/smileart, [email protected] | |
# | |
# INSTALL: | |
# | |
# 1. Resolve dependencies of raspell.gem: | |
# https://github.com/evan/raspell/blob/master/README.rdoc | |
# | |
# 2. Install raspell.gem: | |
# OS X: gem install raspell -- --with-opt-dir=/opt/local | |
# Ubuntu: gem install raspell | |
# | |
# ===================== IF YOU ARE USE NON RUSSIAN DICT ==================== | |
# | |
# 2.1 Install your native language dictionary: | |
# OS X: sudo port install aspell-dict-en | |
# Ubuntu: sudo apt-get install aspell-en | |
# | |
# 2.2 Set language code as @lang variable and alphabet pattern as @patern: | |
# @lang = 'en' | |
# @pattern = /[A-Za-z]+/i | |
# | |
# ================================== END =================================== | |
# | |
# 3. Put this file to ~/.earthquake/plugin/ | |
# | |
# 4. PROFIT!!!111 > :update(<reply>) Текст с ашипкой ⏎ | |
require 'raspell' | |
Earthquake.init do | |
# Set your native language code HERE! | |
# @lang = 'en' | |
@lang = 'ru' | |
# Set your alphabet pattern HERE! | |
# for eng: | |
# @pattern = /[A-Za-z]+/i | |
# or | |
# @pattern = /[\w]+/i | |
@pattern = /[А-Яа-я]+/i | |
input_filter do |text| | |
if text =~ /^:(update|reply)/ | |
@had_mistake = false | |
speller = Aspell.new(@lang) | |
speller.suggestion_mode = Aspell::NORMAL | |
misspelled = text.gsub(@pattern) {|word| | |
if !speller.check(word) | |
@had_mistake = true | |
word.c(31) | |
else | |
word | |
end | |
} | |
puts "\nMisspelled text: ".c(31) + misspelled + "\n\n" if @had_mistake | |
text | |
else | |
text | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment