stringex 2.5.2 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f38aa370c45410b7dddca83f8415b394128fbef0
4
- data.tar.gz: c31065a92e88609aab0d0177df0d55d00a3153e9
3
+ metadata.gz: c133692ec8d93e4edd5ebf1893f754ef004c0251
4
+ data.tar.gz: 0d77e8620e72837829c13a31235bcce1fd807aa6
5
5
  SHA512:
6
- metadata.gz: 549f5d2ae387791d12242a70135f852c295a4bc30bf0d39a9abbd669569bd9d762a408b18bac9c069a813a984c26e943cc52984cc158ef723da875dc3cdf27f2
7
- data.tar.gz: faa753229e05c6feddcf2d028d4678de8400e703d1ac5397193fff571f8f5648846cd94bad92cd82a8f1e03b66c99ad6b757261c9549540cb72c099f95aeda41
6
+ metadata.gz: 33867f2f5c28f26ddc8f07f00d35eb8137dcdc6369ba75d0f69a90909fdd7cb57daa6a22f5cbd684e3a9dd3477f0b28bc7637bd0818c14fbff6cac740c1ace2d
7
+ data.tar.gz: 4223f8aed6061234a7c2d9b0dcc6dd2408ddda98897ef2dc88efd7d19037d24c52b4c6824a804cf22c0101246025640bc6053e9bfb84339a6070880f567a7582
data/Gemfile CHANGED
@@ -27,7 +27,8 @@ group :development do
27
27
  gem 'travis-lint', '1.7.0'
28
28
  # Can I state that I really dislike camelcased gem names?
29
29
  gem 'RedCloth', '4.2.9'
30
- gem 'sqlite3', '1.3.7'
30
+ gem 'sqlite3', '1.3.10'
31
+ gem 'test-unit', '3.0.9'
31
32
 
32
33
  if activerecord?
33
34
  gem 'activerecord', '4.0.3'
