speaking_url 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc
CHANGED
@@ -48,7 +48,14 @@ instead of modifying the field directly.
|
|
48
48
|
|
49
49
|
@person.add_mapping('/some/new/mapping')
|
50
50
|
|
51
|
+
=== Core Extensions
|
51
52
|
|
53
|
+
The gem comes with some helpful inflection methods for the String class.
|
54
|
+
|
55
|
+
* +urlify+ : replaces all white space and special characters with dashes
|
56
|
+
* +unumlaut+ : converts German Umlauts to their ASCII counterparts
|
57
|
+
|
58
|
+
Additionally, the methods +upcase+ and +downcase+ are made Umlaut aware.
|
52
59
|
|
53
60
|
== Configuring routes
|
54
61
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
class String
|
2
|
+
|
3
|
+
alias_method :original_downcase, :downcase
|
4
|
+
alias_method :original_upcase, :upcase
|
5
|
+
|
6
|
+
def upcase
|
7
|
+
translations = [ ["ä", "Ä"], ["ö", "Ö"], ["ü", "Ü"], ["ß", "SS"] ]
|
8
|
+
res = self.original_upcase
|
9
|
+
translations.each do |f,t|
|
10
|
+
res.gsub!(f,t)
|
11
|
+
end
|
12
|
+
res
|
13
|
+
end
|
14
|
+
|
15
|
+
def downcase
|
16
|
+
translations = [ ["Ä", "ä"], ["Ö", "ö"], ["Ü", "ü"] ]
|
17
|
+
res = self.original_downcase
|
18
|
+
translations.each do |f,t|
|
19
|
+
res.gsub!(f,t)
|
20
|
+
end
|
21
|
+
res
|
22
|
+
end
|
23
|
+
|
24
|
+
# Replaces all white space and special characters of a String with dashes, to make
|
25
|
+
# it a valid url segment:
|
26
|
+
#
|
27
|
+
# "** Dr. Jekyll and Mr. Hyde ++" # => "Dr-Jekyll-and-Mr-Hyde"
|
28
|
+
def urlify
|
29
|
+
self.split(/\W+/).reject(&:blank?).join('-')
|
30
|
+
end
|
31
|
+
|
32
|
+
# Romanizes all German Umlaut characters
|
33
|
+
#
|
34
|
+
# "Füße".unumlaut # => "Fuesse"
|
35
|
+
def unumlaut
|
36
|
+
res = self
|
37
|
+
translations = [ ["Ä", "AE"], ["ä", "ae"], ["Ö", "OE"], ["ö", "oe"], ["Ü", "UE"], ["ü", "ue"], ["ß", "ss"] ]
|
38
|
+
translations.each do |f,t|
|
39
|
+
res.gsub!(f,t)
|
40
|
+
end
|
41
|
+
res
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
data/lib/speaking_url/version.rb
CHANGED
data/lib/speaking_url.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
require 'test_helper'
|
3
|
+
|
4
|
+
class StringExtUrlify < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_space_delimited
|
7
|
+
assert_equal 'Firstname-Lastname', "Firstname Lastname".urlify
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_leading_and_trailing_space
|
11
|
+
assert_equal 'Dr-Firstname-Lastname', " Dr. Firstname Lastname ".urlify
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_leading_and_trailing_special_characters
|
15
|
+
assert_equal 'Dr-Firstname-Lastname-1', "*** Dr. Firstname Lastname #1 !!!".urlify
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class StringExtUnumlaut < Test::Unit::TestCase
|
21
|
+
|
22
|
+
def test_replace_umlaute_with_ascii
|
23
|
+
assert_equal "AEOEUESSaeoeuess","ÄÖÜSSäöüß".unumlaut
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
class StringExtUpAndDowncase < Test::Unit::TestCase
|
29
|
+
|
30
|
+
def test_make_umlaut_uppercase
|
31
|
+
assert_equal "ÄÖÜSS", "äöüß".upcase
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_make_umlaute_downcase
|
35
|
+
assert_equal "äöüss","ÄÖÜSS".downcase
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
|
metadata
CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.2
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kai Rubarth
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-06-
|
18
|
+
date: 2011-06-28 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -61,10 +61,12 @@ files:
|
|
61
61
|
- README.rdoc
|
62
62
|
- Rakefile
|
63
63
|
- lib/speaking_url.rb
|
64
|
+
- lib/speaking_url/core_ext/string/inflections.rb
|
64
65
|
- lib/speaking_url/mongo_resource.rb
|
65
66
|
- lib/speaking_url/routing_extensions.rb
|
66
67
|
- lib/speaking_url/version.rb
|
67
68
|
- speaking_url.gemspec
|
69
|
+
- test/core_ext/string_extensions_test.rb
|
68
70
|
- test/dummy/Rakefile
|
69
71
|
- test/dummy/app/controllers/application_controller.rb
|
70
72
|
- test/dummy/app/controllers/articles_controller.rb
|
@@ -136,6 +138,7 @@ signing_key:
|
|
136
138
|
specification_version: 3
|
137
139
|
summary: allows arbitrary url for resources and facilitates seo-friendly changing of urls.
|
138
140
|
test_files:
|
141
|
+
- test/core_ext/string_extensions_test.rb
|
139
142
|
- test/dummy/Rakefile
|
140
143
|
- test/dummy/app/controllers/application_controller.rb
|
141
144
|
- test/dummy/app/controllers/articles_controller.rb
|