stringex 2.0.3 → 2.0.4
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/README.rdoc +9 -6
- data/VERSION +1 -1
- data/lib/stringex/localization.rb +1 -0
- data/lib/stringex/localization/backend/base.rb +13 -0
- data/lib/stringex/localization/backend/i18n.rb +4 -8
- data/lib/stringex/localization/backend/internal.rb +1 -5
- data/lib/stringex/localization/conversion_expressions.rb +1 -1
- data/lib/stringex/localization/converter.rb +5 -1
- data/lib/stringex/string_extensions.rb +1 -0
- data/stringex.gemspec +3 -2
- data/test/localization_test.rb +19 -0
- data/test/string_extensions_test.rb +16 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OTk5MGJkMmU1Nzk5Yzc4YWEwYzExMmYzZDMzNmY4ODg0MmIwMjM1Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MTczNTY4NjEwMDFkNTdlNzQyZGI4MTZlNzJlOWZjODU1MWM2ZmE0ZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MzhlMWQwMmIxNDg1M2IyYjRmMjYwYTRlMGQyMWQ2YmI2ODhiNDVlNGZiZTE2
|
10
|
+
NGY4OTM5Y2M3MjRmYTA5ZDM2YWRhNzM4OTFhNDgxMDg2Y2E3ODU5YmJjM2Nh
|
11
|
+
ZGNmOTNjN2U3MDM2MzI4ZDNjYjc1MmM1YWVjZGY5ODk0MmE2MGU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzU4ODc0MGE4MTEyZjk1NzAxNGQ3MWIyM2U3NDE1OTZkNWJjMzU5NTBlMDMy
|
14
|
+
MjRlNWYzZWVlZjI5YjUxZGNjNDJjYzg3ZjBiZjdkYzIyYjYxZWM4MTc2ZGQ4
|
15
|
+
MmM2OTdkMTM4NDgxMWNiOTFjNjBjYzk5MzQ5N2QzODUzNWVkOTI=
|
data/README.rdoc
CHANGED
@@ -95,14 +95,15 @@ A small collection of extensions on Ruby's String class. Please see the document
|
|
95
95
|
|
96
96
|
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.
|
97
97
|
|
98
|
-
==
|
98
|
+
== Ruby on Rails Usage
|
99
99
|
|
100
|
-
When using Stringex with Ruby on Rails, you automatically get built-in translations for miscellaneous characters, HTML entities, and vulgar fractions.
|
101
|
-
|
102
|
-
You can see Stringex's standard translations here[https://github.com/rsl/stringex/tree/master/locales].
|
100
|
+
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
101
|
|
104
102
|
Currently, built-in translations are available for the following languages:
|
105
|
-
|
103
|
+
|
104
|
+
* English (en)
|
105
|
+
* Danish (da)
|
106
|
+
* Portugueuse Brazilian (pt-BR)
|
106
107
|
|
107
108
|
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.
|
108
109
|
|
@@ -110,7 +111,7 @@ If you don't want to use the Stringex built-in translations, you can force Strin
|
|
110
111
|
|
111
112
|
Stringex::Localization.locale = :en
|
112
113
|
|
113
|
-
==
|
114
|
+
== CanCan Usage Note
|
114
115
|
|
115
116
|
You'll need to add a <tt>:find_by => :url</tt> to your <tt>load_and_authorize_resource</tt>. Here's an example:
|
116
117
|
|
@@ -120,4 +121,6 @@ You'll need to add a <tt>:find_by => :url</tt> to your <tt>load_and_authorize_re
|
|
120
121
|
|
121
122
|
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/].
|
122
123
|
|
124
|
+
GIANT thanks to the many contributors who have helped make Stringex better and better: http://github.com/rsl/stringex/contributors
|
125
|
+
|
123
126
|
copyright (c) 2008-2012 Lucky Sneaks, released under the MIT license
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.4
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module Stringex
|
2
2
|
module Localization
|
3
3
|
module Backend
|
4
|
-
|
4
|
+
class I18n < Base
|
5
5
|
LOAD_PATH_BASE = File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', '..', '..', 'locales')
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def locale
|
9
|
-
::I18n.locale
|
9
|
+
@locale || ::I18n.locale
|
10
10
|
end
|
11
11
|
|
12
12
|
def locale=(new_locale)
|
13
|
-
|
13
|
+
@locale = new_locale
|
14
14
|
end
|
15
15
|
|
16
16
|
def default_locale
|
@@ -37,15 +37,11 @@ module Stringex
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def load_translations(locale = nil)
|
40
|
-
locale ||=
|
40
|
+
locale ||= self.locale
|
41
41
|
path = Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")]
|
42
42
|
::I18n.load_path |= Dir[File.join(LOAD_PATH_BASE, "#{locale}.yml")]
|
43
43
|
::I18n.backend.load_translations
|
44
44
|
end
|
45
|
-
|
46
|
-
def reset!
|
47
|
-
# Can't reset I18n. Needed?
|
48
|
-
end
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Stringex
|
2
2
|
module Localization
|
3
3
|
module Backend
|
4
|
-
|
4
|
+
class Internal < Base
|
5
5
|
DEFAULT_LOCALE = :en
|
6
6
|
|
7
7
|
class << self
|
@@ -40,10 +40,6 @@ module Stringex
|
|
40
40
|
def initial_translation(scope, key, locale)
|
41
41
|
translations[locale][scope][key.to_sym]
|
42
42
|
end
|
43
|
-
|
44
|
-
def reset!
|
45
|
-
@translations = @locale = @default_locale = nil
|
46
|
-
end
|
47
43
|
end
|
48
44
|
end
|
49
45
|
end
|
@@ -36,6 +36,10 @@ module Stringex
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def normalize_currency!
|
40
|
+
string.gsub! /(\d+),(\d+)/, '\1\2'
|
41
|
+
end
|
42
|
+
|
39
43
|
def smart_strip!
|
40
44
|
string.strip!
|
41
45
|
@string = "#{starting_whitespace}#{string}#{ending_whitespace}"
|
@@ -71,7 +75,7 @@ module Stringex
|
|
71
75
|
expressions.characters.each do |key, expression|
|
72
76
|
next if key == :slash && options[:allow_slash]
|
73
77
|
replacement = translate(key)
|
74
|
-
replacement = " #{replacement} " unless key == :dot
|
78
|
+
replacement = " #{replacement} " unless replacement == '' || key == :dot
|
75
79
|
string.gsub! expression, replacement
|
76
80
|
end
|
77
81
|
end
|
@@ -53,6 +53,7 @@ module Stringex
|
|
53
53
|
# before running this method.
|
54
54
|
def convert_miscellaneous_characters(options = {})
|
55
55
|
stringex_convert(options) do
|
56
|
+
normalize_currency!
|
56
57
|
translate! :ellipses, :currencies, :abbreviations, :characters, :apostrophes
|
57
58
|
cleanup_characters!
|
58
59
|
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.4"
|
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-
|
12
|
+
s.date = "2013-07-15"
|
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 = [
|
@@ -37,6 +37,7 @@ Gem::Specification.new do |s|
|
|
37
37
|
"lib/stringex/configuration/configurator.rb",
|
38
38
|
"lib/stringex/configuration/string_extensions.rb",
|
39
39
|
"lib/stringex/localization.rb",
|
40
|
+
"lib/stringex/localization/backend/base.rb",
|
40
41
|
"lib/stringex/localization/backend/i18n.rb",
|
41
42
|
"lib/stringex/localization/backend/internal.rb",
|
42
43
|
"lib/stringex/localization/conversion_expressions.rb",
|
data/test/localization_test.rb
CHANGED
@@ -4,6 +4,7 @@ require 'i18n'
|
|
4
4
|
|
5
5
|
class LocalizationTest < Test::Unit::TestCase
|
6
6
|
def setup
|
7
|
+
I18n.locale = :en
|
7
8
|
Stringex::Localization.reset!
|
8
9
|
end
|
9
10
|
|
@@ -120,4 +121,22 @@ class LocalizationTest < Test::Unit::TestCase
|
|
120
121
|
assert_equal "Testblank", "Test blank".convert_miscellaneous_html_entities
|
121
122
|
end
|
122
123
|
end
|
124
|
+
|
125
|
+
def test_assigns_locale_in_i18n_backend
|
126
|
+
I18n.locale = :en
|
127
|
+
Stringex::Localization.backend = :i18n
|
128
|
+
|
129
|
+
assert_equal :en, Stringex::Localization.locale
|
130
|
+
|
131
|
+
I18n.locale = :jp
|
132
|
+
assert_equal :jp, Stringex::Localization.locale
|
133
|
+
|
134
|
+
Stringex::Localization.locale = :de
|
135
|
+
assert_equal :de, Stringex::Localization.locale
|
136
|
+
assert_equal :jp, I18n.locale
|
137
|
+
|
138
|
+
Stringex::Localization.locale = nil
|
139
|
+
assert_equal :jp, Stringex::Localization.locale
|
140
|
+
assert_equal :jp, I18n.locale
|
141
|
+
end
|
123
142
|
end
|
@@ -71,7 +71,11 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
71
71
|
"У лукоморья дуб зеленый" =>
|
72
72
|
"u-lukomoria-dub-zielienyi",
|
73
73
|
"Here are some {braces}" =>
|
74
|
-
"here-are-some-braces"
|
74
|
+
"here-are-some-braces",
|
75
|
+
"$1,000" =>
|
76
|
+
"1000-dollars",
|
77
|
+
"«zut alors»" =>
|
78
|
+
"zut-alors"
|
75
79
|
}.each do |html, plain|
|
76
80
|
assert_equal plain, html.to_url
|
77
81
|
end
|
@@ -214,4 +218,15 @@ class StringExtensionsTest < Test::Unit::TestCase
|
|
214
218
|
|
215
219
|
assert_equal "now-with-hyphens", "----now---------with-hyphens--------".collapse("-")
|
216
220
|
end
|
221
|
+
|
222
|
+
def test_empty_translations
|
223
|
+
Stringex::Localization.backend = :internal
|
224
|
+
Stringex::Localization.store_translations :de, :characters, {
|
225
|
+
:star => "",
|
226
|
+
:percent => "prozent"
|
227
|
+
}
|
228
|
+
Stringex::Localization.locale = :de
|
229
|
+
|
230
|
+
assert_equal "foobar ist 100 prozent gut", "foo*bar ist 100% gut".convert_miscellaneous_characters
|
231
|
+
end
|
217
232
|
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.4
|
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-
|
11
|
+
date: 2013-07-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -195,6 +195,7 @@ files:
|
|
195
195
|
- lib/stringex/configuration/configurator.rb
|
196
196
|
- lib/stringex/configuration/string_extensions.rb
|
197
197
|
- lib/stringex/localization.rb
|
198
|
+
- lib/stringex/localization/backend/base.rb
|
198
199
|
- lib/stringex/localization/backend/i18n.rb
|
199
200
|
- lib/stringex/localization/backend/internal.rb
|
200
201
|
- lib/stringex/localization/conversion_expressions.rb
|