thbar-diacritics_fu 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 1.0.1 / 2008-12-05
2
+ * Added support for Rails > 2.2 (thanks Nicolas Fouché!)
3
+ * Refactored to check ActiveSupport version
4
+ * Added missing require activerecord to the lib
5
+
1
6
  == 1.0.0 / 2008-10-21
2
7
  * Packaged as a gem.
3
8
 
data/Manifest.txt CHANGED
@@ -1,6 +1,10 @@
1
1
  diacritics_fu.gemspec
2
2
  History.txt
3
3
  lib/diacritics_fu.rb
4
+ lib/diacritics_fu/new_escaper.rb
5
+ lib/diacritics_fu/old_escaper.rb
4
6
  Manifest.txt
7
+ Rakefile
5
8
  README
6
- spec/diacritics_fu_spec.rb
9
+ spec/diacritics_fu_spec.rb
10
+ spec/spec_helper.rb
data/README CHANGED
@@ -10,23 +10,23 @@ DiacriticsFu::escape("räksmörgås")
10
10
  What?
11
11
  =====
12
12
 
13
- A small library to remove accents from a string. Relies on ActiveSupport::Multibyte::Handlers::UTF8Handler (Rails).
13
+ A small library to remove accents from a string. Relies on ActiveSupport.
14
14
 
15
15
  Created because I needed a simple way to remove most diacritics from French sentences, while generating slugs (url) for a CMS (either Mephisto or ComatoseCMS).
16
16
 
17
17
  Nb: this approach is not the fastest way to achieve this. It's good enough for me though.
18
18
 
19
- The library is not packaged (either like a gem, or a plugin, that is). Just drop diacritics_fu.rb in your /lib folder.
20
-
21
19
  Author
22
20
  ======
23
21
 
24
22
  Thibaut Barrère (http://blog.logeek.fr)
25
23
 
26
- TODO
27
- ====
24
+ Testing
25
+ =======
26
+
27
+ You can run the spec against the latest available ActiveSupport using "rake spec".
28
28
 
29
- This Git commit http://github.com/rails/rails/commit/22f75d539dca7b6f33cbf86e4e9d1944bb22731f indicates that the gem won't be able to work in future versions of rails => fix this.
29
+ To run the tests against all installed ActiveSupport versions, use "rake spec_multi"
30
30
 
31
31
  License
32
32
  =======
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require 'spec/rake/spectask'
4
+
5
+ task :default => :spec
6
+
7
+ desc "run specs for the gem"
8
+ Spec::Rake::SpecTask.new(:spec) do |t|
9
+ t.spec_files = FileList["spec/**/*_spec.rb"]
10
+ end
11
+
12
+ desc "run specs for the gem against all available activesupport versions"
13
+ task :spec_multi do
14
+ # hmm - there's probably a better way to write this
15
+ IO.popen("gem list activesupport").readlines.last.split(',').grep(/(\d\.\d\.\d)/) { $1 }.each do |version|
16
+ throw "Failed against ActiveSupport v#{version}" unless system("rake spec DIACRITICS_FU_ACTIVESUPPORT_VERSION=#{version}")
17
+ end
18
+ end
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "diacritics_fu"
3
- s.version = "1.0.0"
4
- s.date = "2008-10-21"
3
+ s.version = "1.0.1"
4
+ s.date = "2008-12-05"
5
5
  s.summary = "Tiny Ruby library to remove accents and other diacritics from a string (relies on ActiveSupport)."
6
6
  s.email = "thibaut.barrere@gmail.com"
7
7
  s.homepage = "http://github.com/thbar/diacritics_fu"
@@ -10,10 +10,13 @@ Gem::Specification.new do |s|
10
10
  s.authors = ["Thibaut Barrère"]
11
11
  s.files = ["History.txt",
12
12
  "README",
13
+ "Rakefile",
13
14
  "Manifest.txt",
14
15
  "diacritics_fu.gemspec",
15
- "lib/diacritics_fu.rb"]
16
- s.test_files = ["spec/diacritics_fu_spec.rb"]
16
+ "lib/diacritics_fu.rb",
17
+ "lib/diacritics_fu/new_escaper.rb",
18
+ "lib/diacritics_fu/old_escaper.rb"]
19
+ s.test_files = ["spec/diacritics_fu_spec.rb","spec/spec_helper.rb"]
17
20
 
18
21
  s.rdoc_options = ["--main", "README"]
19
22
  s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README"]
