stringex 2.1.0 → 2.2.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.
- checksums.yaml +8 -8
- data/Gemfile +7 -1
- data/README.rdoc +2 -0
- data/VERSION +1 -1
- data/lib/stringex/acts_as_url/adapter/active_record.rb +1 -1
- data/lib/stringex/configuration/acts_as_url.rb +2 -1
- data/lib/stringex/configuration/string_extensions.rb +2 -1
- data/lib/stringex/localization/conversion_expressions.rb +1 -1
- data/lib/stringex/string_extensions.rb +24 -3
- data/stringex.gemspec +5 -5
- data/test/unit/acts_as_url_integration_test.rb +18 -0
- data/test/unit/localization/da_test.rb +1 -1
- data/test/unit/string_extensions_test.rb +10 -3
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGQxMmNjMmIwMzU1MzY0YzdmMWEzZjhiYjI0MTk5ZGE4M2ZiODY0Mg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzkxMzZiYTBmZWM0YWUyYTMyYWY0MDgzNDRhM2IxNmJjZWM2MDZmOQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MmMxMmRmNTg3NGY0Nzg1M2Q2MWM4NTk5M2I0NjAxMjgwNmIwZjljZmEzZmNj
|
10
|
+
MGE4MWYwOGNjYTRkMzM5NzRhMTdjMzI3MWVhNzY4NzBkNTQ2ZTM0YWEzYzE1
|
11
|
+
ZmM1YWY2NmY0MzM5ZDk4MTc2MjQzNWVkZTU5NDNmNjZkZmNlMDM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTA2MjBkMTVkYWVlMzM0MDA4Y2JmODNjMGM4NWM5MjBkZjM3YmJiMmFkZjA4
|
14
|
+
YjQyNDBkOWMwMDE3YmI4ZDkwNjE1ZWQ2ODdjMzMzZTU4OTBmZjE1NDU2NTQ0
|
15
|
+
OGY4ZDA2MWU2MjUyYWM1NTZhNTNjZDRmOTk5NDYwZjcxNTQyMzY=
|
data/Gemfile
CHANGED
@@ -14,7 +14,13 @@ group :development do
|
|
14
14
|
puts "Mongoid requires Ruby higher than 1.8.x"
|
15
15
|
end
|
16
16
|
gem "RedCloth", "4.2.9" # Can I state that I really dislike camelcased gem names?
|
17
|
-
gem "sqlite3", "1.3.7"
|
18
17
|
gem "travis-lint", "1.7.0"
|
19
18
|
gem "i18n", "0.6.1"
|
19
|
+
# For non-Jruby...
|
20
|
+
gem "sqlite3", "1.3.7", :platform => [:ruby, :mswin, :mingw]
|
21
|
+
# And for Jruby...
|
22
|
+
platform :jruby do
|
23
|
+
# gem "jdbc-sqlite3"
|
24
|
+
# gem "activerecord-jdbcsqlite3-adapter"
|
25
|
+
end
|
20
26
|
end
|
data/README.rdoc
CHANGED
@@ -28,6 +28,8 @@ which will populate the <tt>url</tt> attribute on the object with the converted
|
|
28
28
|
if you are routing solely on the generated slug as you will no longer
|
29
29
|
be guaranteed to lookup the expected record based on a duplicate slug.</em>
|
30
30
|
<tt>:limit</tt>:: If set, will limit length of url generated. Default is nil.
|
31
|
+
<tt>:truncate_words</tt>:: Used with :limit. If set to false, the url will be truncated to the last
|
32
|
+
whole word before the limit was reached. Default is true.
|
31
33
|
|
32
34
|
In order to use the generated url attribute, you will probably want to override <tt>to_param</tt> like so, in your Model:
|
33
35
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
@@ -3,7 +3,7 @@
|
|
3
3
|
module Stringex
|
4
4
|
module Localization
|
5
5
|
module ConversionExpressions
|
6
|
-
ABBREVIATION = /(\s|^)([[:alpha:]](\.[[:alpha:]])+(\.?)[[:alpha:]]*(\s|$))/
|
6
|
+
ABBREVIATION = /(\s|\(|^)([[:alpha:]](\.[[:alpha:]])+(\.?)[[:alpha:]]*(\s|\)|$))/
|
7
7
|
|
8
8
|
ACCENTED_HTML_ENTITY = /&([A-Za-z])(grave|acute|circ|tilde|uml|ring|cedil|slash);/
|
9
9
|
|
@@ -94,10 +94,31 @@ module Stringex
|
|
94
94
|
end
|
95
95
|
|
96
96
|
# Returns the string limited in size to the value of limit.
|
97
|
-
def limit(limit = nil)
|
98
|
-
limit.nil?
|
97
|
+
def limit(limit = nil, truncate_words = true)
|
98
|
+
if limit.nil?
|
99
|
+
self
|
100
|
+
else
|
101
|
+
truncate_words == false ? self.whole_word_limit(limit) : self[0...limit]
|
102
|
+
end
|
99
103
|
end
|
100
104
|
|
105
|
+
def whole_word_limit(limit)
|
106
|
+
whole_words = []
|
107
|
+
words = self.split('-')
|
108
|
+
|
109
|
+
words.each do |word|
|
110
|
+
if word.size > limit
|
111
|
+
break
|
112
|
+
else
|
113
|
+
whole_words << word
|
114
|
+
limit -= (word.size + 1)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
whole_words.join('-')
|
119
|
+
end
|
120
|
+
|
121
|
+
|
101
122
|
# Performs multiple text manipulations. Essentially a shortcut for typing them all. View source
|
102
123
|
# below to see which methods are run.
|
103
124
|
def remove_formatting(options = {})
|
@@ -167,7 +188,7 @@ module Stringex
|
|
167
188
|
dummy = remove_formatting(options).
|
168
189
|
replace_whitespace(whitespace_replacement_token).
|
169
190
|
collapse("-").
|
170
|
-
limit(options[:limit])
|
191
|
+
limit(options[:limit], options[:truncate_words])
|
171
192
|
dummy.downcase! unless options[:force_downcase] == false
|
172
193
|
dummy
|
173
194
|
end
|
data/stringex.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "stringex"
|
8
|
-
s.version = "2.
|
8
|
+
s.version = "2.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Russell Norris"]
|
12
|
-
s.date = "
|
12
|
+
s.date = "2014-02-03"
|
13
13
|
s.description = "Some [hopefully] useful extensions to Ruby's String class. Stringex is made up of three libraries: ActsAsUrl [permalink solution with better character translation], Unidecoder [Unicode to ASCII transliteration], and StringExtensions [miscellaneous helper methods for the String class]."
|
14
14
|
s.email = "rsl@luckysneaks.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -280,9 +280,9 @@ Gem::Specification.new do |s|
|
|
280
280
|
s.add_development_dependency(%q<jeweler>, ["= 1.8.4"])
|
281
281
|
s.add_development_dependency(%q<mongoid>, ["= 3.1.4"])
|
282
282
|
s.add_development_dependency(%q<RedCloth>, ["= 4.2.9"])
|
283
|
-
s.add_development_dependency(%q<sqlite3>, ["= 1.3.7"])
|
284
283
|
s.add_development_dependency(%q<travis-lint>, ["= 1.7.0"])
|
285
284
|
s.add_development_dependency(%q<i18n>, ["= 0.6.1"])
|
285
|
+
s.add_development_dependency(%q<sqlite3>, ["= 1.3.7"])
|
286
286
|
else
|
287
287
|
s.add_dependency(%q<activerecord>, ["= 3.2.13"])
|
288
288
|
s.add_dependency(%q<dm-core>, ["= 1.2.0"])
|
@@ -292,9 +292,9 @@ Gem::Specification.new do |s|
|
|
292
292
|
s.add_dependency(%q<jeweler>, ["= 1.8.4"])
|
293
293
|
s.add_dependency(%q<mongoid>, ["= 3.1.4"])
|
294
294
|
s.add_dependency(%q<RedCloth>, ["= 4.2.9"])
|
295
|
-
s.add_dependency(%q<sqlite3>, ["= 1.3.7"])
|
296
295
|
s.add_dependency(%q<travis-lint>, ["= 1.7.0"])
|
297
296
|
s.add_dependency(%q<i18n>, ["= 0.6.1"])
|
297
|
+
s.add_dependency(%q<sqlite3>, ["= 1.3.7"])
|
298
298
|
end
|
299
299
|
else
|
300
300
|
s.add_dependency(%q<activerecord>, ["= 3.2.13"])
|
@@ -305,9 +305,9 @@ Gem::Specification.new do |s|
|
|
305
305
|
s.add_dependency(%q<jeweler>, ["= 1.8.4"])
|
306
306
|
s.add_dependency(%q<mongoid>, ["= 3.1.4"])
|
307
307
|
s.add_dependency(%q<RedCloth>, ["= 4.2.9"])
|
308
|
-
s.add_dependency(%q<sqlite3>, ["= 1.3.7"])
|
309
308
|
s.add_dependency(%q<travis-lint>, ["= 1.7.0"])
|
310
309
|
s.add_dependency(%q<i18n>, ["= 0.6.1"])
|
310
|
+
s.add_dependency(%q<sqlite3>, ["= 1.3.7"])
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
@@ -326,4 +326,22 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
326
326
|
@doc = Document.create(:title => "a b/c d")
|
327
327
|
assert_equal "a-b/c-d", @doc.url
|
328
328
|
end
|
329
|
+
|
330
|
+
def test_should_truncate_words_by_default
|
331
|
+
Document.class_eval do
|
332
|
+
acts_as_url :title, :limit => 20
|
333
|
+
end
|
334
|
+
|
335
|
+
@doc = Document.create(:title => "title with many whole words")
|
336
|
+
assert_equal 'title-with-many-whol', @doc.url
|
337
|
+
end
|
338
|
+
|
339
|
+
def test_should_not_truncate_words
|
340
|
+
Document.class_eval do
|
341
|
+
acts_as_url :title, :limit => 20, :truncate_words => false
|
342
|
+
end
|
343
|
+
|
344
|
+
@doc = Document.create(:title => "title with many whole words")
|
345
|
+
assert_equal 'title-with-many', @doc.url
|
346
|
+
end
|
329
347
|
end
|
@@ -24,7 +24,7 @@ class DanishYAMLLocalizationTest < Test::Unit::TestCase
|
|
24
24
|
"100%" => "100 procent",
|
25
25
|
"cost+tax" => "cost plus tax",
|
26
26
|
"batman/robin fan fiction" => "batman skråstreg robin fan fiction",
|
27
|
-
"dial *69" => "dial stjerne 69"
|
27
|
+
"dial *69" => "dial stjerne 69"
|
28
28
|
# " i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
|
29
29
|
}.each do |original, converted|
|
30
30
|
define_method "test_character_conversion: '#{original}'" do
|
@@ -89,12 +89,19 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
89
89
|
"Rabbits aren't real" =>
|
90
90
|
"rabbits-arent-real",
|
91
91
|
"R$ isn't R" =>
|
92
|
-
"reais-isnt-r"
|
92
|
+
"reais-isnt-r",
|
93
|
+
"Last Friday Night (T.G.I.F.)" =>
|
94
|
+
"last-friday-night-tgif"
|
93
95
|
}.each do |html, plain|
|
94
96
|
assert_equal plain, html.to_url
|
95
97
|
end
|
96
98
|
end
|
97
99
|
|
100
|
+
def test_to_url_with_danish_characters
|
101
|
+
Stringex::Localization.locale = :da
|
102
|
+
assert_equal "roedgroed-med-floede", "Rødgrød med fløde".to_url
|
103
|
+
end
|
104
|
+
|
98
105
|
def test_to_url_with_excludes
|
99
106
|
assert_equal "So Fucking Special", "So Fucking Special".to_url(:exclude => "So Fucking Special")
|
100
107
|
end
|
@@ -152,11 +159,11 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
152
159
|
|
153
160
|
def test_localized_vulgar_fractions_conversion
|
154
161
|
Stringex::Localization.backend = :internal
|
155
|
-
Stringex::Localization.store_translations :
|
162
|
+
Stringex::Localization.store_translations :da, :vulgar_fractions, {
|
156
163
|
:one_fourth => "en fjerdedel",
|
157
164
|
:half => "en halv"
|
158
165
|
}
|
159
|
-
Stringex::Localization.locale = :
|
166
|
+
Stringex::Localization.locale = :da
|
160
167
|
|
161
168
|
{
|
162
169
|
"¼" => "en fjerdedel",
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stringex
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Norris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -123,47 +123,47 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 4.2.9
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: travis-lint
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - '='
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 1.
|
131
|
+
version: 1.7.0
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - '='
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 1.
|
138
|
+
version: 1.7.0
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: i18n
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - '='
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 0.6.1
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - '='
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 0.6.1
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
|
-
name:
|
154
|
+
name: sqlite3
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - '='
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
159
|
+
version: 1.3.7
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - '='
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
166
|
+
version: 1.3.7
|
167
167
|
description: ! 'Some [hopefully] useful extensions to Ruby''s String class. Stringex
|
168
168
|
is made up of three libraries: ActsAsUrl [permalink solution with better character
|
169
169
|
translation], Unidecoder [Unicode to ASCII transliteration], and StringExtensions
|