thbar-diacritics_fu 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +5 -0
- data/Manifest.txt +5 -1
- data/README +6 -6
- data/Rakefile +18 -0
- data/diacritics_fu.gemspec +7 -4
- data/lib/diacritics_fu/new_escaper.rb +5 -0
- data/lib/diacritics_fu/old_escaper.rb +5 -0
- data/lib/diacritics_fu.rb +7 -10
- data/spec/diacritics_fu_spec.rb +16 -7
- data/spec/spec_helper.rb +5 -0
- metadata +6 -2
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
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
|
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
|
-
|
27
|
-
|
24
|
+
Testing
|
25
|
+
=======
|
26
|
+
|
27
|
+
You can run the spec against the latest available ActiveSupport using "rake spec".
|
28
28
|
|
29
|
-
|
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
|
data/diacritics_fu.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "diacritics_fu"
|
3
|
-
s.version = "1.0.
|
4
|
-
s.date = "2008-
|
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
|
-
|
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"]
|
data/lib/diacritics_fu.rb
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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
|
data/spec/diacritics_fu_spec.rb
CHANGED
@@ -1,23 +1,32 @@
|
|
1
|
-
require
|
2
|
-
require 'diacritics_fu'
|
1
|
+
require 'rubygems'
|
3
2
|
|
4
|
-
|
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
|
16
|
+
DiacriticsFu::escape("éphémère").should == "ephemere"
|
8
17
|
DiacriticsFu::escape("éêèïîù").should eql("eeeiiu")
|
9
18
|
end
|
10
19
|
|
11
|
-
it "should
|
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.
|
29
|
+
originals.each_char do |original|
|
21
30
|
DiacriticsFu.escape(original).should eql(expected_replacement)
|
22
31
|
end
|
23
32
|
end
|
data/spec/spec_helper.rb
ADDED
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.
|
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-
|
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
|