babosa 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +53 -14
- data/lib/babosa/characters.rb +1 -0
- data/lib/babosa/slug_string.rb +3 -3
- data/lib/babosa/version.rb +1 -1
- data/test/babosa_test.rb +4 -0
- metadata +3 -3
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Babosa is a library for creating slugs. It is an extraction and improvement of
|
4
4
|
the string code from [FriendlyId](http://github.com/norman/friendly_id),
|
5
|
-
intended to help developers create libraries
|
5
|
+
intended to help developers create similar libraries and plugins.
|
6
6
|
|
7
7
|
## Features / Usage
|
8
8
|
|
@@ -10,12 +10,13 @@ intended to help developers create libraries similar to FriendlyId.
|
|
10
10
|
|
11
11
|
"Gölcük, Turkey".to_slug.approximate_ascii.to_s #=> "Golcuk, Turkey"
|
12
12
|
|
13
|
-
###
|
13
|
+
### Per-locale transliteration
|
14
14
|
|
15
15
|
"Jürgen Müller".to_slug.approximate_ascii.to_s #=> "Jurgen Muller"
|
16
16
|
"Jürgen Müller".to_slug.approximate_ascii(:german).to_s #=> "Juergen Mueller"
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
Currently, only German, Spanish and Serbian are supported. I'll gladly accept
|
19
|
+
contributions and support more languages.
|
19
20
|
|
20
21
|
### Non-ASCII removal
|
21
22
|
|
@@ -32,12 +33,45 @@ whose length is limited by bytes rather than UTF-8 characters.
|
|
32
33
|
|
33
34
|
"üüü".to_slug.truncate_bytes(2).to_s #=> "ü"
|
34
35
|
|
36
|
+
### Remove punctuation chars
|
37
|
+
|
38
|
+
"this is, um, **really** cool, huh?".to_slug.word_chars.to_s #=> "this is um really cool huh"
|
39
|
+
|
35
40
|
### All-in-one
|
36
41
|
|
37
42
|
"Gölcük, Turkey".to_slug.normalize.to_s #=> "golcuk-turkey"
|
38
43
|
|
39
|
-
|
40
|
-
|
44
|
+
|
45
|
+
### UTF-8 support
|
46
|
+
|
47
|
+
Babosa has no hard dependencies, but if you have either the Unicode or
|
48
|
+
ActiveSupport gems installed and required prior to requiring "babosa", these
|
49
|
+
will be used to perform upcasing and downcasing on UTF-8 strings. On JRuby 1.5
|
50
|
+
and above, Java's native Unicode support will be used.
|
51
|
+
|
52
|
+
If none of these libraries are available, Babosa falls back to a simple module
|
53
|
+
which supports only Unicode strings only with Latin characters. I recommend
|
54
|
+
using the Unicode gem where possible since it's a C extension and is very fast.
|
55
|
+
|
56
|
+
|
57
|
+
### Rails 3
|
58
|
+
|
59
|
+
Most of Babosa's functionality is already present in Active Support/Rails 3.
|
60
|
+
Babosa exists primarily to support non-Rails applications, and Rails apps prior
|
61
|
+
to 3.0. Most of the code here was originally written for FriendlyId. Several
|
62
|
+
things, like tidy_bytes and ASCII transliteration, were later added to Rails and I18N.
|
63
|
+
|
64
|
+
Babosa differs from ActiveSupport primarily in that it supports non-Latin
|
65
|
+
strings by default. If you are considering using Babosa with Rails 3, you should first
|
66
|
+
take a look at Active Support's
|
67
|
+
[transliterate](http://edgeapi.rubyonrails.org/classes/ActiveSupport/Inflector.html#M000565)
|
68
|
+
and
|
69
|
+
[parameterize](http://edgeapi.rubyonrails.org/classes/ActiveSupport/Inflector.html#M000566)
|
70
|
+
because it's very likely they already do what you need.
|
71
|
+
|
72
|
+
### More info
|
73
|
+
|
74
|
+
Please see the [API docs](http://norman.github.com/babosa) and source code for more info.
|
41
75
|
|
42
76
|
## Getting it
|
43
77
|
|
@@ -47,6 +81,9 @@ Babosa can be installed via Rubygems:
|
|
47
81
|
|
48
82
|
You can get the source code from its [Github repository](http://github.com/norman/babosa).
|
49
83
|
|
84
|
+
Babosa is tested to be compatible with Ruby 1.8.6-1.9.2, JRuby 1.4-1.5,
|
85
|
+
Rubinius 1.0, and is probably compatible with other Rubies as well.
|
86
|
+
|
50
87
|
## Reporting bugs
|
51
88
|
|
52
89
|
Please use Babosa's [Github issue tracker](http://github.com/norman/babosa/issues).
|
@@ -54,20 +91,22 @@ Please use Babosa's [Github issue tracker](http://github.com/norman/babosa/issue
|
|
54
91
|
|
55
92
|
## Misc
|
56
93
|
|
57
|
-
The speed and quality of Babosa's UTF-8 support depends on which Ruby and which
|
58
|
-
gems you are using.
|
59
|
-
|
60
|
-
On JRuby 1.5 and above, Babosa uses Java's native UTF-8 support. If you require
|
61
|
-
[Unicode](http://github.com/blackwinter/unicode) or ActiveSupport before
|
62
|
-
Babosa, it will use the support provided by those libraries. Otherwise, Babosa
|
63
|
-
defaults to very basic UTF-8 support for Latin characters only.
|
64
|
-
|
65
94
|
"Babosa" means slug in Spanish.
|
66
95
|
|
67
96
|
## Author
|
68
97
|
|
69
98
|
[Norman Clarke](http://njclarke.com)
|
70
99
|
|
100
|
+
## Contributors
|
101
|
+
|
102
|
+
* [Milan Dobrota](http://github.com/milandobrota) - Serbian support
|
103
|
+
|
104
|
+
|
105
|
+
## Changelog
|
106
|
+
|
107
|
+
* 0.1.1 - Added support for Serbian.
|
108
|
+
* 0.1.0 - Initial extraction from FriendlyId.
|
109
|
+
|
71
110
|
## Copyright
|
72
111
|
|
73
112
|
Copyright (c) 2010 Norman Clarke
|
data/lib/babosa/characters.rb
CHANGED
@@ -37,6 +37,7 @@ module Babosa
|
|
37
37
|
|
38
38
|
add_approximations :spanish, "ñ" => "ni"
|
39
39
|
add_approximations :german, "ä" => "ae", "ö" => "oe", "ü" => "ue"
|
40
|
+
add_approximations :serbian, "Ð" => "Dj", "đ" => "dj" ,"Č" => "Ch", "č" => "ch", "Š" => "Sh", "š" => "sh"
|
40
41
|
add_approximations :latin, {
|
41
42
|
"À" => "A", "Á" => "A", "Â" => "A", "Ã" => "A", "Ä" => "A", "Å" => "A",
|
42
43
|
"Æ" => "AE", "Ç" => "C", "È" => "E", "É" => "E", "Ê" => "E", "Ë" => "E",
|
data/lib/babosa/slug_string.rb
CHANGED
@@ -50,7 +50,7 @@ module Babosa
|
|
50
50
|
@wrapped_string.__send__(symbol, *args, &block)
|
51
51
|
end
|
52
52
|
|
53
|
-
# @param string [
|
53
|
+
# @param string [#to_s] The string to use as the basis of the SlugString.
|
54
54
|
def initialize(string)
|
55
55
|
@wrapped_string = string.to_s
|
56
56
|
tidy_bytes!
|
@@ -101,7 +101,8 @@ module Babosa
|
|
101
101
|
@wrapped_string = @wrapped_string.gsub("-", " ").squeeze(" ").strip
|
102
102
|
end
|
103
103
|
|
104
|
-
# Remove any non-word characters.
|
104
|
+
# Remove any non-word characters. For this library's purposes, this means
|
105
|
+
# anything other than letters, numbers, spaces, newlines and linefeeds.
|
105
106
|
# @return String
|
106
107
|
def word_chars!
|
107
108
|
@wrapped_string = (unpack("U*") - Characters.strippable).pack("U*")
|
@@ -218,6 +219,5 @@ module Babosa
|
|
218
219
|
string.send(*args)
|
219
220
|
string
|
220
221
|
end
|
221
|
-
|
222
222
|
end
|
223
223
|
end
|
data/lib/babosa/version.rb
CHANGED
data/test/babosa_test.rb
CHANGED
@@ -113,6 +113,10 @@ class BabosaTest < Test::Unit::TestCase
|
|
113
113
|
assert_equal "anio", "año".to_slug.approximate_ascii!(:spanish)
|
114
114
|
end
|
115
115
|
|
116
|
+
test "should do special approximations for Serbian" do
|
117
|
+
assert_equal "Indjija", "Inđija".to_slug.approximate_ascii!(:serbian)
|
118
|
+
end
|
119
|
+
|
116
120
|
test "should work with non roman chars" do
|
117
121
|
assert_equal "検-索", "検 索".to_slug.normalize!
|
118
122
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Norman Clarke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-
|
17
|
+
date: 2010-08-09 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|