thbar-diacritics_fu 1.0.0
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 +6 -0
- data/README +34 -0
- data/diacritics_fu.gemspec +21 -0
- data/lib/diacritics_fu.rb +11 -0
- data/spec/diacritics_fu_spec.rb +26 -0
- metadata +68 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
Quick start
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
DiacriticsFu::escape("éphémère")
|
|
5
|
+
=> "ephemere"
|
|
6
|
+
|
|
7
|
+
DiacriticsFu::escape("räksmörgås")
|
|
8
|
+
=> "raksmorgas"
|
|
9
|
+
|
|
10
|
+
What?
|
|
11
|
+
=====
|
|
12
|
+
|
|
13
|
+
A small library to remove accents from a string. Relies on ActiveSupport::Multibyte::Handlers::UTF8Handler (Rails).
|
|
14
|
+
|
|
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
|
+
|
|
17
|
+
Nb: this approach is not the fastest way to achieve this. It's good enough for me though.
|
|
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
|
+
Author
|
|
22
|
+
======
|
|
23
|
+
|
|
24
|
+
Thibaut Barrère (http://blog.logeek.fr)
|
|
25
|
+
|
|
26
|
+
TODO
|
|
27
|
+
====
|
|
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.
|
|
30
|
+
|
|
31
|
+
License
|
|
32
|
+
=======
|
|
33
|
+
|
|
34
|
+
MIT
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "diacritics_fu"
|
|
3
|
+
s.version = "1.0.0"
|
|
4
|
+
s.date = "2008-10-21"
|
|
5
|
+
s.summary = "Tiny Ruby library to remove accents and other diacritics from a string (relies on ActiveSupport)."
|
|
6
|
+
s.email = "thibaut.barrere@gmail.com"
|
|
7
|
+
s.homepage = "http://github.com/thbar/diacritics_fu"
|
|
8
|
+
s.description = "A small library to remove accents from a string."
|
|
9
|
+
s.has_rdoc = true
|
|
10
|
+
s.authors = ["Thibaut Barrère"]
|
|
11
|
+
s.files = ["History.txt",
|
|
12
|
+
"README",
|
|
13
|
+
"Manifest.txt",
|
|
14
|
+
"diacritics_fu.gemspec",
|
|
15
|
+
"lib/diacritics_fu.rb"]
|
|
16
|
+
s.test_files = ["spec/diacritics_fu_spec.rb"]
|
|
17
|
+
|
|
18
|
+
s.rdoc_options = ["--main", "README"]
|
|
19
|
+
s.extra_rdoc_files = ["History.txt", "Manifest.txt", "README"]
|
|
20
|
+
s.add_dependency("activesupport", ["> 0.0.0"])
|
|
21
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
11
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
|
+
require 'diacritics_fu'
|
|
3
|
+
|
|
4
|
+
describe "DiacriticsFu.escape" do
|
|
5
|
+
|
|
6
|
+
it "should remove the accents with grace" do
|
|
7
|
+
DiacriticsFu::escape("éphémère").should eql("ephemere")
|
|
8
|
+
DiacriticsFu::escape("éêèïîù").should eql("eeeiiu")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "should work" do
|
|
12
|
+
DiacriticsFu::escape("räksmörgås").should eql("raksmorgas")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
KNOWN_DIACRITICS = { "a" => "àäâ", "e" => "éèêë", "i" => "îï", "o" => "ôö", "u" => "üû", "c" => "ç",
|
|
16
|
+
"I" => "ÏÎ", "E" => "ÊË", "n" => "ñ", "O" => "ÔÖ", "Y" => "Ÿ", "y" => "ÿ", "N" => "Ñ" }
|
|
17
|
+
|
|
18
|
+
KNOWN_DIACRITICS.each do |expected_replacement,originals|
|
|
19
|
+
it "should transform any of '#{originals}' into '#{expected_replacement}'" do
|
|
20
|
+
originals.split(//).each do |original|
|
|
21
|
+
DiacriticsFu.escape(original).should eql(expected_replacement)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: thbar-diacritics_fu
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- "Thibaut Barr\xC3\xA8re"
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2008-10-21 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: activesupport
|
|
17
|
+
version_requirement:
|
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
+
requirements:
|
|
20
|
+
- - ">"
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 0.0.0
|
|
23
|
+
version:
|
|
24
|
+
description: A small library to remove accents from a string.
|
|
25
|
+
email: thibaut.barrere@gmail.com
|
|
26
|
+
executables: []
|
|
27
|
+
|
|
28
|
+
extensions: []
|
|
29
|
+
|
|
30
|
+
extra_rdoc_files:
|
|
31
|
+
- History.txt
|
|
32
|
+
- Manifest.txt
|
|
33
|
+
- README
|
|
34
|
+
files:
|
|
35
|
+
- History.txt
|
|
36
|
+
- README
|
|
37
|
+
- Manifest.txt
|
|
38
|
+
- diacritics_fu.gemspec
|
|
39
|
+
- lib/diacritics_fu.rb
|
|
40
|
+
has_rdoc: true
|
|
41
|
+
homepage: http://github.com/thbar/diacritics_fu
|
|
42
|
+
post_install_message:
|
|
43
|
+
rdoc_options:
|
|
44
|
+
- --main
|
|
45
|
+
- README
|
|
46
|
+
require_paths:
|
|
47
|
+
- lib
|
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: "0"
|
|
53
|
+
version:
|
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
|
+
requirements:
|
|
56
|
+
- - ">="
|
|
57
|
+
- !ruby/object:Gem::Version
|
|
58
|
+
version: "0"
|
|
59
|
+
version:
|
|
60
|
+
requirements: []
|
|
61
|
+
|
|
62
|
+
rubyforge_project:
|
|
63
|
+
rubygems_version: 1.2.0
|
|
64
|
+
signing_key:
|
|
65
|
+
specification_version: 2
|
|
66
|
+
summary: Tiny Ruby library to remove accents and other diacritics from a string (relies on ActiveSupport).
|
|
67
|
+
test_files:
|
|
68
|
+
- spec/diacritics_fu_spec.rb
|