@@ -1,4 +1,4 @@
1
- = Stringex {<img src="https://codeclimate.com/github/rsl/stringex.png" />}[https://codeclimate.com/github/rsl/stringex] {<img src="https://travis-ci.org/rsl/stringex.png?branch=master" alt="Build Status" />}[https://travis-ci.org/rsl/stringex]
1
+ = Stringex {<img src="https://codeclimate.com/github/rsl/stringex.png" />}[https://codeclimate.com/github/rsl/stringex] {<img src="https://travis-ci.org/rsl/stringex.png?branch=master" alt="Build Status" />}[https://travis-ci.org/rsl/stringex] {<img src="https://badge.fury.io/rb/stringex.svg" alt="Gem Version" />}[http://badge.fury.io/rb/stringex]
2
2
 
3
3
  Some [hopefully] useful extensions to Ruby's String class. It is made up of three libraries: ActsAsUrl, Unidecoder, and StringExtensions.
4
4
 
@@ -34,7 +34,7 @@ which will populate the <tt>url</tt> attribute on the object with the converted
34
34
  <tt>:blacklist</tt>:: List of urls that should not be allowed. Default is <tt>%w{new}</tt> [which avoids confusion
35
35
  on urls like <tt>/documents/new</tt>].
36
36
  <tt>:blacklist_policy</tt>:: Proc or lambda defining new naming behavior when blacklisted urls are encountered.
37
- Default converts <tt>/documents/new</tt> to </tt>/documents/new-document</tt>.
37
+ Default converts <tt>/documents/new</tt> to <tt>/documents/new-document</tt>.
38
38
 
39
39
 
40
40
  In order to use the generated url attribute, you will probably want to override <tt>to_param</tt> like so, in your Model:
@@ -85,7 +85,16 @@ Note: No offense is intended to the author[s] of whatever plugins might produce
85
85
 
86
86
  This library converts Unicode [and accented ASCII] characters to their plain-text ASCII equivalents. This is a port of Perl's Unidecode and provides eminently superior and more reliable results than Iconv. (Seriously, Iconv... A plague on both your houses! [sic])
87
87
 
88
- You probably won't ever need to run Unidecoder by itself. StringExtensions adds String#to_ascii which wraps all of Unidecoder's functionality. For anyone interested, details of the implementation can be read about in the original implementation of Text::Unidecode[http://interglacial.com/~sburke/tpj/as_html/tpj22.html]. Extensive examples can be found in the tests.
88
+ You may require only the unidecoder (and its dependent localization) via
89
+
90
+ require "stringex/unidecoder"
91
+
92
+ You probably won't ever need to run Unidecoder by itself. Thus, you probably would want to add String#to_ascii which wraps all of Unidecoder's functionality, by requiring:
93
+
94
+ require "stringex/core_ext"
95
+
96
+ For anyone interested, details of the implementation can be read about in the original implementation of Text::Unidecode[http://interglacial.com/~sburke/tpj/as_html/tpj22.html]. Extensive examples can be found in the tests.
97
+
89
98
 
90
99
  == StringExtensions
91
100
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.5.2
1
+ 2.6.0
@@ -8,8 +8,7 @@ require 'stringex/unidecoder'
8
8
  require 'stringex/acts_as_url'
9
9
  require 'stringex/version'
10
10
 
11
- String.send :include, Stringex::StringExtensions::PublicInstanceMethods
12
- String.send :extend, Stringex::StringExtensions::PublicClassMethods
11
+ require 'stringex/core_ext'
13
12
 
14
13
  Stringex::ActsAsUrl::Adapter.load_available
15
14
 
@@ -119,14 +119,22 @@ module Stringex
119
119
  end
120
120
 
121
121
  def handle_duplicate_url!
122
- return if url_owners.none?{|owner| url_attribute_for(owner) == base_url}
122
+ return if !url_taken?(base_url)
123
123
  n = 1
124
- while url_owners.any?{|owner| url_attribute_for(owner) == duplicate_for_base_url(n)}
124
+ while url_taken?(duplicate_for_base_url(n))
125
125
  n = n.succ
126
126
  end
127
127
  write_url_attribute duplicate_for_base_url(n)
128
128
  end
129
129
 
130
+ def url_taken?(url)
131
+ if settings.url_taken_method
132
+ instance.send(settings.url_taken_method, url)
133
+ else
134
+ url_owners.any?{|owner| url_attribute_for(owner) == url}
135
+ end
136
+ end
137
+
130
138
  def handle_url!
131
139
  self.base_url = instance.send(settings.url_attribute)
132
140
  modify_base_url if is_blank?(base_url) || !settings.only_when_blank
@@ -0,0 +1,10 @@
1
+ Stringex = Module.new unless defined?(Stringex)
2
+ ensure_module_defined = ->(base, module_name){
3
+ base.const_set(module_name, Module.new) unless base.const_defined?(module_name)
4
+ }
5
+ ensure_module_defined[Stringex, :StringExtensions]
6
+ ensure_module_defined[Stringex::StringExtensions, :PublicInstanceMethods]
7
+ ensure_module_defined[Stringex::StringExtensions, :PublicClassMethods]
8
+
9
+ String.send :include, Stringex::StringExtensions::PublicInstanceMethods
10
+ String.send :extend, Stringex::StringExtensions::PublicClassMethods
@@ -5,6 +5,11 @@ module Stringex
5
5
  LOAD_PATH_BASE = File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', '..', '..', 'locales')
6
6
 
7
7
  class << self
8
+ def reset!
9
+ super
10
+ ::I18n.reload! if defined?(::I18n) && ::I18n.respond_to?(:reload!)
11
+ end
12
+
8
13
  def locale
9
14
  @locale || ::I18n.locale
10
15
  end
@@ -59,7 +64,7 @@ module Stringex
59
64
  def ensure_locales_enforced_or_not
60
65
  return unless ::I18n.respond_to?(:enforce_available_locales)
61
66
  # Allow users to have set this to false manually but default to true
62
- return if ::I18n.enforce_available_locales != nil
67
+ return unless ::I18n.enforce_available_locales == nil
63
68
  ::I18n.enforce_available_locales = ::I18n.available_locales != []
64
69
  end
65
70
  end
@@ -103,6 +103,8 @@ module Stringex
103
103
  /…/ => "...",
104
104
  }
105
105
 
106
+ UNREADABLE_CONTROL_CHARACTERS = /[[:cntrl:]]/
107
+
106
108
  # Ordered by denominator then numerator of the value
107
109
  VULGAR_FRACTIONS = {
108
110
  :half => /(&#189;|&frac12;|½)/,
@@ -138,6 +140,7 @@ module Stringex
138
140
  html_entities
139
141
  html_tag
140
142
  smart_punctuation
143
+ unreadable_control_characters
141
144
  vulgar_fractions
142
145
  whitespace
143
146
  }.each do |conversion_type|
@@ -59,7 +59,11 @@ module Stringex
59
59
  end
60
60
  end
61
61
 
62
- protected
62
+ protected
63
+
64
+ def unreadable_control_characters
65
+ string.gsub! expressions.unreadable_control_characters, ''
66
+ end
63
67
 
64
68
  def abbreviations
65
69
  string.gsub! expressions.abbreviation do |x|
@@ -107,7 +111,7 @@ module Stringex
107
111
  end
108
112
  end
109
113
 
110
- private
114
+ private
111
115
 
112
116
  def expressions
113
117
  ConversionExpressions
@@ -122,4 +126,4 @@ module Stringex
122
126
  end
123
127
  end
124
128
  end
125
- end
129
+ end
@@ -93,18 +93,24 @@ module Stringex
93
93
  end
94
94
  end
95
95
 
96
+ def convert_unreadable_control_characters
97
+ stringex_convert do
98
+ translate! :unreadable_control_characters
99
+ end
100
+ end
101
+
96
102
  # Returns the string limited in size to the value of limit.
97
- def limit(limit = nil, truncate_words = true)
103
+ def limit(limit = nil, truncate_words = true, whitespace_replacement_token = "-")
98
104
  if limit.nil?
99
105
  self
100
106
  else
101
- truncate_words == false ? self.whole_word_limit(limit) : self[0...limit]
107
+ truncate_words == false ? self.whole_word_limit(limit, whitespace_replacement_token) : self[0...limit]
102
108
  end
103
109
  end
104
110
 
105
- def whole_word_limit(limit)
111
+ def whole_word_limit(limit, whitespace_replacement_token = "-")
106
112
  whole_words = []
107
- words = self.split('-')
113
+ words = self.split(whitespace_replacement_token)
108
114
 
109
115
  words.each do |word|
110
116
  if word.size > limit
@@ -115,7 +121,7 @@ module Stringex
115
121
  end
116
122
  end
117
123
 
118
- whole_words.join('-')
124
+ whole_words.join(whitespace_replacement_token)
119
125
  end
120
126
 
121
127
 
@@ -126,6 +132,7 @@ module Stringex
126
132
  convert_smart_punctuation.
127
133
  convert_accented_html_entities.
128
134
  convert_vulgar_fractions.
135
+ convert_unreadable_control_characters.
129
136
  convert_miscellaneous_html_entities.
130
137
  convert_miscellaneous_characters(options).
131
138
  to_ascii.
@@ -187,8 +194,8 @@ module Stringex
187
194
  whitespace_replacement_token = options[:replace_whitespace_with]
188
195
  dummy = remove_formatting(options).
189
196
  replace_whitespace(whitespace_replacement_token).
190
- collapse("-").
191
- limit(options[:limit], options[:truncate_words])
197
+ collapse(whitespace_replacement_token).
198
+ limit(options[:limit], options[:truncate_words], whitespace_replacement_token)
192
199
  dummy.downcase! unless options[:force_downcase] == false
193
200
  dummy
194
201
  end
@@ -1,6 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require 'yaml'
4
+ require 'stringex/localization'
4
5
 
5
6
  module Stringex
6
7
  module Unidecoder
@@ -68,12 +69,14 @@ module Stringex
68
69
  end
69
70
 
70
71
  module Stringex
71
- module StringExtensions::PublicInstanceMethods
72
- # Returns string with its UTF-8 characters transliterated to ASCII ones. Example:
73
- #
74
- # "⠋⠗⠁⠝⠉⠑".to_ascii #=> "france"
75
- def to_ascii
76
- Stringex::Unidecoder.decode(self)
72
+ module StringExtensions
73
+ module PublicInstanceMethods
74
+ # Returns string with its UTF-8 characters transliterated to ASCII ones. Example:
75
+ #
76
+ # "⠋⠗⠁⠝⠉⠑".to_ascii #=> "france"
77
+ def to_ascii
78
+ Stringex::Unidecoder.decode(self)
79
+ end
77
80
  end
78
81
  end
79
82
  end
@@ -166,7 +166,7 @@
166
166
  - T
167
167
  - Y
168
168
  - Ph
169
- - Ks
169
+ - X
170
170
  - Ps
171
171
  - O
172
172
  - I
@@ -253,4 +253,4 @@
253
253
  - '[?]'
254
254
  - '[?]'
255
255
  - '[?]'
256
- - '[?]'
256
+ - '[?]'
@@ -0,0 +1,72 @@
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
+ fr:
7
+ stringex:
8
+ characters:
9
+ and: et
10
+ at: arobase
11
+ divide: divisé par
12
+ degrees: degrés
13
+ dot: \1 point \2
14
+ ellipsis: point point point
15
+ equals: égal
16
+ number: numéro
17
+ percent: pourcent
18
+ plus: plus
19
+ slash: slash
20
+ star: étoile
21
+ currencies:
22
+ generic: \1 livres
23
+ dollars: \1 dollars
24
+ dollars_cents: \1 dollars \2 cents
25
+ pounds: \1 livres
26
+ pounds_pence: \1 livres \2 pennies
27
+ euros: \1 euros
28
+ euros_cents: \1 euros \2 cents
29
+ yen: \1 yen
30
+ reais: \1 reais
31
+ reais_cents: \1 reais \2 cents
32
+ html_entities:
33
+ amp: et
34
+ cent: " cents"
35
+ copy: (c)
36
+ deg: " degrés "
37
+ divide: " divisé par "
38
+ double_quote: '"'
39
+ ellipsis: "..."
40
+ en_dash: "-"
41
+ em_dash: "--"
42
+ frac14: un quart
43
+ frac12: un demi
44
+ frac34: trois quarts
45
+ gt: ">"
46
+ lt: <
47
+ nbsp: " "
48
+ pound: " livres "
49
+ reg: (r)
50
+ single_quote: "'"
51
+ times: x
52
+ trade: (tm)
53
+ yen: " yen "
54
+ vulgar_fractions:
55
+ half: un demi
56
+ one_third: un tiers
57
+ two_thirds: deux tiers
58
+ one_fourth: un quart
59
+ three_fourths: trois quarts
60
+ one_fifth: un cinquième
61
+ two_fifths: deux cinquièmes
62
+ three_fifths: trois cinquièmes
63
+ four_fifths: quatre cinquièmes
64
+ one_sixth: un sixième
65
+ five_sixths: cinq sixièmes
66
+ one_eighth: un huitième
67
+ three_eighths: trois huitièmes
68
+ five_eighths: cinq huitièmes
69
+ seven_eighths: sept huitièmes
70
+ transliterations:
71
+ é: e
72
+ è: e
@@ -0,0 +1,76 @@
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
+ nb:
7
+ stringex:
8
+ characters:
9
+ and: og
10
+ at: krøllalfa
11
+ divide: delt på
12
+ degrees: grader
13
+ dot: \1 dot \2
14
+ ellipsis: prikk prikk prikk
15
+ equals: er lik
16
+ number: nummer
17
+ percent: prosent
18
+ plus: pluss
19
+ slash: skråstrek
20
+ star: stjerne
21
+ currencies:
22
+ generic: \1 kroner
23
+ dollars: \1 dollar
24
+ dollars_cents: \1 dollar \2 cent
25
+ pounds: \1 pund
26
+ pounds_pence: \1 pund \2 pence
27
+ euros: \1 euro
28
+ euros_cents: \1 euro \2 cent
29
+ yen: \1 yen
30
+ reais: \1 reais
31
+ reais_cents: \1 reais \2 cent
32
+ html_entities:
33
+ amp: og
34
+ cent: " cents"
35
+ copy: (c)
36
+ deg: " grader "
37
+ divide: " delt på "
38
+ double_quote: '"'
39
+ ellipsis: "..."
40
+ en_dash: "-"
41
+ em_dash: "--"
42
+ frac14: en fjerdedel
43
+ frac12: halv
44
+ frac34: tre fjerdedeler
45
+ gt: ">"
46
+ lt: <
47
+ nbsp: " "
48
+ pound: " pund "
49
+ reg: (r)
50
+ single_quote: "'"
51
+ times: x
52
+ trade: (tm)
53
+ yen: " yen "
54
+ vulgar_fractions:
55
+ half: halv
56
+ one_third: en tredjedel
57
+ two_thirds: to tredjedeler
58
+ one_fourth: en fjerdedel
59
+ three_fourths: tre fjerdedeler
60
+ one_fifth: en femtedel
61
+ two_fifths: to femtedeler
62
+ three_fifths: tre femtedeler
63
+ four_fifths: fire femtedeler
64
+ one_sixth: en sjettedel
65
+ five_sixths: fem sjettedeler
66
+ one_eighth: en åttendel
67
+ three_eighths: tre åttendeler
68
+ five_eighths: fem åttendeler
69
+ seven_eighths: sju åttendeler
70
+ transliterations:
71
+ Å: AA
72
+ Æ: AE
73
+ Ø: OE
74
+ å: aa
75
+ æ: ae
76
+ ø: oe
@@ -0,0 +1,76 @@
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
+ 'no':
7
+ stringex:
8
+ characters:
9
+ and: og
10
+ at: krøllalfa
11
+ divide: delt på
12
+ degrees: grader
13
+ dot: \1 dot \2
14
+ ellipsis: prikk prikk prikk
15
+ equals: er lik
16
+ number: nummer
17
+ percent: prosent
18
+ plus: pluss
19
+ slash: skråstrek
20
+ star: stjerne
21
+ currencies:
22
+ generic: \1 kroner
23
+ dollars: \1 dollar
24
+ dollars_cents: \1 dollar \2 cent
25
+ pounds: \1 pund
26
+ pounds_pence: \1 pund \2 pence
27
+ euros: \1 euro
28
+ euros_cents: \1 euro \2 cent
29
+ yen: \1 yen
30
+ reais: \1 reais
31
+ reais_cents: \1 reais \2 cent
32
+ html_entities:
33
+ amp: og
34
+ cent: " cents"
35
+ copy: (c)
36
+ deg: " grader "
37
+ divide: " delt på "
38
+ double_quote: '"'
39
+ ellipsis: "..."
40
+ en_dash: "-"
41
+ em_dash: "--"
42
+ frac14: en fjerdedel
43
+ frac12: halv
44
+ frac34: tre fjerdedeler
45
+ gt: ">"
46
+ lt: <
47
+ nbsp: " "
48
+ pound: " pund "
49
+ reg: (r)
50
+ single_quote: "'"
51
+ times: x
52
+ trade: (tm)
53
+ yen: " yen "
54
+ vulgar_fractions:
55
+ half: halv
56
+ one_third: en tredjedel
57
+ two_thirds: to tredjedeler
58
+ one_fourth: en fjerdedel
59
+ three_fourths: tre fjerdedeler
60
+ one_fifth: en femtedel
61
+ two_fifths: to femtedeler
62
+ three_fifths: tre femtedeler
63
+ four_fifths: fire femtedeler
64
+ one_sixth: en sjettedel
65
+ five_sixths: fem sjettedeler
66
+ one_eighth: en åttendel
67
+ three_eighths: tre åttendeler
68
+ five_eighths: fem åttendeler
69
+ seven_eighths: sju åttendeler
70
+ transliterations:
71
+ Å: AA
72
+ Æ: AE
73
+ Ø: OE
74
+ å: aa
75
+ æ: ae
76
+ ø: oe
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: stringex 2.5.2 ruby lib
5
+ # stub: stringex 2.6.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "stringex"
9
- s.version = "2.5.2"
9
+ s.version = "2.6.0"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Russell Norris"]
14
- s.date = "2014-04-09"
14
+ s.date = "2016-01-29"
15
15
  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]."
16
16
  s.email = "rsl@luckysneaks.com"
17
17
  s.extra_rdoc_files = [
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  "lib/stringex/configuration/configurator.rb",
39
39
  "lib/stringex/configuration/string_extensions.rb",
40
40
  "lib/stringex/configuration_lite.rb",
41
+ "lib/stringex/core_ext.rb",
41
42
  "lib/stringex/localization.rb",
42
43
  "lib/stringex/localization/backend/base.rb",
43
44
  "lib/stringex/localization/backend/i18n.rb",
@@ -233,7 +234,10 @@ Gem::Specification.new do |s|
233
234
  "locales/da.yml",
234
235
  "locales/de.yml",
235
236
  "locales/en.yml",
237
+ "locales/fr.yml",
238
+ "locales/nb.yml",
236
239
  "locales/nl.yml",
240
+ "locales/no.yml",
237
241
  "locales/pl.yml",
238
242
  "locales/pt-BR.yml",
239
243
  "locales/ru.yml",
@@ -250,6 +254,7 @@ Gem::Specification.new do |s|
250
254
  "test/unit/localization/de_test.rb",
251
255
  "test/unit/localization/default_test.rb",
252
256
  "test/unit/localization/en_test.rb",
257
+ "test/unit/localization/fr_test.rb",
253
258
  "test/unit/localization/nl_test.rb",
254
259
  "test/unit/localization/pl_test.rb",
255
260
  "test/unit/localization/pt_br_test.rb",
@@ -280,14 +285,16 @@ Gem::Specification.new do |s|
280
285
  s.add_development_dependency(%q<jeweler>, ["= 2.0.1"])
281
286
  s.add_development_dependency(%q<travis-lint>, ["= 1.7.0"])
282
287
  s.add_development_dependency(%q<RedCloth>, ["= 4.2.9"])
283
- s.add_development_dependency(%q<sqlite3>, ["= 1.3.7"])
288
+ s.add_development_dependency(%q<sqlite3>, ["= 1.3.10"])
289
+ s.add_development_dependency(%q<test-unit>, ["= 3.0.9"])
284
290
  s.add_development_dependency(%q<activerecord>, ["= 4.0.3"])
285
291
  s.add_development_dependency(%q<i18n>, ["= 0.6.9"])
286
292
  else
287
293
  s.add_dependency(%q<jeweler>, ["= 2.0.1"])
288
294
  s.add_dependency(%q<travis-lint>, ["= 1.7.0"])
289
295
  s.add_dependency(%q<RedCloth>, ["= 4.2.9"])
290
- s.add_dependency(%q<sqlite3>, ["= 1.3.7"])
296
+ s.add_dependency(%q<sqlite3>, ["= 1.3.10"])
297
+ s.add_dependency(%q<test-unit>, ["= 3.0.9"])
291
298
  s.add_dependency(%q<activerecord>, ["= 4.0.3"])
292
299
  s.add_dependency(%q<i18n>, ["= 0.6.9"])
293
300
  end
@@ -295,7 +302,8 @@ Gem::Specification.new do |s|
295
302
  s.add_dependency(%q<jeweler>, ["= 2.0.1"])
296
303
  s.add_dependency(%q<travis-lint>, ["= 1.7.0"])
297
304
  s.add_dependency(%q<RedCloth>, ["= 4.2.9"])
298
- s.add_dependency(%q<sqlite3>, ["= 1.3.7"])
305
+ s.add_dependency(%q<sqlite3>, ["= 1.3.10"])
306
+ s.add_dependency(%q<test-unit>, ["= 3.0.9"])
299
307
  s.add_dependency(%q<activerecord>, ["= 4.0.3"])
300
308
  s.add_dependency(%q<i18n>, ["= 0.6.9"])
301
309
  end
@@ -376,4 +376,17 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
376
376
  @doc = Document.create(:title => "title with many whole words")
377
377
  assert_equal 'title-with-many', @doc.url
378
378
  end
379
+
380
+ def test_should_allow_overriding_url_taken_method
381
+ Document.class_eval do
382
+ acts_as_url :title, :url_taken_method => :url_taken?
383
+
384
+ def url_taken?(url)
385
+ ["unique", "unique-1", "unique-2"].include?(url)
386
+ end
387
+ end
388
+
389
+ @doc = Document.create(:title => "unique")
390
+ assert_equal "unique-3", @doc.url
391
+ end
379
392
  end
@@ -0,0 +1,118 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'test_helper'
4
+ require 'i18n'
5
+ require 'stringex'
6
+
7
+ class FrenchYAMLLocalizationTest < Test::Unit::TestCase
8
+ def setup
9
+ Stringex::Localization.reset!
10
+ Stringex::Localization.backend = :i18n
11
+ Stringex::Localization.backend.load_translations :fr
12
+ Stringex::Localization.locale = :fr
13
+ end
14
+
15
+ {
16
+ "foo & bar" => "foo et bar",
17
+ "AT&T" => "AT et T",
18
+ "99° est normal" => "99 degrés est normal",
19
+ "4 ÷ 2 is 2" => "4 divisé par 2 is 2",
20
+ "webcrawler.com" => "webcrawler point com",
21
+ "Well..." => "Well point point point",
22
+ "x=1" => "x égal 1",
23
+ "a #2 pencil" => "a numéro 2 pencil",
24
+ "100%" => "100 pourcent",
25
+ "cost+tax" => "cost plus tax",
26
+ "batman/robin fan fiction" => "batman slash robin fan fiction",
27
+ "dial *69" => "dial étoile 69",
28
+ " i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
29
+ }.each do |original, converted|
30
+ define_method "test_character_conversion: '#{original}'" do
31
+ assert_equal converted, original.convert_miscellaneous_characters
32
+ end
33
+ end
34
+
35
+ {
36
+ "¤20" => "20 livres",
37
+ "$100" => "100 dollars",
38
+ "$19.99" => "19 dollars 99 cents",
39
+ "£100" => "100 livres",
40
+ "£19.99" => "19 livres 99 pennies",
41
+ "€100" => "100 euros",
42
+ "€19.99" => "19 euros 99 cents",
43
+ "¥1000" => "1000 yen"
44
+ }.each do |original, converted|
45
+ define_method "test_currency_conversion: '#{original}'" do
46
+ assert_equal converted, original.convert_miscellaneous_characters
47
+ end
48
+ end
49
+
50
+ {
51
+ "Tea &amp; Sympathy" => "Tea et Sympathy",
52
+ "10&cent;" => "10 cents",
53
+ "&copy;2000" => "(c)2000",
54
+ "98&deg; is fine" => "98 degrés is fine",
55
+ "10&divide;5" => "10 divisé par 5",
56
+ "&quot;quoted&quot;" => '"quoted"',
57
+ "to be continued&hellip;" => "to be continued...",
58
+ "2000&ndash;2004" => "2000-2004",
59
+ "I wish&mdash;oh, never mind" => "I wish--oh, never mind",
60
+ "&frac12; ounce of gold" => "un demi ounce of gold",
61
+ "1 et &frac14; d'once de platinium" => "1 et un quart d'once de platinium",
62
+ "9 et &frac34; d'once de platinium" => "9 et trois quarts d'once de platinium",
63
+ "3&gt;2" => "3>2",
64
+ "2&lt;3" => "2<3",
65
+ "two&nbsp;words" => "two words",
66
+ "&pound;100" => "livres 100",
67
+ "Walmart&reg;" => "Walmart(r)",
68
+ "&apos;single quoted&apos;" => "'single quoted'",
69
+ "2&times;4" => "2x4",
70
+ "Programming&trade;" => "Programming(tm)",
71
+ "&yen;20000" => "yen 20000",
72
+ " i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
73
+ }.each do |original, converted|
74
+ define_method "test_html_entity_conversion: '#{original}'" do
75
+ assert_equal converted, original.convert_miscellaneous_html_entities
76
+ end
77
+ end
78
+
79
+ {
80
+ "&frac12;" => "un demi",
81
+ "½" => "un demi",
82
+ "&#189;" => "un demi",
83
+ "⅓" => "un tiers",
84
+ "&#8531;" => "un tiers",
85
+ "⅔" => "deux tiers",
86
+ "&#8532;" => "deux tiers",
87
+ "&frac14;" => "un quart",
88
+ "¼" => "un quart",
89
+ "&#188;" => "un quart",
90
+ "&frac34;" => "trois quarts",
91
+ "¾" => "trois quarts",
92
+ "&#190;" => "trois quarts",
93
+ "⅕" => "un cinquième",
94
+ "&#8533;" => "un cinquième",
95
+ "⅖" => "deux cinquièmes",
96
+ "&#8534;" => "deux cinquièmes",
97
+ "⅗" => "trois cinquièmes",
98
+ "&#8535;" => "trois cinquièmes",
99
+ "⅘" => "quatre cinquièmes",
100
+ "&#8536;" => "quatre cinquièmes",
101
+ "⅙" => "un sixième",
102
+ "&#8537;" => "un sixième",
103
+ "⅚" => "cinq sixièmes",
104
+ "&#8538;" => "cinq sixièmes",
105
+ "⅛" => "un huitième",
106
+ "&#8539;" => "un huitième",
107
+ "⅜" => "trois huitièmes",
108
+ "&#8540;" => "trois huitièmes",
109
+ "⅝" => "cinq huitièmes",
110
+ "&#8541;" => "cinq huitièmes",
111
+ "⅞" => "sept huitièmes",
112
+ "&#8542;" => "sept huitièmes"
113
+ }.each do |original, converted|
114
+ define_method "test_vulgar_fractions_conversion: #{original}" do
115
+ assert_equal converted, original.convert_vulgar_fractions
116
+ end
117
+ end
118
+ end
@@ -144,13 +144,16 @@ class LocalizationTest < Test::Unit::TestCase
144
144
  end
145
145
  end
146
146
 
147
- def test_defaults_enforce_available_locales_to_true
147
+ def test_enforce_available_locales_default
148
+ return unless I18n.respond_to?(:enforce_available_locales)
148
149
  Stringex::Localization.backend = :i18n
150
+ assert_not_nil I18n.enforce_available_locales
149
151
  'Some String'.to_url
150
- assert_equal true, I18n.enforce_available_locales
152
+ assert_not_nil I18n.enforce_available_locales
151
153
  end
152
154
 
153
155
  def test_respects_user_enforce_available_locales_setting
156
+ return unless I18n.respond_to?(:enforce_available_locales)
154
157
  Stringex::Localization.backend = :i18n
155
158
  I18n.enforce_available_locales = false
156
159
  'Some String'.to_url
@@ -1,4 +1,4 @@
1
- # encoding: UTF-8
1
+ # encoding: utf-8
2
2
 
3
3
  require "test_helper"
4
4
  require "stringex"
@@ -118,6 +118,10 @@ class StringExtensionsTest < Test::Unit::TestCase
118
118
  assert_equal "under_scores", "Under Scores".to_url(:replace_whitespace_with => "_")
119
119
  end
120
120
 
121
+ def test_to_url_with_alternate_whitespace_replacement_and_with_limit_and_with_truncate_words_disabled
122
+ assert_equal "i_am_much", "I am much too long".to_url(:replace_whitespace_with => "_", :limit => 12, :truncate_words => false)
123
+ end
124
+
121
125
  def test_remove_formatting
122
126
  {
123
127
  "<p>This has 100% too much <em>formatting</em></p>" =>
@@ -280,6 +284,14 @@ class StringExtensionsTest < Test::Unit::TestCase
280
284
  end
281
285
  end
282
286
 
287
+ def test_remove_nonreadable_characters
288
+ cases = { "Jörg Immendor\u0014. Les théâtres" => "jorg-immendor-les-theatres",
289
+ }
290
+ cases.each do |plain, converted|
291
+ assert_equal converted, plain.to_url
292
+ end
293
+ end
294
+
283
295
  if defined?(RedCloth)
284
296
  def test_to_html
285
297
  {
@@ -45,7 +45,7 @@ class BasicGreekTest < Test::Unit::TestCase
45
45
  "Ϋ" => "Y",
46
46
  "Ύ" => "Y",
47
47
  "Φ" => "Ph",
48
- "Χ" => "Ks",
48
+ "Χ" => "X",
49
49
  "Ψ" => "Ps",
50
50
  "Ω" => "O",
51
51
  "Ώ" => "O",
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  require "test_helper"
4
- require "stringex"
4
+ require "stringex/unidecoder"
5
5
 
6
6
  class UnidecoderTest < Test::Unit::TestCase
7
7
  # Silly phrases courtesy of Frank da Cruz
@@ -61,6 +61,7 @@ class UnidecoderTest < Test::Unit::TestCase
61
61
  end
62
62
 
63
63
  def test_to_ascii
64
+ require "stringex/core_ext"
64
65
  DONT_CONVERT.each do |ascii|
65
66
  assert_equal ascii, ascii.to_ascii
66
67
  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.5.2
4
+ version: 2.6.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: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2016-01-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jeweler
@@ -58,14 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 1.3.7
61
+ version: 1.3.10
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 1.3.7
68
+ version: 1.3.10
69
+ - !ruby/object:Gem::Dependency
70
+ name: test-unit
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 3.0.9
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 3.0.9
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: activerecord
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -124,6 +138,7 @@ files:
124
138
  - lib/stringex/configuration/configurator.rb
125
139
  - lib/stringex/configuration/string_extensions.rb
126
140
  - lib/stringex/configuration_lite.rb
141
+ - lib/stringex/core_ext.rb
127
142
  - lib/stringex/localization.rb
128
143
  - lib/stringex/localization/backend/base.rb
129
144
  - lib/stringex/localization/backend/i18n.rb
@@ -319,7 +334,10 @@ files:
319
334
  - locales/da.yml
320
335
  - locales/de.yml
321
336
  - locales/en.yml
337
+ - locales/fr.yml
338
+ - locales/nb.yml
322
339
  - locales/nl.yml
340
+ - locales/no.yml
323
341
  - locales/pl.yml
324
342
  - locales/pt-BR.yml
325
343
  - locales/ru.yml
@@ -336,6 +354,7 @@ files:
336
354
  - test/unit/localization/de_test.rb
337
355
  - test/unit/localization/default_test.rb
338
356
  - test/unit/localization/en_test.rb
357
+ - test/unit/localization/fr_test.rb
339
358
  - test/unit/localization/nl_test.rb
340
359
  - test/unit/localization/pl_test.rb
341
360
  - test/unit/localization/pt_br_test.rb