stringex 2.0.7 → 2.0.8
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/localization.rb +17 -4
- data/lib/stringex/localization/backend/i18n.rb +12 -0
- data/stringex.gemspec +3 -2
- data/test/unit/localization_18n_failure_test.rb +40 -0
- data/test/unit/string_extensions_test.rb +9 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjIzZmNiMzRhOWEzMDA0NDBlMTZjNjRlN2I2MjY4NGQxNGYxNGY4MQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGZmZWVmZTdlMDlmOGY3YTEwMDgzZTUzYTc0NGI3Njc0ODEyNDVhNQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDczOTliYTA2NGFhZjE5NDRmNDk2MjcxYmI1ZDJlMjBhMTVkZWQ0MmE3NDg0
|
10
|
+
YTBkODdmNzk5NmU2ODNmNTllNTA5Y2M1ODE3YTViZTYwYWVkNDgyYTNhMDcw
|
11
|
+
NjJiZDM4NjE0MjlmMDYyYmMwNDdiM2VhOWQ0YTc5Zjk2ZjViNDM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzJkOWQxN2U2NDg0YjQ1NjJjYjIxNGRmNDM0ZThmNmRjZWU1YzQxZWIyNWVh
|
14
|
+
NzQyNzU5ZmU2OGIwNWQ1NTZhOTQyMmZkZWMwNTc1YzY1YjQ5NTU1MmM2MmVk
|
15
|
+
NTQ4OGE1ZTRhOGRjODU5MDU3MTlhZGUxYmZiNTQ4ZjkxZGI3YTg=
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.8
|
@@ -12,15 +12,19 @@ module Stringex
|
|
12
12
|
|
13
13
|
class << self
|
14
14
|
def backend
|
15
|
-
@backend ||=
|
15
|
+
@backend ||= i18n_present? ? Backend::I18n : Backend::Internal
|
16
16
|
end
|
17
17
|
|
18
18
|
def backend=(sym_or_class)
|
19
19
|
if sym_or_class.is_a?(Symbol)
|
20
20
|
@backend = case sym_or_class
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
when :internal
|
22
|
+
Backend::Internal
|
23
|
+
when :i18n
|
24
|
+
ensure_i18n!
|
25
|
+
Backend::I18n
|
26
|
+
else
|
27
|
+
raise "Invalid backend :#{sym_or_class}"
|
24
28
|
end
|
25
29
|
else
|
26
30
|
@backend = sym_or_class
|
@@ -94,6 +98,15 @@ module Stringex
|
|
94
98
|
return unless DefaultConversions.respond_to?(scope)
|
95
99
|
DefaultConversions.send(scope)[key]
|
96
100
|
end
|
101
|
+
|
102
|
+
def i18n_present?
|
103
|
+
defined?(I18n) && I18n.respond_to?(:translate)
|
104
|
+
end
|
105
|
+
|
106
|
+
def ensure_i18n!
|
107
|
+
raise Backend::I18nNotDefined unless defined?(I18n)
|
108
|
+
raise Backend::I18nMissingTranslate unless I18n.respond_to?(:translate)
|
109
|
+
end
|
97
110
|
end
|
98
111
|
end
|
99
112
|
end
|
@@ -56,6 +56,18 @@ module Stringex
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
|
+
|
60
|
+
class I18nNotDefined < RuntimeError
|
61
|
+
def initialize
|
62
|
+
super 'Stringex cannot use I18n backend: I18n is not defined'
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class I18nMissingTranslate < RuntimeError
|
67
|
+
def initialize
|
68
|
+
super 'Stringex cannot use I18n backend: I18n is defined but missing a translate method'
|
69
|
+
end
|
70
|
+
end
|
59
71
|
end
|
60
72
|
end
|
61
73
|
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.0.
|
8
|
+
s.version = "2.0.8"
|
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-07-
|
12
|
+
s.date = "2013-07-31"
|
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 = [
|
@@ -242,6 +242,7 @@ Gem::Specification.new do |s|
|
|
242
242
|
"test/unit/localization/de_test.rb",
|
243
243
|
"test/unit/localization/default_test.rb",
|
244
244
|
"test/unit/localization/en_test.rb",
|
245
|
+
"test/unit/localization_18n_failure_test.rb",
|
245
246
|
"test/unit/localization_test.rb",
|
246
247
|
"test/unit/redcloth_to_html_test.rb",
|
247
248
|
"test/unit/string_extensions_test.rb",
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require 'stringex'
|
3
|
+
|
4
|
+
class LocalizationI18nFailureTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
alias_i18n
|
7
|
+
Stringex::Localization.reset!
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_loading_i18n_backend_fails_if_no_i18n_module
|
11
|
+
assert_raise(Stringex::Localization::Backend::I18nNotDefined) do
|
12
|
+
Stringex::Localization.backend = :i18n
|
13
|
+
end
|
14
|
+
ensure
|
15
|
+
unalias_i18n
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_loading_i18n_backend_fails_if_i18n_defined_without_translate
|
19
|
+
Object.send :const_set, :I18n, Module.new
|
20
|
+
|
21
|
+
assert_raise(Stringex::Localization::Backend::I18nMissingTranslate) do
|
22
|
+
Stringex::Localization.backend = :i18n
|
23
|
+
end
|
24
|
+
ensure
|
25
|
+
Object.send :remove_const, :I18n
|
26
|
+
unalias_i18n
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def alias_i18n
|
32
|
+
Object.send :const_set, :I18nBackup, I18n
|
33
|
+
Object.send :remove_const, :I18n
|
34
|
+
end
|
35
|
+
|
36
|
+
def unalias_i18n
|
37
|
+
Object.send :const_set, :I18n, I18nBackup
|
38
|
+
Object.send :remove_const, :I18nBackup
|
39
|
+
end
|
40
|
+
end
|
@@ -241,11 +241,18 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
241
241
|
|
242
242
|
{
|
243
243
|
"مصدر أمني: مجهولون يطلقون «خرطوش» على متظاهرين بمترو عزبة النخل وإصابة 16" =>
|
244
|
-
"
|
245
|
-
|
244
|
+
"مصدر-أمني-مجهولون-يطلقون-«خرطوش»-على-متظاهرين-بمترو-عزبة-النخل-وإصابة-16",
|
245
|
+
"c'est ça" =>
|
246
|
+
"cest-ça",
|
247
|
+
"la muñeca" =>
|
248
|
+
"la-muñeca"
|
249
|
+
}.each do |original, converted|
|
250
|
+
assert_equal converted, original.to_url
|
251
|
+
end
|
246
252
|
ensure
|
247
253
|
String.class_eval do
|
248
254
|
remove_method :to_ascii
|
255
|
+
|
249
256
|
def to_ascii
|
250
257
|
old_to_ascii
|
251
258
|
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.8
|
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-07-
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -400,6 +400,7 @@ files:
|
|
400
400
|
- test/unit/localization/de_test.rb
|
401
401
|
- test/unit/localization/default_test.rb
|
402
402
|
- test/unit/localization/en_test.rb
|
403
|
+
- test/unit/localization_18n_failure_test.rb
|
403
404
|
- test/unit/localization_test.rb
|
404
405
|
- test/unit/redcloth_to_html_test.rb
|
405
406
|
- test/unit/string_extensions_test.rb
|