stringex 2.0.2 → 2.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- 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 +20 -5
- data/lib/stringex/acts_as_url/adapter/data_mapper.rb +3 -9
- data/lib/stringex/acts_as_url/adapter/mongoid.rb +1 -1
- data/lib/stringex/configuration/acts_as_url.rb +1 -0
- data/lib/stringex/localization.rb +1 -1
- data/lib/stringex/localization/conversion_expressions.rb +3 -1
- data/lib/stringex/string_extensions.rb +1 -1
- data/locales/da.yml +2 -0
- data/locales/en.yml +2 -0
- data/locales/pt-BR.yml +68 -0
- data/stringex.gemspec +3 -2
- data/test/acts_as_url_integration_test.rb +35 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmMxOWVlZjNkYzk5YTMyOWM1MGViNWNjZWE3Y2EyYzc4OGNiZTJiNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NWM2ZjYwODhmZDU3ZDk0MzQzM2U4YmE2MGE5YzE0MzhmYzVmZWI5YQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MGI1Y2FiMGVhOGNmMjE4MmQwZDMyYjkwNzY2YzA0ZWQwN2I5NjAzZTZiODll
|
10
|
+
ZDRkZTdlOWVhMDkxYmQxOTE2OWYyM2IwZjdjMzk4ZTRmMGE2M2ZjYTBjYjdj
|
11
|
+
MDNhNDExZTIyNGJjMDE3OTk1NjA3NWFjMjFlYzYxMzI5ZDA1MjQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTdlMjBlMWZmOGQ4YzBiNjk1MWExNGQyNTRiOTgxYjUxZjY1OTUwZTg3Mzgy
|
14
|
+
MWNhNzQ2YmQ2NjQ1MjM2YjAwMDBjYmUwZTRiN2JiZGIyZTJhNTlhMGJjNzIy
|
15
|
+
MzYyZGNjNGRiZjNiMDQ4MjA5Yzg5NTk5ZWMyODBjOGY0N2ZhNTM=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.3
|
@@ -2,7 +2,7 @@ module Stringex
|
|
2
2
|
module ActsAsUrl
|
3
3
|
module Adapter
|
4
4
|
class Base
|
5
|
-
attr_accessor :base_url, :configuration, :instance, :klass, :settings
|
5
|
+
attr_accessor :base_url, :callback_options, :configuration, :instance, :klass, :settings
|
6
6
|
|
7
7
|
def initialize(configuration)
|
8
8
|
ensure_loadable
|
@@ -12,6 +12,7 @@ module Stringex
|
|
12
12
|
|
13
13
|
def create_callbacks!(klass)
|
14
14
|
self.klass = klass
|
15
|
+
self.callback_options = {}
|
15
16
|
create_method_to_callback
|
16
17
|
create_callback
|
17
18
|
end
|
@@ -68,10 +69,24 @@ module Stringex
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def create_callback
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
72
|
+
klass.send klass_callback_method, :ensure_unique_url, callback_options
|
73
|
+
end
|
74
|
+
|
75
|
+
def klass_callback_method
|
76
|
+
settings.sync_url ? klass_sync_url_callback_method : klass_non_sync_url_callback_method
|
77
|
+
end
|
78
|
+
|
79
|
+
def klass_sync_url_callback_method
|
80
|
+
configuration.settings.callback_method
|
81
|
+
end
|
82
|
+
|
83
|
+
def klass_non_sync_url_callback_method
|
84
|
+
case configuration.settings.callback_method
|
85
|
+
when :before_save
|
86
|
+
:before_create
|
87
|
+
else # :before_validation
|
88
|
+
callback_options[:on] = :create
|
89
|
+
configuration.settings.callback_method
|
75
90
|
end
|
76
91
|
end
|
77
92
|
|
@@ -11,14 +11,8 @@ module Stringex
|
|
11
11
|
private
|
12
12
|
|
13
13
|
def create_callback
|
14
|
-
|
15
|
-
|
16
|
-
before :save, :ensure_unique_url
|
17
|
-
end
|
18
|
-
else
|
19
|
-
klass.class_eval do
|
20
|
-
before :create, :ensure_unique_url
|
21
|
-
end
|
14
|
+
klass.class_eval do
|
15
|
+
before acts_as_url_configuration.settings.sync_url ? :save : :create, :ensure_unique_url
|
22
16
|
end
|
23
17
|
end
|
24
18
|
|
@@ -39,7 +33,7 @@ module Stringex
|
|
39
33
|
end
|
40
34
|
|
41
35
|
def klass_previous_instances(&block)
|
42
|
-
klass.all(:conditions => {settings.url_attribute => nil}).each(&block)
|
36
|
+
klass.all(:conditions => {settings.url_attribute => [nil]}).each(&block)
|
43
37
|
end
|
44
38
|
|
45
39
|
def primary_key
|
@@ -25,7 +25,7 @@ module Stringex
|
|
25
25
|
}
|
26
26
|
|
27
27
|
# Things that just get converted to spaces
|
28
|
-
CLEANUP_CHARACTERS = /[\.,:;(){}\[\]
|
28
|
+
CLEANUP_CHARACTERS = /[\.,:;(){}\[\]\?!\^'ʼ"_\|]/
|
29
29
|
CLEANUP_HTML_ENTITIES = /&[^;]+;/
|
30
30
|
|
31
31
|
CURRENCIES_SUPPORTED_SIMPLE = {
|
@@ -33,11 +33,13 @@ module Stringex
|
|
33
33
|
:euros => /€/,
|
34
34
|
:pounds => /£/,
|
35
35
|
:yen => /¥/,
|
36
|
+
:reais => /R$/
|
36
37
|
}
|
37
38
|
CURRENCIES_SUPPORTED_COMPLEX = {
|
38
39
|
:dollars => :dollars_cents,
|
39
40
|
:euros => :euros_cents,
|
40
41
|
:pounds => :pounds_pence,
|
42
|
+
:reais => :reais_cents
|
41
43
|
}
|
42
44
|
CURRENCIES_SUPPORTED = Regexp.new(CURRENCIES_SUPPORTED_SIMPLE.values.join('|'))
|
43
45
|
CURRENCIES_SIMPLE = CURRENCIES_SUPPORTED_SIMPLE.inject({}) do |hash, content|
|
@@ -52,7 +52,7 @@ module Stringex
|
|
52
52
|
# you should run any methods which convert HTML entities (convert_accented_html_entities and convert_miscellaneous_html_entities)
|
53
53
|
# before running this method.
|
54
54
|
def convert_miscellaneous_characters(options = {})
|
55
|
-
stringex_convert do
|
55
|
+
stringex_convert(options) do
|
56
56
|
translate! :ellipses, :currencies, :abbreviations, :characters, :apostrophes
|
57
57
|
cleanup_characters!
|
58
58
|
end
|
data/locales/da.yml
CHANGED
data/locales/en.yml
CHANGED
data/locales/pt-BR.yml
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# NOTE: Some translation keys make use of matches from regular expressions
|
2
|
+
# to manipulate whitespace and order. Please consult the source code for
|
3
|
+
# Stringex::Localization::ConversionExpressions to see what those
|
4
|
+
# regular expressions look like if you need to manipulate the order
|
5
|
+
# differently than the usage below.
|
6
|
+
pt-BR:
|
7
|
+
stringex:
|
8
|
+
characters:
|
9
|
+
and: e
|
10
|
+
at: em
|
11
|
+
divide: dividido por
|
12
|
+
degrees: graus
|
13
|
+
dot: \1 ponto \2
|
14
|
+
ellipsis: reticências
|
15
|
+
equals: igual à
|
16
|
+
number: número
|
17
|
+
percent: porcento
|
18
|
+
plus: mais
|
19
|
+
slash: barra
|
20
|
+
star: estrela
|
21
|
+
currencies:
|
22
|
+
dollars: \1 dólares
|
23
|
+
dollars_cents: \1 dólares \2 cents
|
24
|
+
pounds: \1 libras
|
25
|
+
pounds_pence: \1 libras \2 centavos
|
26
|
+
euros: \1 euros
|
27
|
+
euros_cents: \1 euros \2 cents
|
28
|
+
yen: \1 yen
|
29
|
+
reais: \1 reais
|
30
|
+
reais_cents: \1 reais \2 centavos
|
31
|
+
html_entities:
|
32
|
+
amp: e
|
33
|
+
cent: " centavos"
|
34
|
+
copy: (c)
|
35
|
+
deg: " graus "
|
36
|
+
divide: " dividido por "
|
37
|
+
double_quote: '"'
|
38
|
+
ellipsis: "..."
|
39
|
+
en_dash: "-"
|
40
|
+
em_dash: "--"
|
41
|
+
frac14: um quarto
|
42
|
+
frac12: metade
|
43
|
+
frac34: três quartos
|
44
|
+
gt: ">"
|
45
|
+
lt: <
|
46
|
+
nbsp: " "
|
47
|
+
pound: " libras "
|
48
|
+
reg: (r)
|
49
|
+
single_quote: "'"
|
50
|
+
times: x
|
51
|
+
trade: (tm)
|
52
|
+
yen: " yen "
|
53
|
+
vulgar_fractions:
|
54
|
+
half: metade
|
55
|
+
one_third: um terço
|
56
|
+
two_thirds: dois terços
|
57
|
+
one_fourth: um quarto
|
58
|
+
three_fourths: três quartos
|
59
|
+
one_fifth: um quinto
|
60
|
+
two_fifths: dois quintos
|
61
|
+
three_fifths: três quintos
|
62
|
+
four_fifths: quatro quintos
|
63
|
+
one_sixth: um sexto
|
64
|
+
five_sixths: cinco sextos
|
65
|
+
one_eighth: um oitavo
|
66
|
+
three_eighths: três oitavos
|
67
|
+
five_eighths: cinco oitavos
|
68
|
+
seven_eighths: sete oitavos
|
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.0.
|
8
|
+
s.version = "2.0.3"
|
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 = "2013-06-
|
12
|
+
s.date = "2013-06-17"
|
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 = [
|
@@ -228,6 +228,7 @@ Gem::Specification.new do |s|
|
|
228
228
|
"lib/stringex/version.rb",
|
229
229
|
"locales/da.yml",
|
230
230
|
"locales/en.yml",
|
231
|
+
"locales/pt-BR.yml",
|
231
232
|
"stringex.gemspec",
|
232
233
|
"test/acts_as_url/adapter/active_record.rb",
|
233
234
|
"test/acts_as_url/adapter/data_mapper.rb",
|
@@ -188,6 +188,23 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
188
188
|
end
|
189
189
|
end
|
190
190
|
|
191
|
+
def test_should_mass_initialize_empty_string_urls
|
192
|
+
@doc = Document.create(:title => "Initial")
|
193
|
+
@other_doc = Document.create(:title => "Subsequent")
|
194
|
+
adapter_specific_update @doc, :url => ''
|
195
|
+
adapter_specific_update @other_doc, :url => ''
|
196
|
+
# Just making sure this got unset before the real test
|
197
|
+
assert_equal '', @doc.url
|
198
|
+
assert_equal '', @other_doc.url
|
199
|
+
|
200
|
+
Document.initialize_urls
|
201
|
+
|
202
|
+
@doc.reload
|
203
|
+
@other_doc.reload
|
204
|
+
assert_equal "initial", @doc.url
|
205
|
+
assert_equal "subsequent", @other_doc.url
|
206
|
+
end
|
207
|
+
|
191
208
|
def test_should_allow_using_custom_method_for_generating_url
|
192
209
|
Document.class_eval do
|
193
210
|
acts_as_url :non_attribute_method
|
@@ -291,4 +308,22 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
|
|
291
308
|
@doc_2 = AnotherSTIChildDocument.create(:title => "Unique")
|
292
309
|
assert_equal "unique-1", @doc_2.url
|
293
310
|
end
|
311
|
+
|
312
|
+
def test_should_strip_slashes_by_default
|
313
|
+
Document.class_eval do
|
314
|
+
acts_as_url :title
|
315
|
+
end
|
316
|
+
|
317
|
+
@doc = Document.create(:title => "a b/c d")
|
318
|
+
assert_equal "a-b-slash-c-d", @doc.url
|
319
|
+
end
|
320
|
+
|
321
|
+
def test_should_allow_slashes_to_be_allowed
|
322
|
+
Document.class_eval do
|
323
|
+
acts_as_url :title, :allow_slash => true
|
324
|
+
end
|
325
|
+
|
326
|
+
@doc = Document.create(:title => "a b/c d")
|
327
|
+
assert_equal "a-b/c-d", @doc.url
|
328
|
+
end
|
294
329
|
end
|
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.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Norris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -386,6 +386,7 @@ files:
|
|
386
386
|
- lib/stringex/version.rb
|
387
387
|
- locales/da.yml
|
388
388
|
- locales/en.yml
|
389
|
+
- locales/pt-BR.yml
|
389
390
|
- stringex.gemspec
|
390
391
|
- test/acts_as_url/adapter/active_record.rb
|
391
392
|
- test/acts_as_url/adapter/data_mapper.rb
|