@@ -0,0 +1,5 @@
1
+ module DiacriticsFu
2
+ def self.escape(str)
3
+ ActiveSupport::Multibyte::Chars.new(str).normalize(:d).split(//u).reject { |e| e.length > 1 }.join
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module DiacriticsFu
2
+ def self.escape(str)
3
+ ActiveSupport::Multibyte::Handlers::UTF8Handler.normalize(str,:d).split(//u).reject { |e| e.length > 1 }.join
4
+ end
5
+ end
data/lib/diacritics_fu.rb CHANGED
@@ -1,11 +1,8 @@
1
- # A tiny class to remove accents (éèê) and other diacritics (ç) from a string.
2
- #
3
- # Author:: Thibaut Barrère (mailto:thibaut.barrere@gmail.com)
4
- # Copyright:: Copyright (c) 2008 LoGeek EURL
5
- # License:: Distributes under the same terms as Ruby
6
- module DiacriticsFu
7
- # Remove all accents and other diacritics from the passed string (ie: éphémère will return ephemere)
8
- def self.escape(str)
9
- ActiveSupport::Multibyte::Handlers::UTF8Handler.normalize(str,:d).split(//u).reject { |e| e.length > 1 }.join
10
- end
1
+ require 'active_support'
2
+ require 'active_support/version'
3
+
4
+ if ActiveSupport::VERSION::STRING >= "2.2.0"
5
+ require File.dirname(__FILE__) + '/diacritics_fu/new_escaper'
6
+ else
7
+ require File.dirname(__FILE__) + '/diacritics_fu/old_escaper'
11
8
  end
@@ -1,23 +1,32 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require 'diacritics_fu'
1
+ require 'rubygems'
3
2
 
4
- describe "DiacriticsFu.escape" do
3
+ # allow activation of a specific version of activesupport for testing
4
+ gem 'activesupport', "= #{ENV['DIACRITICS_FU_ACTIVESUPPORT_VERSION']}" if ENV['DIACRITICS_FU_ACTIVESUPPORT_VERSION']
5
+
6
+ require File.dirname(__FILE__) + '/spec_helper'
7
+ require 'active_support'
8
+
9
+ describe DiacriticsFu do
10
+
11
+ before(:all) do
12
+ puts "Testing using ActiveSupport version #{ActiveSupport::VERSION::STRING}"
13
+ end
5
14
 
6
15
  it "should remove the accents with grace" do
7
- DiacriticsFu::escape("éphémère").should eql("ephemere")
16
+ DiacriticsFu::escape("éphémère").should == "ephemere"
8
17
  DiacriticsFu::escape("éêèïîù").should eql("eeeiiu")
9
18
  end
10
19
 
11
- it "should work" do
20
+ it "should remove more exotic accents" do
12
21
  DiacriticsFu::escape("räksmörgås").should eql("raksmorgas")
13
22
  end
14
-
23
+
15
24
  KNOWN_DIACRITICS = { "a" => "àäâ", "e" => "éèêë", "i" => "îï", "o" => "ôö", "u" => "üû", "c" => "ç",
16
25
  "I" => "ÏÎ", "E" => "ÊË", "n" => "ñ", "O" => "ÔÖ", "Y" => "Ÿ", "y" => "ÿ", "N" => "Ñ" }
17
26
 
18
27
  KNOWN_DIACRITICS.each do |expected_replacement,originals|
19
28
  it "should transform any of '#{originals}' into '#{expected_replacement}'" do
20
- originals.split(//).each do |original|
29
+ originals.each_char do |original|
21
30
  DiacriticsFu.escape(original).should eql(expected_replacement)
22
31
  end
23
32
  end
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require File.dirname(__FILE__) + '/../lib/diacritics_fu'
3
+
4
+ # require after library code to avoid http://emmanueloga.wordpress.com/2008/10/16/rspec-118-in-exit-undefined-method-run-rails-210/
5
+ require 'spec'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thbar-diacritics_fu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Thibaut Barr\xC3\xA8re"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-10-21 00:00:00 -07:00
12
+ date: 2008-12-05 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -34,9 +34,12 @@ extra_rdoc_files:
34
34
  files:
35
35
  - History.txt
36
36
  - README
37
+ - Rakefile
37
38
  - Manifest.txt
38
39
  - diacritics_fu.gemspec
39
40
  - lib/diacritics_fu.rb
41
+ - lib/diacritics_fu/new_escaper.rb
42
+ - lib/diacritics_fu/old_escaper.rb
40
43
  has_rdoc: true
41
44
  homepage: http://github.com/thbar/diacritics_fu
42
45
  post_install_message:
@@ -66,3 +69,4 @@ specification_version: 2
66
69
  summary: Tiny Ruby library to remove accents and other diacritics from a string (relies on ActiveSupport).
67
70
  test_files:
68
71
  - spec/diacritics_fu_spec.rb
72
+ - spec/spec_helper.rb