stringex 2.0.4 → 2.0.5
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/Rakefile +9 -1
- data/VERSION +1 -1
- data/lib/stringex/localization/backend/i18n.rb +16 -4
- data/stringex.gemspec +21 -20
- data/test/performance/localization_performance_test.rb +24 -0
- data/test/{acts_as_url → unit/acts_as_url}/adapter/active_record.rb +0 -0
- data/test/{acts_as_url → unit/acts_as_url}/adapter/data_mapper.rb +0 -0
- data/test/{acts_as_url → unit/acts_as_url}/adapter/mongoid.rb +0 -0
- data/test/{acts_as_url_configuration_test.rb → unit/acts_as_url_configuration_test.rb} +0 -0
- data/test/{acts_as_url_integration_test.rb → unit/acts_as_url_integration_test.rb} +0 -0
- data/test/{localization → unit/localization}/da_test.rb +0 -0
- data/test/{localization → unit/localization}/default_test.rb +0 -0
- data/test/{localization → unit/localization}/en_test.rb +0 -0
- data/test/{localization_test.rb → unit/localization_test.rb} +0 -0
- data/test/{redcloth_to_html_test.rb → unit/redcloth_to_html_test.rb} +0 -0
- data/test/{string_extensions_test.rb → unit/string_extensions_test.rb} +0 -0
- data/test/{unicode_point_suite → unit/unicode_point_suite}/basic_greek_test.rb +0 -0
- data/test/{unicode_point_suite → unit/unicode_point_suite}/basic_latin_test.rb +0 -0
- data/test/{unicode_point_suite → unit/unicode_point_suite}/codepoint_test_helper.rb +0 -0
- data/test/{unidecoder → unit/unidecoder}/bad_localization.yml +0 -0
- data/test/{unidecoder → unit/unidecoder}/localization.yml +0 -0
- data/test/{unidecoder_test.rb → unit/unidecoder_test.rb} +0 -0
- data/test/{version_test.rb → unit/version_test.rb} +0 -0
- metadata +21 -20
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzJhYzkxYjk0MzM2YzY0NjA3YTJlNTQwMzJiZTY0MTk4MWZiNzI1YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
M2JjNzFjZWJhN2NhZmZmNzhlMTM0ZThmNmUwMDNiZDQ2MGY1YTllZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MDE4NDUxZjY1ZTdlMzc4M2E5NWVmNGFjN2MyY2M1ZDI4ZjQ0YzFlMzJiY2Y2
|
10
|
+
YjIzZGJlM2U2MDQ4NjgzNjA1NGRjYjdkNDQxYzdjMDBhZDMwYWVlNWRiMWVm
|
11
|
+
OTNkNjc0ZGM1YjlmODhjMDBhNzZhNGY4Mzc0M2U4NzE5M2NiMGY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Zjc2YTJkOTM0YmM1NzlhMTEzZGY0NGQwNTExOGNlOTJkNWM2MTNiYTg0MWU4
|
14
|
+
ZDM5ZTcyZGVkN2NmOTMxMjkzOTg0MjgwMmM5ZGU4ZGE1N2E3YThiYWNiOGJh
|
15
|
+
MTAxOGM0Mjk3MWI5NTg0ODc5YzFlMmUwMTJhNWVmYWE4Zjk0Y2U=
|
data/Rakefile
CHANGED
@@ -29,10 +29,18 @@ end
|
|
29
29
|
|
30
30
|
Rake::TestTask.new do |t|
|
31
31
|
t.libs << 'lib' << 'test'
|
32
|
-
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.pattern = 'test/unit/**/*_test.rb'
|
33
33
|
t.verbose = true
|
34
34
|
end
|
35
35
|
|
36
|
+
namespace :test do
|
37
|
+
Rake::TestTask.new(:performance) do |t|
|
38
|
+
t.libs << 'lib' << 'test'
|
39
|
+
t.pattern = 'test/performance/**/*_test.rb'
|
40
|
+
t.verbose = true
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
36
44
|
desc 'Default: Run Stringex test suite using ActiveRecord as the ORM'
|
37
45
|
task :default => [:setup_active_record_suite, :test]
|
38
46
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.5
|
@@ -27,13 +27,16 @@ module Stringex
|
|
27
27
|
|
28
28
|
def store_translations(locale, scope, data)
|
29
29
|
::I18n.backend.store_translations(locale, { :stringex => { scope => data } })
|
30
|
+
reset_translations_cache
|
31
|
+
end
|
32
|
+
|
33
|
+
def translations
|
34
|
+
# Set up hash like translations[:en][:transliterations]["é"]
|
35
|
+
@translations ||= Hash.new { |hsh, locale| hsh[locale] = Hash.new({}).merge(i18n_translations_for(locale)) }
|
30
36
|
end
|
31
37
|
|
32
38
|
def initial_translation(scope, key, locale)
|
33
|
-
|
34
|
-
# is specified, so we use a string instead.
|
35
|
-
translated = ::I18n.translate(key, :scope => [:stringex, scope], :locale => locale, :default => "__default__")
|
36
|
-
translated == "__default__" ? nil : translated
|
39
|
+
translations[locale][scope][key.to_sym]
|
37
40
|
end
|
38
41
|
|
39
42
|
def load_translations(locale = nil)
|
@@ -41,6 +44,15 @@ module Stringex
|
|
41
44
|
path = Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")]
|
42
45
|
::I18n.load_path |= Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")]
|
43
46
|
::I18n.backend.load_translations
|
47
|
+
reset_translations_cache
|
48
|
+
end
|
49
|
+
|
50
|
+
def i18n_translations_for(locale)
|
51
|
+
::I18n.translate("stringex", :locale => locale, :default => {})
|
52
|
+
end
|
53
|
+
|
54
|
+
def reset_translations_cache
|
55
|
+
@translations = nil
|
44
56
|
end
|
45
57
|
end
|
46
58
|
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.5"
|
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-16"
|
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 = [
|
@@ -231,25 +231,26 @@ Gem::Specification.new do |s|
|
|
231
231
|
"locales/en.yml",
|
232
232
|
"locales/pt-BR.yml",
|
233
233
|
"stringex.gemspec",
|
234
|
-
"test/
|
235
|
-
"test/acts_as_url/adapter/data_mapper.rb",
|
236
|
-
"test/acts_as_url/adapter/mongoid.rb",
|
237
|
-
"test/acts_as_url_configuration_test.rb",
|
238
|
-
"test/acts_as_url_integration_test.rb",
|
239
|
-
"test/localization/da_test.rb",
|
240
|
-
"test/localization/default_test.rb",
|
241
|
-
"test/localization/en_test.rb",
|
242
|
-
"test/localization_test.rb",
|
243
|
-
"test/redcloth_to_html_test.rb",
|
244
|
-
"test/string_extensions_test.rb",
|
234
|
+
"test/performance/localization_performance_test.rb",
|
245
235
|
"test/test_helper.rb",
|
246
|
-
"test/
|
247
|
-
"test/
|
248
|
-
"test/
|
249
|
-
"test/
|
250
|
-
"test/
|
251
|
-
"test/
|
252
|
-
"test/
|
236
|
+
"test/unit/acts_as_url/adapter/active_record.rb",
|
237
|
+
"test/unit/acts_as_url/adapter/data_mapper.rb",
|
238
|
+
"test/unit/acts_as_url/adapter/mongoid.rb",
|
239
|
+
"test/unit/acts_as_url_configuration_test.rb",
|
240
|
+
"test/unit/acts_as_url_integration_test.rb",
|
241
|
+
"test/unit/localization/da_test.rb",
|
242
|
+
"test/unit/localization/default_test.rb",
|
243
|
+
"test/unit/localization/en_test.rb",
|
244
|
+
"test/unit/localization_test.rb",
|
245
|
+
"test/unit/redcloth_to_html_test.rb",
|
246
|
+
"test/unit/string_extensions_test.rb",
|
247
|
+
"test/unit/unicode_point_suite/basic_greek_test.rb",
|
248
|
+
"test/unit/unicode_point_suite/basic_latin_test.rb",
|
249
|
+
"test/unit/unicode_point_suite/codepoint_test_helper.rb",
|
250
|
+
"test/unit/unidecoder/bad_localization.yml",
|
251
|
+
"test/unit/unidecoder/localization.yml",
|
252
|
+
"test/unit/unidecoder_test.rb",
|
253
|
+
"test/unit/version_test.rb"
|
253
254
|
]
|
254
255
|
s.homepage = "http://github.com/rsl/stringex"
|
255
256
|
s.licenses = ["MIT"]
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require 'stringex'
|
3
|
+
require 'i18n'
|
4
|
+
require 'benchmark'
|
5
|
+
|
6
|
+
class LocalizationPerformanceTest < Test::Unit::TestCase
|
7
|
+
def setup
|
8
|
+
I18n.locale = :en
|
9
|
+
Stringex::Localization.reset!
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_i18n_performance
|
13
|
+
Stringex::Localization.backend = :internal
|
14
|
+
internal_time = Benchmark.realtime { 100.times{ "alskdjfal".to_url } }
|
15
|
+
|
16
|
+
Stringex::Localization.backend = :i18n
|
17
|
+
i18n_time = Benchmark.realtime { 100.times{ "alskdjfal".to_url } }
|
18
|
+
|
19
|
+
percentage_difference = ((i18n_time - internal_time) / internal_time) * 100
|
20
|
+
allowed_difference = 25
|
21
|
+
|
22
|
+
assert percentage_difference <= allowed_difference, "The I18n backend is #{percentage_difference.to_i} percent slower than the internal backend. The allowed difference is #{allowed_difference} percent."
|
23
|
+
end
|
24
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
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.5
|
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-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -389,25 +389,26 @@ files:
|
|
389
389
|
- locales/en.yml
|
390
390
|
- locales/pt-BR.yml
|
391
391
|
- stringex.gemspec
|
392
|
-
- test/
|
393
|
-
- test/acts_as_url/adapter/data_mapper.rb
|
394
|
-
- test/acts_as_url/adapter/mongoid.rb
|
395
|
-
- test/acts_as_url_configuration_test.rb
|
396
|
-
- test/acts_as_url_integration_test.rb
|
397
|
-
- test/localization/da_test.rb
|
398
|
-
- test/localization/default_test.rb
|
399
|
-
- test/localization/en_test.rb
|
400
|
-
- test/localization_test.rb
|
401
|
-
- test/redcloth_to_html_test.rb
|
402
|
-
- test/string_extensions_test.rb
|
392
|
+
- test/performance/localization_performance_test.rb
|
403
393
|
- test/test_helper.rb
|
404
|
-
- test/
|
405
|
-
- test/
|
406
|
-
- test/
|
407
|
-
- test/
|
408
|
-
- test/
|
409
|
-
- test/
|
410
|
-
- test/
|
394
|
+
- test/unit/acts_as_url/adapter/active_record.rb
|
395
|
+
- test/unit/acts_as_url/adapter/data_mapper.rb
|
396
|
+
- test/unit/acts_as_url/adapter/mongoid.rb
|
397
|
+
- test/unit/acts_as_url_configuration_test.rb
|
398
|
+
- test/unit/acts_as_url_integration_test.rb
|
399
|
+
- test/unit/localization/da_test.rb
|
400
|
+
- test/unit/localization/default_test.rb
|
401
|
+
- test/unit/localization/en_test.rb
|
402
|
+
- test/unit/localization_test.rb
|
403
|
+
- test/unit/redcloth_to_html_test.rb
|
404
|
+
- test/unit/string_extensions_test.rb
|
405
|
+
- test/unit/unicode_point_suite/basic_greek_test.rb
|
406
|
+
- test/unit/unicode_point_suite/basic_latin_test.rb
|
407
|
+
- test/unit/unicode_point_suite/codepoint_test_helper.rb
|
408
|
+
- test/unit/unidecoder/bad_localization.yml
|
409
|
+
- test/unit/unidecoder/localization.yml
|
410
|
+
- test/unit/unidecoder_test.rb
|
411
|
+
- test/unit/version_test.rb
|
411
412
|
homepage: http://github.com/rsl/stringex
|
412
413
|
licenses:
|
413
414
|
- MIT
|