|
From: <hma...@us...> - 2010-01-28 18:56:59
|
Revision: 2083
http://ndlb.svn.sourceforge.net/ndlb/?rev=2083&view=rev
Author: hmazariegos
Date: 2010-01-28 18:56:52 +0000 (Thu, 28 Jan 2010)
Log Message:
-----------
Added spelling to lib, added spellchecker methods, added spellchecker to administrative units.
Modified Paths:
--------------
portal/ror/plugins/mms_engine/trunk/app/controllers/application_controller.rb
portal/ror/plugins/mms_engine/trunk/app/views/administrative_units/_edit.html.erb
portal/ror/plugins/mms_engine/trunk/app/views/administrative_units/_new.html.erb
Added Paths:
-----------
portal/ror/plugins/mms_engine/trunk/lib/spelling.rb
Modified: portal/ror/plugins/mms_engine/trunk/app/controllers/application_controller.rb
===================================================================
--- portal/ror/plugins/mms_engine/trunk/app/controllers/application_controller.rb 2010-01-28 18:41:55 UTC (rev 2082)
+++ portal/ror/plugins/mms_engine/trunk/app/controllers/application_controller.rb 2010-01-28 18:56:52 UTC (rev 2083)
@@ -3,7 +3,19 @@
#require_dependency 'login_system'
class ApplicationController < ActionController::Base
+ include Spelling
+
# See ActionController::RequestForgeryProtection for details
# Uncomment the :secret if you're not using the cookie session store
- protect_from_forgery # :secret => '051292610481c0699540df094adf0f36'
+ protect_from_forgery # :secret => '051292610481c0699540df094adf0f36'
+
+ def spellchecker
+ language, words, method = params[:params][0], params[:params][1], params[:method] unless params[:params].blank?
+ return render :nothing => true if language.blank? || words.blank? || method.blank?
+ headers["Content-Type"] = "text/plain"
+ headers["charset"] = "utf-8"
+ suggestions = check_spelling(words, method, language)
+ results = {"id" => nil, "result" => suggestions, "error" => nil}
+ render :json => results
+ end
end
\ No newline at end of file
Modified: portal/ror/plugins/mms_engine/trunk/app/views/administrative_units/_edit.html.erb
===================================================================
--- portal/ror/plugins/mms_engine/trunk/app/views/administrative_units/_edit.html.erb 2010-01-28 18:41:55 UTC (rev 2082)
+++ portal/ror/plugins/mms_engine/trunk/app/views/administrative_units/_edit.html.erb 2010-01-28 18:56:52 UTC (rev 2083)
@@ -5,7 +5,7 @@
height : '270px',
mode : 'textareas',
noneditable_leave_contenteditable : 'true',
-plugins : "example, contextmenu,paste,media,fullscreen,template,noneditable,code, table",
+plugins : "contextmenu,paste,media,fullscreen,template,noneditable, table, spellchecker",
template_external_list_url : '/templates/templates.js',
content_css : '/stylesheets/customtinymce.css',
theme : 'advanced',
@@ -13,7 +13,9 @@
theme_advanced_buttons1 : " fullscreen,separator,bold,italic,underline,strikethrough,separator,undo,redo,separator,link,unlink,template,formatselect, code",
theme_advanced_buttons2 : "cut,copy,paste,separator,pastetext,pasteword,separator,bullist,numlist,outdent,indent,separator,justifyleft,justifycenter,justifyright,justifiyfull,separator,removeformat,charmap",
theme_advanced_buttons3 : "EventButton,HimalayanButton,MapButton,OrgButton,PersonButton,PlaceButton, ProjectButton,RefButton,TibetanButton,TibTextButton, TopicButton ",
-theme_advanced_buttons4 : "tablecontrols",
+theme_advanced_buttons4 : "spellchecker,tablecontrols ",
+spellchecker_languages : "+English=en",
+spellchecker_rpc_url : '/application/spellchecker',
table_styles : "Header 1=header1;Header 2=header2;Header 3=header3",
table_cell_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1",
table_row_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1",
@@ -151,6 +153,7 @@
});
//]]>
</script>
+
<h1><%= ts 'edit.ing.record', :what => h(@element.level_name) %></h1>
<%= error_messages_for :element %>
<% if base_language? %>
Modified: portal/ror/plugins/mms_engine/trunk/app/views/administrative_units/_new.html.erb
===================================================================
--- portal/ror/plugins/mms_engine/trunk/app/views/administrative_units/_new.html.erb 2010-01-28 18:41:55 UTC (rev 2082)
+++ portal/ror/plugins/mms_engine/trunk/app/views/administrative_units/_new.html.erb 2010-01-28 18:56:52 UTC (rev 2083)
@@ -5,7 +5,7 @@
height : '270px',
mode : 'textareas',
noneditable_leave_contenteditable : 'true',
-plugins : "example, contextmenu,paste,media,fullscreen,template,noneditable,code, table",
+plugins : "contextmenu,paste,media,fullscreen,template,noneditable, table, spellchecker",
template_external_list_url : '/templates/templates.js',
content_css : '/stylesheets/customtinymce.css',
theme : 'advanced',
@@ -13,7 +13,9 @@
theme_advanced_buttons1 : " fullscreen,separator,bold,italic,underline,strikethrough,separator,undo,redo,separator,link,unlink,template,formatselect, code",
theme_advanced_buttons2 : "cut,copy,paste,separator,pastetext,pasteword,separator,bullist,numlist,outdent,indent,separator,justifyleft,justifycenter,justifyright,justifiyfull,separator,removeformat,charmap",
theme_advanced_buttons3 : "EventButton,HimalayanButton,MapButton,OrgButton,PersonButton,PlaceButton, ProjectButton,RefButton,TibetanButton,TibTextButton, TopicButton ",
-theme_advanced_buttons4 : "tablecontrols",
+theme_advanced_buttons4 : "spellchecker,tablecontrols ",
+spellchecker_languages : "+English=en",
+spellchecker_rpc_url : '/application/spellchecker',
table_styles : "Header 1=header1;Header 2=header2;Header 3=header3",
table_cell_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Cell=tableCel1",
table_row_styles : "Header 1=header1;Header 2=header2;Header 3=header3;Table Row=tableRow1",
@@ -151,6 +153,7 @@
});
//]]>
</script>
+
<% if !@element.parent.nil? %>
<h1><%= ts 'new.under', :what => h(@parent.next_level_name), :where => h(@parent.title) %></h1>
<% else %>
Added: portal/ror/plugins/mms_engine/trunk/lib/spelling.rb
===================================================================
--- portal/ror/plugins/mms_engine/trunk/lib/spelling.rb (rev 0)
+++ portal/ror/plugins/mms_engine/trunk/lib/spelling.rb 2010-01-28 18:56:52 UTC (rev 2083)
@@ -0,0 +1,36 @@
+module Spelling
+ require 'net/https'
+ require 'uri'
+ require 'rexml/document'
+
+ ASPELL_WORD_DATA_REGEX = Regexp.new(/\&\s\w+\s\d+\s\d+(.*)$/)
+ #ASPELL_PATH = "/opt/local/bin/aspell"
+ ASPELL_PATH = "/usr/bin/aspell"
+
+ def check_spelling(spell_check_text, command, lang)
+ xml_response_values = Array.new
+ spell_check_text = spell_check_text.join(' ') if command == 'checkWords'
+ spell_check_response = `echo "#{spell_check_text}" | #{ASPELL_PATH} -a -l #{lang}`
+ if (spell_check_response != '')
+ spelling_errors = spell_check_response.split("\n").slice(1..-1)
+ if (command == 'checkWords')
+ for error in spelling_errors
+ error.strip!
+ if (match_data = error.match(ASPELL_WORD_DATA_REGEX))
+ arr = match_data[0].split(' ')
+ xml_response_values << arr[1]
+ end
+ end
+ elsif (command == 'getSuggestions')
+ for error in spelling_errors
+ error.strip!
+ if (match_data = error.match(ASPELL_WORD_DATA_REGEX))
+ xml_response_values << error.split(',')[1..-1].collect(&:strip!)
+ xml_response_values = xml_response_values.first
+ end
+ end
+ end
+ end
+ return xml_response_values
+ end
+end
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|