stringex 2.0.11 → 2.8.6
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.
- checksums.yaml +6 -14
- data/Gemfile +45 -14
- data/MIT-LICENSE +1 -1
- data/README.md +162 -0
- data/Rakefile +5 -31
- data/VERSION +1 -1
- data/lib/stringex/acts_as_url/adapter/active_record.rb +1 -1
- data/lib/stringex/acts_as_url/adapter/base.rb +37 -5
- data/lib/stringex/acts_as_url/adapter/data_mapper.rb +3 -7
- data/lib/stringex/acts_as_url/adapter/mongoid.rb +2 -2
- data/lib/stringex/acts_as_url.rb +11 -4
- data/lib/stringex/configuration/acts_as_url.rb +15 -10
- data/lib/stringex/configuration/string_extensions.rb +7 -6
- data/lib/stringex/core_ext.rb +10 -0
- data/lib/stringex/localization/backend/i18n.rb +16 -3
- data/lib/stringex/localization/conversion_expressions.rb +64 -60
- data/lib/stringex/localization/converter.rb +8 -4
- data/lib/stringex/localization/default_conversions.rb +56 -55
- data/lib/stringex/localization.rb +2 -2
- data/lib/stringex/string_extensions.rb +34 -6
- data/lib/stringex/unidecoder.rb +26 -22
- data/lib/stringex/unidecoder_data/x00.yml +1 -1
- data/lib/stringex/unidecoder_data/x03.yml +2 -2
- data/lib/stringex/unidecoder_data/x05.yml +1 -1
- data/lib/stringex/unidecoder_data/x07.yml +1 -1
- data/lib/stringex/unidecoder_data/x09.yml +2 -2
- data/lib/stringex/unidecoder_data/x0a.yml +2 -2
- data/lib/stringex/unidecoder_data/x0f.yml +1 -1
- data/lib/stringex/unidecoder_data/x12.yml +1 -1
- data/lib/stringex/unidecoder_data/x13.yml +1 -1
- data/lib/stringex/unidecoder_data/x14.yml +2 -2
- data/lib/stringex/unidecoder_data/x15.yml +1 -1
- data/lib/stringex/unidecoder_data/x16.yml +2 -2
- data/lib/stringex/unidecoder_data/x18.yml +2 -2
- data/lib/stringex/unidecoder_data/x20.yml +4 -4
- data/lib/stringex/unidecoder_data/x21.yml +28 -28
- data/lib/stringex/unidecoder_data/x25.yml +16 -16
- data/lib/stringex/unidecoder_data/x28.yml +1 -1
- data/lib/stringex/unidecoder_data/x30.yml +2 -2
- data/lib/stringex/unidecoder_data/x32.yml +1 -1
- data/lib/stringex/unidecoder_data/xa1.yml +1 -1
- data/lib/stringex/unidecoder_data/xb1.yml +1 -1
- data/lib/stringex/unidecoder_data/xc6.yml +2 -2
- data/lib/stringex/unidecoder_data/xfe.yml +3 -3
- data/lib/stringex/unidecoder_data/xff.yml +5 -5
- data/lib/stringex.rb +1 -2
- data/locales/da.yml +2 -1
- data/locales/de.yml +1 -0
- data/locales/en.yml +1 -0
- data/locales/fr.yml +72 -0
- data/locales/nb.yml +76 -0
- data/locales/nl.yml +69 -0
- data/locales/no.yml +76 -0
- data/locales/pl.yml +88 -0
- data/locales/pt-BR.yml +1 -0
- data/locales/ru.yml +1 -0
- data/locales/sv.yml +76 -0
- data/stringex.gemspec +38 -59
- data/test/unit/acts_as_url/adapter/{active_record.rb → activerecord.rb} +4 -5
- data/test/unit/acts_as_url/adapter/{data_mapper.rb → datamapper.rb} +2 -3
- data/test/unit/acts_as_url/adapter/mongoid.rb +18 -11
- data/test/unit/acts_as_url_configuration_test.rb +2 -2
- data/test/unit/acts_as_url_integration_test.rb +169 -73
- data/test/unit/localization/da_test.rb +3 -2
- data/test/unit/localization/de_test.rb +1 -0
- data/test/unit/localization/default_test.rb +2 -0
- data/test/unit/localization/en_test.rb +1 -0
- data/test/unit/localization/fr_test.rb +118 -0
- data/test/unit/localization/nl_test.rb +118 -0
- data/test/unit/localization/pl_test.rb +118 -0
- data/test/unit/localization/pt_br_test.rb +118 -0
- data/test/unit/localization/ru_test.rb +2 -1
- data/test/unit/localization/sv_test.rb +118 -0
- data/test/unit/localization_test.rb +39 -19
- data/test/unit/string_extensions_test.rb +60 -6
- data/test/unit/unicode_point_suite/basic_greek_test.rb +1 -1
- data/test/unit/unicode_point_suite/basic_latin_test.rb +3 -1
- data/test/unit/unidecoder_test.rb +2 -1
- metadata +47 -94
- data/README.rdoc +0 -131
- data/test/unit/redcloth_to_html_test.rb +0 -37
@@ -1,4 +1,4 @@
|
|
1
|
-
# encoding:
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require "test_helper"
|
4
4
|
require "stringex"
|
@@ -7,6 +7,16 @@ if RUBY_VERSION.to_f < 1.9
|
|
7
7
|
$KCODE = "U"
|
8
8
|
end
|
9
9
|
|
10
|
+
# Try loading RedCloth but it's okay if it's not there
|
11
|
+
begin
|
12
|
+
gem 'RedCloth'
|
13
|
+
rescue LoadError
|
14
|
+
puts
|
15
|
+
puts ">> Could not load RedCloth. String#to_html was not tested."
|
16
|
+
puts ">> Please gem install RedCloth if you'd like to use this functionality."
|
17
|
+
puts
|
18
|
+
end
|
19
|
+
|
10
20
|
class StringExtensionsTest < Test::Unit::TestCase
|
11
21
|
def setup
|
12
22
|
Stringex::Localization.reset!
|
@@ -78,15 +88,24 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
78
88
|
"zut-alors",
|
79
89
|
"Rabbits aren't real" =>
|
80
90
|
"rabbits-arent-real",
|
81
|
-
"R" =>
|
82
|
-
"r",
|
83
91
|
"R$ isn't R" =>
|
84
|
-
"reais-isnt-r"
|
92
|
+
"reais-isnt-r",
|
93
|
+
"Last Friday Night (T.G.I.F.)" =>
|
94
|
+
"last-friday-night-tgif",
|
95
|
+
"foo` bar" =>
|
96
|
+
"foo-bar",
|
97
|
+
"foo~ bar" =>
|
98
|
+
"foo-bar"
|
85
99
|
}.each do |html, plain|
|
86
100
|
assert_equal plain, html.to_url
|
87
101
|
end
|
88
102
|
end
|
89
103
|
|
104
|
+
def test_to_url_with_danish_characters
|
105
|
+
Stringex::Localization.locale = :da
|
106
|
+
assert_equal "roedgroed-med-floede", "Rødgrød med fløde".to_url
|
107
|
+
end
|
108
|
+
|
90
109
|
def test_to_url_with_excludes
|
91
110
|
assert_equal "So Fucking Special", "So Fucking Special".to_url(:exclude => "So Fucking Special")
|
92
111
|
end
|
@@ -103,6 +122,10 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
103
122
|
assert_equal "under_scores", "Under Scores".to_url(:replace_whitespace_with => "_")
|
104
123
|
end
|
105
124
|
|
125
|
+
def test_to_url_with_alternate_whitespace_replacement_and_with_limit_and_with_truncate_words_disabled
|
126
|
+
assert_equal "i_am_much", "I am much too long".to_url(:replace_whitespace_with => "_", :limit => 12, :truncate_words => false)
|
127
|
+
end
|
128
|
+
|
106
129
|
def test_remove_formatting
|
107
130
|
{
|
108
131
|
"<p>This has 100% too much <em>formatting</em></p>" =>
|
@@ -144,11 +167,11 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
144
167
|
|
145
168
|
def test_localized_vulgar_fractions_conversion
|
146
169
|
Stringex::Localization.backend = :internal
|
147
|
-
Stringex::Localization.store_translations :
|
170
|
+
Stringex::Localization.store_translations :da, :vulgar_fractions, {
|
148
171
|
:one_fourth => "en fjerdedel",
|
149
172
|
:half => "en halv"
|
150
173
|
}
|
151
|
-
Stringex::Localization.locale = :
|
174
|
+
Stringex::Localization.locale = :da
|
152
175
|
|
153
176
|
{
|
154
177
|
"¼" => "en fjerdedel",
|
@@ -264,4 +287,35 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
264
287
|
end
|
265
288
|
end
|
266
289
|
end
|
290
|
+
|
291
|
+
def test_remove_nonreadable_characters
|
292
|
+
cases = { "Jörg Immendor\u0014. Les théâtres" => "jorg-immendor-les-theatres",
|
293
|
+
}
|
294
|
+
cases.each do |plain, converted|
|
295
|
+
assert_equal converted, plain.to_url
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
if defined?(RedCloth)
|
300
|
+
def test_to_html
|
301
|
+
{
|
302
|
+
"h1. A Solution" => "<h1>A Solution</h1>",
|
303
|
+
"I hated wrapping textilize around a string.\n\nIt always felt dirty." =>
|
304
|
+
"<p>I hated wrapping textilize around a string.</p>\n<p>It always felt dirty.</p>",
|
305
|
+
"I think _this_ is awesome" => "<p>I think <em>this</em> is awesome</p>",
|
306
|
+
"Um... _*really*_, man" => "<p>Um… <em><strong>really</strong></em>, man</p>"
|
307
|
+
}.each do |plain, html|
|
308
|
+
assert_equal html, plain.to_html
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
def test_to_html_lite
|
313
|
+
{
|
314
|
+
"I have no pee on me" => "I have no pee on me",
|
315
|
+
"But I _do_ get Textile!" => "But I <em>do</em> get Textile!"
|
316
|
+
}.each do |plain, html|
|
317
|
+
assert_equal html, plain.to_html(:lite)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
267
321
|
end
|
@@ -108,7 +108,9 @@ class BasicLatinTest < Test::Unit::TestCase
|
|
108
108
|
end
|
109
109
|
|
110
110
|
def test_grave_accents
|
111
|
-
assert_equal_encoded "'", %w{
|
111
|
+
assert_equal_encoded "'", %w{02cb 2035}
|
112
|
+
# Ascii grave accent should remain as ascii!
|
113
|
+
assert_equal_encoded "`", "0060"
|
112
114
|
end
|
113
115
|
|
114
116
|
def test_bars
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# encoding: UTF-8
|
2
2
|
|
3
3
|
require "test_helper"
|
4
|
-
require "stringex"
|
4
|
+
require "stringex/unidecoder"
|
5
5
|
|
6
6
|
class UnidecoderTest < Test::Unit::TestCase
|
7
7
|
# Silly phrases courtesy of Frank da Cruz
|
@@ -61,6 +61,7 @@ class UnidecoderTest < Test::Unit::TestCase
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def test_to_ascii
|
64
|
+
require "stringex/core_ext"
|
64
65
|
DONT_CONVERT.each do |ascii|
|
65
66
|
assert_equal ascii, ascii.to_ascii
|
66
67
|
end
|
metadata
CHANGED
@@ -1,170 +1,114 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stringex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Norris
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - '='
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 3.2.13
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - '='
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 3.2.13
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: dm-core
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - '='
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 1.2.0
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - '='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 1.2.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: dm-migrations
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 1.2.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 1.2.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: dm-sqlite-adapter
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - '='
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.2.0
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - '='
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.2.0
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: dm-validations
|
14
|
+
name: jeweler
|
71
15
|
requirement: !ruby/object:Gem::Requirement
|
72
16
|
requirements:
|
73
17
|
- - '='
|
74
18
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
19
|
+
version: 2.3.7
|
76
20
|
type: :development
|
77
21
|
prerelease: false
|
78
22
|
version_requirements: !ruby/object:Gem::Requirement
|
79
23
|
requirements:
|
80
24
|
- - '='
|
81
25
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
26
|
+
version: 2.3.7
|
83
27
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
28
|
+
name: travis-lint
|
85
29
|
requirement: !ruby/object:Gem::Requirement
|
86
30
|
requirements:
|
87
31
|
- - '='
|
88
32
|
- !ruby/object:Gem::Version
|
89
|
-
version: 1.
|
33
|
+
version: 1.7.0
|
90
34
|
type: :development
|
91
35
|
prerelease: false
|
92
36
|
version_requirements: !ruby/object:Gem::Requirement
|
93
37
|
requirements:
|
94
38
|
- - '='
|
95
39
|
- !ruby/object:Gem::Version
|
96
|
-
version: 1.
|
40
|
+
version: 1.7.0
|
97
41
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
42
|
+
name: RedCloth
|
99
43
|
requirement: !ruby/object:Gem::Requirement
|
100
44
|
requirements:
|
101
45
|
- - '='
|
102
46
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
47
|
+
version: 4.2.9
|
104
48
|
type: :development
|
105
49
|
prerelease: false
|
106
50
|
version_requirements: !ruby/object:Gem::Requirement
|
107
51
|
requirements:
|
108
52
|
- - '='
|
109
53
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
54
|
+
version: 4.2.9
|
111
55
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
56
|
+
name: sqlite3
|
113
57
|
requirement: !ruby/object:Gem::Requirement
|
114
58
|
requirements:
|
115
59
|
- - '='
|
116
60
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
61
|
+
version: 1.3.10
|
118
62
|
type: :development
|
119
63
|
prerelease: false
|
120
64
|
version_requirements: !ruby/object:Gem::Requirement
|
121
65
|
requirements:
|
122
66
|
- - '='
|
123
67
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
68
|
+
version: 1.3.10
|
125
69
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
70
|
+
name: test-unit
|
127
71
|
requirement: !ruby/object:Gem::Requirement
|
128
72
|
requirements:
|
129
73
|
- - '='
|
130
74
|
- !ruby/object:Gem::Version
|
131
|
-
version:
|
75
|
+
version: 3.0.9
|
132
76
|
type: :development
|
133
77
|
prerelease: false
|
134
78
|
version_requirements: !ruby/object:Gem::Requirement
|
135
79
|
requirements:
|
136
80
|
- - '='
|
137
81
|
- !ruby/object:Gem::Version
|
138
|
-
version:
|
82
|
+
version: 3.0.9
|
139
83
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
84
|
+
name: activerecord
|
141
85
|
requirement: !ruby/object:Gem::Requirement
|
142
86
|
requirements:
|
143
87
|
- - '='
|
144
88
|
- !ruby/object:Gem::Version
|
145
|
-
version: 1.
|
89
|
+
version: 5.1.4
|
146
90
|
type: :development
|
147
91
|
prerelease: false
|
148
92
|
version_requirements: !ruby/object:Gem::Requirement
|
149
93
|
requirements:
|
150
94
|
- - '='
|
151
95
|
- !ruby/object:Gem::Version
|
152
|
-
version: 1.
|
96
|
+
version: 5.1.4
|
153
97
|
- !ruby/object:Gem::Dependency
|
154
98
|
name: i18n
|
155
99
|
requirement: !ruby/object:Gem::Requirement
|
156
100
|
requirements:
|
157
101
|
- - '='
|
158
102
|
- !ruby/object:Gem::Version
|
159
|
-
version: 0.
|
103
|
+
version: 0.7.0
|
160
104
|
type: :development
|
161
105
|
prerelease: false
|
162
106
|
version_requirements: !ruby/object:Gem::Requirement
|
163
107
|
requirements:
|
164
108
|
- - '='
|
165
109
|
- !ruby/object:Gem::Version
|
166
|
-
version: 0.
|
167
|
-
description:
|
110
|
+
version: 0.7.0
|
111
|
+
description: 'Some [hopefully] useful extensions to Ruby''s String class. Stringex
|
168
112
|
is made up of three libraries: ActsAsUrl [permalink solution with better character
|
169
113
|
translation], Unidecoder [Unicode to ASCII transliteration], and StringExtensions
|
170
114
|
[miscellaneous helper methods for the String class].'
|
@@ -173,11 +117,10 @@ executables: []
|
|
173
117
|
extensions: []
|
174
118
|
extra_rdoc_files:
|
175
119
|
- MIT-LICENSE
|
176
|
-
- README.rdoc
|
177
120
|
files:
|
178
121
|
- Gemfile
|
179
122
|
- MIT-LICENSE
|
180
|
-
- README.
|
123
|
+
- README.md
|
181
124
|
- Rakefile
|
182
125
|
- VERSION
|
183
126
|
- init.rb
|
@@ -194,6 +137,7 @@ files:
|
|
194
137
|
- lib/stringex/configuration/configurator.rb
|
195
138
|
- lib/stringex/configuration/string_extensions.rb
|
196
139
|
- lib/stringex/configuration_lite.rb
|
140
|
+
- lib/stringex/core_ext.rb
|
197
141
|
- lib/stringex/localization.rb
|
198
142
|
- lib/stringex/localization/backend/base.rb
|
199
143
|
- lib/stringex/localization/backend/i18n.rb
|
@@ -389,13 +333,19 @@ files:
|
|
389
333
|
- locales/da.yml
|
390
334
|
- locales/de.yml
|
391
335
|
- locales/en.yml
|
336
|
+
- locales/fr.yml
|
337
|
+
- locales/nb.yml
|
338
|
+
- locales/nl.yml
|
339
|
+
- locales/no.yml
|
340
|
+
- locales/pl.yml
|
392
341
|
- locales/pt-BR.yml
|
393
342
|
- locales/ru.yml
|
343
|
+
- locales/sv.yml
|
394
344
|
- stringex.gemspec
|
395
345
|
- test/performance/localization_performance_test.rb
|
396
346
|
- test/test_helper.rb
|
397
|
-
- test/unit/acts_as_url/adapter/
|
398
|
-
- test/unit/acts_as_url/adapter/
|
347
|
+
- test/unit/acts_as_url/adapter/activerecord.rb
|
348
|
+
- test/unit/acts_as_url/adapter/datamapper.rb
|
399
349
|
- test/unit/acts_as_url/adapter/mongoid.rb
|
400
350
|
- test/unit/acts_as_url_configuration_test.rb
|
401
351
|
- test/unit/acts_as_url_integration_test.rb
|
@@ -403,10 +353,14 @@ files:
|
|
403
353
|
- test/unit/localization/de_test.rb
|
404
354
|
- test/unit/localization/default_test.rb
|
405
355
|
- test/unit/localization/en_test.rb
|
356
|
+
- test/unit/localization/fr_test.rb
|
357
|
+
- test/unit/localization/nl_test.rb
|
358
|
+
- test/unit/localization/pl_test.rb
|
359
|
+
- test/unit/localization/pt_br_test.rb
|
406
360
|
- test/unit/localization/ru_test.rb
|
361
|
+
- test/unit/localization/sv_test.rb
|
407
362
|
- test/unit/localization_18n_failure_test.rb
|
408
363
|
- test/unit/localization_test.rb
|
409
|
-
- test/unit/redcloth_to_html_test.rb
|
410
364
|
- test/unit/string_extensions_configuration_test.rb
|
411
365
|
- test/unit/string_extensions_test.rb
|
412
366
|
- test/unit/unicode_point_suite/basic_greek_test.rb
|
@@ -420,29 +374,28 @@ homepage: http://github.com/rsl/stringex
|
|
420
374
|
licenses:
|
421
375
|
- MIT
|
422
376
|
metadata: {}
|
423
|
-
post_install_message:
|
377
|
+
post_install_message:
|
424
378
|
rdoc_options:
|
425
|
-
- --main
|
379
|
+
- "--main"
|
426
380
|
- README.rdoc
|
427
|
-
- --charset
|
381
|
+
- "--charset"
|
428
382
|
- utf-8
|
429
|
-
- --line-numbers
|
383
|
+
- "--line-numbers"
|
430
384
|
require_paths:
|
431
385
|
- lib
|
432
386
|
required_ruby_version: !ruby/object:Gem::Requirement
|
433
387
|
requirements:
|
434
|
-
- -
|
388
|
+
- - ">="
|
435
389
|
- !ruby/object:Gem::Version
|
436
390
|
version: '0'
|
437
391
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
438
392
|
requirements:
|
439
|
-
- -
|
393
|
+
- - ">="
|
440
394
|
- !ruby/object:Gem::Version
|
441
395
|
version: '0'
|
442
396
|
requirements: []
|
443
|
-
|
444
|
-
|
445
|
-
signing_key:
|
397
|
+
rubygems_version: 3.4.9
|
398
|
+
signing_key:
|
446
399
|
specification_version: 4
|
447
400
|
summary: Some [hopefully] useful extensions to Ruby's String class
|
448
401
|
test_files: []
|
data/README.rdoc
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
= Stringex {<img src="https://codeclimate.com/github/rsl/stringex.png" />}[https://codeclimate.com/github/rsl/stringex] {<img src="https://travis-ci.org/rsl/stringex.png?branch=master" alt="Build Status" />}[https://travis-ci.org/rsl/stringex]
|
2
|
-
|
3
|
-
Some [hopefully] useful extensions to Ruby's String class. It is made up of three libraries: ActsAsUrl, Unidecoder, and StringExtensions.
|
4
|
-
|
5
|
-
<em>NOTE: Stringex 2.0 [and beyond] drops support for Rails 2. If you need support for that version, use 1.5.1 instead.</em>
|
6
|
-
|
7
|
-
== ActsAsUrl
|
8
|
-
|
9
|
-
<em>NOTE: You can now require 'stringex_lite' instead of 'stringex' and skip loading ActsAsUrl functionality if you don't need it.</em>
|
10
|
-
|
11
|
-
This library is designed to create URI-friendly representations of an attribute, for use in generating urls from your attributes. Basic usage is just calling the method:
|
12
|
-
|
13
|
-
# Inside your model
|
14
|
-
acts_as_url :title
|
15
|
-
|
16
|
-
which will populate the <tt>url</tt> attribute on the object with the converted contents of the <tt>title</tt> attribute. This behavior can be customized by adding the following options to the arguments of the <tt>acts_as_url</tt> method:
|
17
|
-
|
18
|
-
<tt>:url_attribute</tt>:: The name of the attribute to use for storing the generated url string.
|
19
|
-
Default is <tt>:url</tt>
|
20
|
-
<tt>:scope</tt>:: The name of model attribute to scope unique urls to. There is no default here.
|
21
|
-
<tt>:only_when_blank</tt>:: If set to true, the url generation will only happen when <tt>:url_attribute</tt> is
|
22
|
-
blank. Default is false (meaning url generation will happen always).
|
23
|
-
<tt>:sync_url</tt>:: If set to true, the url field will be updated when changes are made to the
|
24
|
-
attribute it is based on. Default is false.
|
25
|
-
<tt>:allow_slash</tt>:: If set to true, the url field will not convert slashes. Default is false.
|
26
|
-
<tt>:allow_duplicates</tt>:: If set to true, unique urls will not be enforced.
|
27
|
-
Default is false. <em>NOTE: This is strongly not recommended
|
28
|
-
if you are routing solely on the generated slug as you will no longer
|
29
|
-
be guaranteed to lookup the expected record based on a duplicate slug.</em>
|
30
|
-
<tt>:limit</tt>:: If set, will limit length of url generated. Default is nil.
|
31
|
-
|
32
|
-
In order to use the generated url attribute, you will probably want to override <tt>to_param</tt> like so, in your Model:
|
33
|
-
|
34
|
-
# Inside your model
|
35
|
-
def to_param
|
36
|
-
url # or whatever you set :url_attribute to
|
37
|
-
end
|
38
|
-
|
39
|
-
Routing called via named routes like <tt>foo_path(@foo)</tt> will automatically use the url. In your controllers you will need to call <tt>Foo.find_by_url(params[:id])</tt> instead of the regular find. Don't look for <tt>params[:url]</tt> unless you set it explicitly in the routing, <tt>to_param</tt> will generate <tt>params[:id]</tt>.
|
40
|
-
|
41
|
-
Note that if you add <tt>acts_as_url</tt> to an existing model, the <tt>url</tt> database column will initially be blank. To set this column for your existing instances, you can use the <tt>initialize_urls</tt> method. So if your class is <tt>Post</tt>, just say <tt>Post.initialize_urls</tt>.
|
42
|
-
|
43
|
-
Unlike other permalink solutions, ActsAsUrl doesn't rely on Iconv (which is inconsistent across platforms and doesn't provide great transliteration as is) but instead uses a transliteration scheme (see the code for Unidecoder) which produces much better results for Unicode characters. It also mixes in some custom helpers to translate common characters into a more URI-friendly format rather than just dump them completely. Examples:
|
44
|
-
|
45
|
-
# A simple prelude
|
46
|
-
"simple English".to_url => "simple-english"
|
47
|
-
"it's nothing at all".to_url => "its-nothing-at-all"
|
48
|
-
"rock & roll".to_url => "rock-and-roll"
|
49
|
-
|
50
|
-
# Let's show off
|
51
|
-
"$12 worth of Ruby power".to_url => "12-dollars-worth-of-ruby-power"
|
52
|
-
"10% off if you act now".to_url => "10-percent-off-if-you-act-now"
|
53
|
-
|
54
|
-
# You don't even wanna trust Iconv for this next part
|
55
|
-
"kick it en Français".to_url => "kick-it-en-francais"
|
56
|
-
"rock it Español style".to_url => "rock-it-espanol-style"
|
57
|
-
"tell your readers 你好".to_url => "tell-your-readers-ni-hao"
|
58
|
-
|
59
|
-
Compare those results with the ones produced on my Intel Mac by a leading permalink plugin:
|
60
|
-
|
61
|
-
"simple English" # => "simple-english"
|
62
|
-
"it's nothing at all" # => "it-s-nothing-at-all"
|
63
|
-
"rock & roll" # => "rock-roll"
|
64
|
-
|
65
|
-
"$12 worth of Ruby power" # => "12-worth-of-ruby-power"
|
66
|
-
"10% off if you act now" # => "10-off-if-you-act-now"
|
67
|
-
|
68
|
-
"kick it en Français" # => "kick-it-en-francais"
|
69
|
-
"rock it Español style" # => "rock-it-espan-ol-style"
|
70
|
-
"tell your readers 你好" # => "tell-your-readers"
|
71
|
-
|
72
|
-
Not so great, actually.
|
73
|
-
|
74
|
-
Note: No offense is intended to the author[s] of whatever plugins might produce such results. It's not your faults Iconv sucks.
|
75
|
-
|
76
|
-
== Unidecoder
|
77
|
-
|
78
|
-
This library converts Unicode [and accented ASCII] characters to their plain-text ASCII equivalents. This is a port of Perl's Unidecode and provides eminently superior and more reliable results than Iconv. (Seriously, Iconv... A plague on both your houses! [sic])
|
79
|
-
|
80
|
-
You probably won't ever need to run Unidecoder by itself. StringExtensions adds String#to_ascii which wraps all of Unidecoder's functionality. For anyone interested, details of the implementation can be read about in the original implementation of Text::Unidecode[http://interglacial.com/~sburke/tpj/as_html/tpj22.html]. Extensive examples can be found in the tests.
|
81
|
-
|
82
|
-
Unidecoder module also provides localization options for Stringex. You can use this functionality by loading either a YAML file or Hash like the following code snippets:
|
83
|
-
|
84
|
-
# Using a Hash
|
85
|
-
Stringex.localize_from :en => {"é" => "ee"}
|
86
|
-
|
87
|
-
# Loading from a file. NOTE: The path to file should be absolute.
|
88
|
-
Stringex.localize_from "/path/to/yaml_file"
|
89
|
-
|
90
|
-
In both the YAML and pure Hash implementation, the end result should be a Hash with keys representing the locale and values being another Hash with those keys being the UTF character and the values the transliterated ASCII values. (I hope that made sense.) You can check the documentation for the Unidecoder module for more information about setting locales.
|
91
|
-
|
92
|
-
== StringExtensions
|
93
|
-
|
94
|
-
A small collection of extensions on Ruby's String class. Please see the documentation for StringExtensions module for more information. There's not much to explain about them really.
|
95
|
-
|
96
|
-
== Localization
|
97
|
-
|
98
|
-
With Stringex version 2.0 and higher, you can localize the different conversions in Stringex. Read more here[https://github.com/rsl/stringex/wiki/Localization-of-Stringex-conversions]. If you add a new language, please submit a pull request so we can make it available to other users also.
|
99
|
-
|
100
|
-
== Ruby on Rails Usage
|
101
|
-
|
102
|
-
When using Stringex with Ruby on Rails, you automatically get built-in translations for miscellaneous characters, HTML entities, and vulgar fractions. You can see Stringex's standard translations here[https://github.com/rsl/stringex/tree/master/locales].
|
103
|
-
|
104
|
-
Currently, built-in translations are available for the following languages:
|
105
|
-
|
106
|
-
* English (en)
|
107
|
-
* Danish (da)
|
108
|
-
* German (de)
|
109
|
-
* Portuguese Brazilian (pt-BR)
|
110
|
-
* Russian (ru)
|
111
|
-
|
112
|
-
|
113
|
-
You can easily add your own or customize the built-in translations - read here[https://github.com/rsl/stringex/wiki/Localization-of-Stringex-conversions]. If you add a new language, please submit a pull request so we can make it available to other users also.
|
114
|
-
|
115
|
-
If you don't want to use the Stringex built-in translations, you can force Stringex to use English (or another language), regardless what is in your +I18n.locale+. In an initializer, e.g. +config/initializers/stringex.rb+:
|
116
|
-
|
117
|
-
Stringex::Localization.locale = :en
|
118
|
-
|
119
|
-
== CanCan Usage Note
|
120
|
-
|
121
|
-
You'll need to add a <tt>:find_by => :url</tt> to your <tt>load_and_authorize_resource</tt>. Here's an example:
|
122
|
-
|
123
|
-
load_and_authorize_resource :class => "Whatever", :message => "Not authorized", :find_by => :url
|
124
|
-
|
125
|
-
== Thanks & Acknowledgements
|
126
|
-
|
127
|
-
If it's not obvious, some of the code for ActsAsUrl is based on Rick Olsen's permalink_fu[http://svn.techno-weenie.net/projects/plugins/permalink_fu/] plugin. Unidecoder is a Ruby port of Sean Burke's Text::Unidecode[http://interglacial.com/~sburke/tpj/as_html/tpj22.html] module for Perl. And, finally, the bulk of strip_html_tags[link:classes/Stringex/StringExtensions.html#M000005] in StringExtensions was stolen from Tobias Lütke's Regex in Typo[http://typosphere.org/].
|
128
|
-
|
129
|
-
GIANT thanks to the many contributors who have helped make Stringex better and better: http://github.com/rsl/stringex/contributors
|
130
|
-
|
131
|
-
copyright (c) 2008-2012 Lucky Sneaks, released under the MIT license
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
require 'stringex'
|
3
|
-
|
4
|
-
begin
|
5
|
-
require 'rubygems'
|
6
|
-
require 'RedCloth'
|
7
|
-
rescue LoadError
|
8
|
-
puts
|
9
|
-
puts ">> Could not load RedCloth. String#to_html was not tested."
|
10
|
-
puts ">> Please gem install RedCloth if you'd like to use this functionality."
|
11
|
-
puts
|
12
|
-
end
|
13
|
-
|
14
|
-
class RedclothToHTMLTest < Test::Unit::TestCase
|
15
|
-
if defined?(RedCloth)
|
16
|
-
def test_to_html
|
17
|
-
{
|
18
|
-
"h1. A Solution" => "<h1>A Solution</h1>",
|
19
|
-
"I hated wrapping textilize around a string.\n\nIt always felt dirty." =>
|
20
|
-
"<p>I hated wrapping textilize around a string.</p>\n<p>It always felt dirty.</p>",
|
21
|
-
"I think _this_ is awesome" => "<p>I think <em>this</em> is awesome</p>",
|
22
|
-
"Um... _*really*_, man" => "<p>Um… <em><strong>really</strong></em>, man</p>"
|
23
|
-
}.each do |plain, html|
|
24
|
-
assert_equal html, plain.to_html
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_to_html_lite
|
29
|
-
{
|
30
|
-
"I have no pee on me" => "I have no pee on me",
|
31
|
-
"But I _do_ get Textile!" => "But I <em>do</em> get Textile!"
|
32
|
-
}.each do |plain, html|
|
33
|
-
assert_equal html, plain.to_html(:lite)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|