Permalink
Browse files

An RDoc spellchecker

Added option parsing
  • Loading branch information...
0 parents commit 335d50d28acde5587bb2a0bf65174e9fe4930c85 @drbrain drbrain committed Apr 5, 2012
Showing with 233 additions and 0 deletions.
  1. +17 −0 .autotest
  2. +5 −0 .gitignore
  3. +15 −0 .travis.yml
  4. +5 −0 History.rdoc
  5. +8 −0 Manifest.txt
  6. +60 −0 README.rdoc
  7. +19 −0 Rakefile
  8. +2 −0 lib/rdoc/discover.rb
  9. +63 −0 lib/rdoc/generator/spellcheck.rb
  10. +39 −0 test/test_rdoc_generator_spellcheck.rb
@@ -0,0 +1,17 @@
+# -*- ruby -*-
+
+require 'autotest/restart'
+
+Autotest.add_hook :initialize do |at|
+ at.testlib = 'minitest/autorun'
+ at.add_exception '.git'
+
+ def at.path_to_classname s
+ sep = File::SEPARATOR
+ f = s.sub(/^test#{sep}/, '').sub(/\.rb$/, '').split(sep)
+ f = f.map { |path| path.split(/_|(\d+)/).map { |seg| seg.capitalize }.join }
+ f = f.map { |path| path =~ /^Test/ ? path : "Test#{path}" }
+ f.join('::').gsub('Rdoc', 'RDoc')
+ end
+end
+
@@ -0,0 +1,5 @@
+*.rbc
+*.swp
+/TAGS
+/doc
+/pkg
@@ -0,0 +1,15 @@
+---
+after_script:
+- rake travis:after -t
+before_script:
+- gem install hoe-travis --no-rdoc --no-ri
+- rake travis:before -t
+language: ruby
+notifications:
+ email:
+ - drbrain@segment7.net
+rvm:
+- 1.8.7
+- 1.9.2
+- 1.9.3
+script: rake travis
@@ -0,0 +1,5 @@
+=== 1.0 / 2012-04-05
+
+* Major enhancements
+ * Birthday!
+
@@ -0,0 +1,8 @@
+.autotest
+History.rdoc
+Manifest.txt
+README.rdoc
+Rakefile
+lib/rdoc/discover.rb
+lib/rdoc/generator/spellcheck.rb
+test/test_rdoc_generator_spellcheck.rb
@@ -0,0 +1,60 @@
+= rdoc-spellcheck
+
+home :: https://github.com/drbrain/rdoc-spellcheck
+rdoc :: http://docs.seattlerb.org/rdoc-spellcheck
+bugs :: https://github.com/drbrain/rdoc-spellcheck/issues
+
+== Description
+
+FIX (describe your package)
+
+== Features and Problems
+
+* FIX (list of features or problems)
+
+== Synopsis
+
+ FIX (code sample of usage)
+
+== Requirements
+
+* FIX (list of requirements)
+
+== Install
+
+ sudo gem install rdoc-spellcheck
+
+== Developers
+
+After checking out the source, run:
+
+ $ rake newb
+
+This task will install any missing dependencies, run the tests/specs,
+and generate the RDoc.
+
+== License
+
+(The MIT License)
+
+Copyright (c) FIX
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
@@ -0,0 +1,19 @@
+# -*- ruby -*-
+
+require 'rubygems'
+require 'hoe'
+
+Hoe.plugin :minitest
+Hoe.plugin :git
+Hoe.plugin :travis
+
+Hoe.spec 'rdoc-spellcheck' do
+ developer 'Eric Hodel', 'drbrain@segment7.net'
+
+ rdoc_locations <<
+ 'docs.seattlerb.org:/data/www/docs.seattlerb.org/rdoc-spellcheck/'
+
+ dependency 'raspell', '~> 1.3'
+end
+
+# vim: syntax=ruby
@@ -0,0 +1,2 @@
+require 'rdoc/spellcheck'
+
@@ -0,0 +1,63 @@
+require 'rubygems'
+
+gem 'rdoc', '~> 3.12'
+
+require 'rdoc'
+require 'rdoc/generator'
+
+require 'raspell'
+
+class RDoc::Generator::Spellcheck
+
+ RDoc::RDoc.add_generator self
+
+ ##
+ # This version of rdoc-spellcheck
+
+ VERSION = '1.0'
+
+ ##
+ # OptionParser validator for Aspell language dictionaries
+
+ SpellLanguage = Object.new
+
+ ##
+ # Adds rdoc-spellcheck options to the rdoc command
+
+ def self.setup_options options
+ default_language, = ENV['LANG'].split '.'
+
+ options.spell_language = default_language
+
+ op = options.option_parser
+
+ op.accept SpellLanguage do |language|
+ found = Aspell.list_dicts.find do |dict|
+ dict.name == language
+ end
+
+ raise OptionParser::InvalidArgument,
+ "dictionary #{language} not installed" unless found
+
+ language
+ end
+
+ op.on('--spell-language=LANGUAGE', SpellLanguage,
+ 'Language to use for spell checking',
+ "The default language is #{default_language}") do |language|
+ options.spell_language = language
+ end
+ end
+
+end
+
+class RDoc::Options
+
+ ##
+ # The Aspell dictionary language to use. Defaults to the language in the
+ # LANG environment variable.
+
+ attr_accessor :spell_language
+
+end
+
@@ -0,0 +1,39 @@
+require 'rubygems'
+require 'minitest/autorun'
+
+require 'rdoc/generator/spellcheck'
+require 'rdoc/test_case'
+
+class TestRDocGeneratorSpellcheck < RDoc::TestCase
+
+ def setup
+ super
+
+ @S = RDoc::Generator::Spellcheck
+ end
+
+ def test_class_setup_options_default
+ orig_lang = ENV['LANG']
+ ENV['LANG'] = 'en_US.UTF-8'
+
+ options = RDoc::Options.new
+
+ options.parse %w[--format spellcheck]
+
+ assert_equal 'en_US', options.spell_language
+ end
+
+ def test_class_setup_options_spell_language
+ options = RDoc::Options.new
+
+ options.parse %w[
+ --format spellcheck
+ --no-ignore-invalid
+ --spell-language en_GB
+ ]
+
+ assert_equal 'en_GB', options.spell_language
+ end
+
+end
+

0 comments on commit 335d50d

Please sign in to comment.