Browse files

Refactoring for Rails 2.2 support + rake tasks

  • Loading branch information...
1 parent bd8e35d commit b350d8004599bfefa702430c22479c97b5b25293 @thbar committed Dec 5, 2008
Showing with 39 additions and 23 deletions.
  1. +5 −0 History.txt
  2. +5 −1 Manifest.txt
  3. +7 −4 diacritics_fu.gemspec
  4. +6 −11 lib/diacritics_fu.rb
  5. +16 −7 spec/diacritics_fu_spec.rb
View
5 History.txt
@@ -1,3 +1,8 @@
+== 1.0.1 / 2008-12-05
+ * Added support for Rails > 2.2 (thanks Nicolas Fouché!)
+ * Refactored to check ActiveSupport version
+ * Added missing require activerecord to the lib
+
== 1.0.0 / 2008-10-21
* Packaged as a gem.
View
6 Manifest.txt
@@ -1,6 +1,10 @@
diacritics_fu.gemspec
History.txt
lib/diacritics_fu.rb
+lib/diacritics_fu/new_escaper.rb
+lib/diacritics_fu/old_escaper.rb
Manifest.txt
+Rakefile
README
-spec/diacritics_fu_spec.rb
+spec/diacritics_fu_spec.rb
+spec/spec_helper.rb
View
11 diacritics_fu.gemspec
@@ -1,7 +1,7 @@
Gem::Specification.new do |s|
s.name = "diacritics_fu"
- s.version = "1.0.0"
- s.date = "2008-10-21"
+ s.version = "1.0.1"
+ s.date = "2008-12-05"
s.summary = "Tiny Ruby library to remove accents and other diacritics from a string (relies on ActiveSupport)."
s.email = "thibaut.barrere@gmail.com"
s.homepage = "http://github.com/thbar/diacritics_fu"
@@ -10,10 +10,13 @@ Gem::Specification.new do |s|
s.authors = ["Thibaut Barrère"]
s.files = ["History.txt",
"README",
+ "Rakefile",
"Manifest.txt",
"diacritics_fu.gemspec",
- "lib/diacritics_fu.rb"]
- s.test_files = ["spec/diacritics_fu_spec.rb"]
+ "lib/diacritics_fu.rb",
+ "lib/diacritics_fu/new_escaper.rb",
+ "lib/diacritics_fu/old_escaper.rb"]
+ s.test_files = ["spec/diacritics_fu_spec.rb","spec/spec_helper.rb"]
s.rdoc_options = ["--main", "README"]
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README"]
View
17 lib/diacritics_fu.rb
@@ -1,13 +1,8 @@
-require 'activesupport'
+require 'active_support'
+require 'active_support/version'
-# A tiny class to remove accents (éèê) and other diacritics (ç) from a string.
-#
-# Author:: Thibaut Barrère (mailto:thibaut.barrere@gmail.com)
-# Copyright:: Copyright (c) 2008 LoGeek EURL
-# License:: Distributes under the same terms as Ruby
-module DiacriticsFu
- # Remove all accents and other diacritics from the passed string (ie: éphémère will return ephemere)
- def self.escape(str)
- ActiveSupport::Multibyte::Handlers::UTF8Handler.normalize(str,:d).split(//u).reject { |e| e.length > 1 }.join
- end
+if ActiveSupport::VERSION::STRING >= "2.2.0"
+ require File.dirname(__FILE__) + '/diacritics_fu/new_escaper'
+else
+ require File.dirname(__FILE__) + '/diacritics_fu/old_escaper'
end
View
23 spec/diacritics_fu_spec.rb
@@ -1,23 +1,32 @@
-require File.dirname(__FILE__) + '/../spec_helper'
-require 'diacritics_fu'
+require 'rubygems'
-describe "DiacriticsFu.escape" do
+# allow activation of a specific version of activesupport for testing
+gem 'activesupport', "= #{ENV['DIACRITICS_FU_ACTIVESUPPORT_VERSION']}" if ENV['DIACRITICS_FU_ACTIVESUPPORT_VERSION']
+
+require File.dirname(__FILE__) + '/spec_helper'
+require 'active_support'
+
+describe DiacriticsFu do
+
+ before(:all) do
+ puts "Testing using ActiveSupport version #{ActiveSupport::VERSION::STRING}"
+ end
it "should remove the accents with grace" do
- DiacriticsFu::escape("éphémère").should eql("ephemere")
+ DiacriticsFu::escape("éphémère").should == "ephemere"
DiacriticsFu::escape("éêèïîù").should eql("eeeiiu")
end
- it "should work" do
+ it "should remove more exotic accents" do
DiacriticsFu::escape("räksmörgås").should eql("raksmorgas")
end
-
+
KNOWN_DIACRITICS = { "a" => "àäâ", "e" => "éèêë", "i" => "îï", "o" => "ôö", "u" => "üû", "c" => "ç",
"I" => "ÏÎ", "E" => "ÊË", "n" => "ñ", "O" => "ÔÖ", "Y" => "Ÿ", "y" => "ÿ", "N" => "Ñ" }
KNOWN_DIACRITICS.each do |expected_replacement,originals|
it "should transform any of '#{originals}' into '#{expected_replacement}'" do
- originals.split(//).each do |original|
+ originals.each_char do |original|
DiacriticsFu.escape(original).should eql(expected_replacement)
end
end

0 comments on commit b350d80

Please sign in to comment.