Index: openacs-4/packages/acs-templating/tcl/spellcheck-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/spellcheck-procs.tcl,v diff -u -r1.21.2.1 -r1.21.2.2 --- openacs-4/packages/acs-templating/tcl/spellcheck-procs.tcl 27 Aug 2013 11:33:14 -0000 1.21.2.1 +++ openacs-4/packages/acs-templating/tcl/spellcheck-procs.tcl 23 Sep 2013 09:23:56 -0000 1.21.2.2 @@ -161,13 +161,15 @@ -var_to_spellcheck:required {-language ""} -error_num_ref:required + {-no_abort:boolean 0} -formtext_to_display_ref:required {-just_the_errwords_ref ""} } { @param text The string to check for spelling errors. @param html_p Does the text have html in it? If so, we strip out html tags in the string we feed to ispell (or aspell). + @param no_abort_p Set this tue for testing purposes (e.g. aa_test). @param var_to_spellcheck The name of the text input type or textarea that holds this text (eg., "email_body") @@ -200,6 +202,23 @@ set spelling_wrapper [file join [acs_root_dir] bin webspell] + if {![file executable $spelling_wrapper]} { + # + # In case no_abort is given we just return the error + # message. Otherwise an ad_return_error is raised and the + # script is ad_script_aborted. + # + if {!$no_abort_p} { + ad_return_error "Webspell could not be executed" \ + "Spell-checking is enabled but the spell-check wrapper\ + ([acs_root_dir]/bin/webspell) returns not be executed.\ + Check that the wrapper exists, and that its permissions are correct." + ad_script_abort + } else { + error $errmsg + } + } + set spellchecker_path [nsv_get spellchecker path] # @@ -213,44 +232,39 @@ append lang_and_enc " --lang=$language" } - # Caveat: The "open" arg must be a list (not a string) to allow the wrapper args to be the empty string - # (which $language will be when ispell is used, for instance) + #ns_log notice WRAPPER=[list |$spelling_wrapper [ns_info home] $spellchecker_path $lang_and_enc $dictionaryfile $tmpfile] - if { [catch { set ispell_proc [open [list |$spelling_wrapper [ns_info home] $spellchecker_path $lang_and_enc $dictionaryfile $tmpfile] r] } errmsg] } { - ad_return_error "Webspell could not be executed" "Spell-checking is enabled but the spell-check wrapper ([acs_root_dir]/bin/webspell) could not be executed. Check that the wrapper exists, and that its permissions are correct.
Here is the error message:
$errmsg" - ad_script_abort + if {[catch { + set ispell_lines [exec $spelling_wrapper [ns_info home] $spellchecker_path $lang_and_enc $dictionaryfile $tmpfile] + } errmsg]} { + #ns_log notice "errorMsg = $errmsg" + + # + # In case no_abort is given we just return the error + # message. Otherwise an ad_return_error is raised and the + # script is ad_script_aborted. + # + if {!$no_abort_p} { + ad_return_error "No dictionary found" \ + "Spell-checking is enabled but the spell-check dictionary\ + could not be reached. Check that the dictionary exists,\ + and that its permissions are correct.\ +
Here is the error message:
$errmsg" + ad_script_abort + } else { + error $errmsg + } } - - # read will occasionally error out with "interrupted system call", - # so retry a few times in the hopes that it will go away. - set try 0 - set max_retry 10 - while { [catch { set ispell_text [read -nonewline $ispell_proc] } errmsg] - && $try < $max_retry } { - incr try - ns_log warning "template::util::spellcheck::get_element_formtext: spellchecker had a problem: $errmsg" - } - fconfigure $ispell_proc -blocking 0 - - if { [catch { close $ispell_proc } errmsg] } { - ad_return_error "No dictionary found" "Spell-checking is enabled but the spell-check dictionary could not be reached. Check that the dictionary exists, and that its permissions are correct.
Here is the error message:
$errmsg" - ad_script_abort - } - file delete $tmpfile - if { $try == $max_retry } { - return -code error "webspell: Tried to execute spellchecker $max_retry times but it did not work out. Sorry!" - } - #### # # Ispell is done. Start manipulating the result string. # #### - set ispell_lines [split $ispell_text "\n"] + set ispell_lines [split $ispell_lines "\n"] # Remove the version line. if { [llength $ispell_lines] > 0 } { set ispell_lines [lreplace $ispell_lines 0 0] Index: openacs-4/packages/acs-templating/tcl/test/spell-checker-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-templating/tcl/test/spell-checker-procs.tcl,v diff -u -r1.7 -r1.7.10.1 --- openacs-4/packages/acs-templating/tcl/test/spell-checker-procs.tcl 10 Jan 2007 21:22:13 -0000 1.7 +++ openacs-4/packages/acs-templating/tcl/test/spell-checker-procs.tcl 23 Sep 2013 09:23:56 -0000 1.7.10.1 @@ -10,9 +10,27 @@ Test the spell-check proc that does the actual spell-checking. } { + + set SpellcheckFormWidgets [parameter::get_from_package_key \ + -package_key acs-templating \ + -parameter SpellcheckFormWidgets] + set enabled 0 + foreach {widget value} $SpellcheckFormWidgets { + if {!$value} continue + set enabled 1 + break + } + + if {!$enabled} { + aa_log "Spell checking is not enabled.\ + If you want to enable it, specify it via package parameter SpellcheckFormWidgets" + return + } + set base_command [list template::util::spellcheck::get_element_formtext \ -var_to_spellcheck var_to_spellcheck \ -error_num_ref error_num \ + -no_abort \ -formtext_to_display_ref formtext_to_display \ -just_the_errwords_ref just_the_errwords] @@ -27,8 +45,12 @@ aa_log "--- Correct text --- $command" - eval $command - + if {[catch {eval $command} errorMsg]} { + aa_false $errorMsg 1 + aa_log "Have you installed aspell and aspell-dict-en ?" + return + } + aa_true "True statement: Text contains no misspelled words" [expr {$error_num == 0}] aa_log "Number of miss-spelled words found in text: $error_num" @@ -59,8 +81,11 @@ aa_log "--- Incorrect text --- $command" - eval $command - + if {[catch {eval $command} errorMsg]} { + aa_false $errorMsg 1 + return + } + aa_true "True statement: Text contains misspelled words" [expr {$error_num > 0}] aa_log "Number of misspelled words found in text: $error_num" @@ -91,7 +116,11 @@ aa_log "--- Correctly spelled HTML fragment --- $command" - eval $command + if {[catch {eval $command} errorMsg]} { + aa_false $errorMsg 1 + aa_log "Maybe you have to install aspell and aspell-dict-en?" + return + } aa_true "True statement: HTML fragment contains no misspelled words" [expr {$error_num == 0}] @@ -124,8 +153,11 @@ aa_log "--- Incorrectly spelled HTML fragment --- $command" - eval $command - + if {[catch {eval $command} errorMsg]} { + aa_false $errorMsg 1 + return + } + aa_true "True statement: HTML fragment contains misspelled words" [expr {$error_num > 0}] aa_log "Number of miss-spelled words found in HTML fragment: $error_num"