[DRE-commits] [ruby-stringex] 01/04: Imported Upstream version 2.6.0
Youhei SASAKI
uwabami-guest at moszumanska.debian.org
Tue Jun 21 12:38:04 UTC 2016
This is an automated email from the git hooks/post-receive script.
uwabami-guest pushed a commit to annotated tag debian/2.6.0-1
in repository ruby-stringex.
commit 602ed3263b4e5745bf7b73f07edf65bb970bb394
Author: Youhei SASAKI <uwabami at gfd-dennou.org>
Date: Tue Jun 21 21:25:46 2016 +0900
Imported Upstream version 2.6.0
---
Gemfile | 3 +-
README.rdoc | 15 ++-
VERSION | 2 +-
checksums.yaml.gz | Bin 269 -> 0 bytes
lib/stringex.rb | 3 +-
lib/stringex/acts_as_url/adapter/base.rb | 12 ++-
lib/stringex/core_ext.rb | 10 ++
lib/stringex/localization/backend/i18n.rb | 7 +-
.../localization/conversion_expressions.rb | 3 +
lib/stringex/localization/converter.rb | 10 +-
lib/stringex/string_extensions.rb | 21 ++--
lib/stringex/unidecoder.rb | 15 +--
lib/stringex/unidecoder_data/x03.yml | 4 +-
locales/fr.yml | 72 +++++++++++++
locales/nb.yml | 76 +++++++++++++
locales/no.yml | 76 +++++++++++++
metadata.yml | 27 ++++-
stringex.gemspec | 20 ++--
test/unit/acts_as_url_integration_test.rb | 13 +++
test/unit/localization/fr_test.rb | 118 +++++++++++++++++++++
test/unit/localization_test.rb | 7 +-
test/unit/string_extensions_test.rb | 14 ++-
test/unit/unicode_point_suite/basic_greek_test.rb | 2 +-
test/unit/unidecoder_test.rb | 3 +-
24 files changed, 490 insertions(+), 43 deletions(-)
diff --git a/Gemfile b/Gemfile
index ace593e..2f977e0 100644
--- a/Gemfile
+++ b/Gemfile
@@ -27,7 +27,8 @@ group :development do
gem 'travis-lint', '1.7.0'
# Can I state that I really dislike camelcased gem names?
gem 'RedCloth', '4.2.9'
- gem 'sqlite3', '1.3.7'
+ gem 'sqlite3', '1.3.10'
+ gem 'test-unit', '3.0.9'
if activerecord?
gem 'activerecord', '4.0.3'
diff --git a/README.rdoc b/README.rdoc
index 1793587..840e3ec 100644
--- a/README.rdoc
+++ b/README.rdoc
@@ -1,4 +1,4 @@
-= 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]
+= 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]
Some [hopefully] useful extensions to Ruby's String class. It is made up of three libraries: ActsAsUrl, Unidecoder, and StringExtensions.
@@ -34,7 +34,7 @@ which will populate the <tt>url</tt> attribute on the object with the converted
<tt>:blacklist</tt>:: List of urls that should not be allowed. Default is <tt>%w{new}</tt> [which avoids confusion
on urls like <tt>/documents/new</tt>].
<tt>:blacklist_policy</tt>:: Proc or lambda defining new naming behavior when blacklisted urls are encountered.
- Default converts <tt>/documents/new</tt> to </tt>/documents/new-document</tt>.
+ Default converts <tt>/documents/new</tt> to <tt>/documents/new-document</tt>.
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
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])
-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.
+You may require only the unidecoder (and its dependent localization) via
+
+ require "stringex/unidecoder"
+
+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:
+
+ require "stringex/core_ext"
+
+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.
+
== StringExtensions
diff --git a/VERSION b/VERSION
index 21b159d..914ec96 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.5.2
\ No newline at end of file
+2.6.0
\ No newline at end of file
diff --git a/checksums.yaml.gz b/checksums.yaml.gz
deleted file mode 100644
index 7683b44..0000000
Binary files a/checksums.yaml.gz and /dev/null differ
diff --git a/lib/stringex.rb b/lib/stringex.rb
index a43cb75..796b6fd 100644
--- a/lib/stringex.rb
+++ b/lib/stringex.rb
@@ -8,8 +8,7 @@ require 'stringex/unidecoder'
require 'stringex/acts_as_url'
require 'stringex/version'
-String.send :include, Stringex::StringExtensions::PublicInstanceMethods
-String.send :extend, Stringex::StringExtensions::PublicClassMethods
+require 'stringex/core_ext'
Stringex::ActsAsUrl::Adapter.load_available
diff --git a/lib/stringex/acts_as_url/adapter/base.rb b/lib/stringex/acts_as_url/adapter/base.rb
index afe5e41..b8ed8b1 100644
--- a/lib/stringex/acts_as_url/adapter/base.rb
+++ b/lib/stringex/acts_as_url/adapter/base.rb
@@ -119,14 +119,22 @@ module Stringex
end
def handle_duplicate_url!
- return if url_owners.none?{|owner| url_attribute_for(owner) == base_url}
+ return if !url_taken?(base_url)
n = 1
- while url_owners.any?{|owner| url_attribute_for(owner) == duplicate_for_base_url(n)}
+ while url_taken?(duplicate_for_base_url(n))
n = n.succ
end
write_url_attribute duplicate_for_base_url(n)
end
+ def url_taken?(url)
+ if settings.url_taken_method
+ instance.send(settings.url_taken_method, url)
+ else
+ url_owners.any?{|owner| url_attribute_for(owner) == url}
+ end
+ end
+
def handle_url!
self.base_url = instance.send(settings.url_attribute)
modify_base_url if is_blank?(base_url) || !settings.only_when_blank
diff --git a/lib/stringex/core_ext.rb b/lib/stringex/core_ext.rb
new file mode 100644
index 0000000..f744d92
--- /dev/null
+++ b/lib/stringex/core_ext.rb
@@ -0,0 +1,10 @@
+Stringex = Module.new unless defined?(Stringex)
+ensure_module_defined = ->(base, module_name){
+ base.const_set(module_name, Module.new) unless base.const_defined?(module_name)
+}
+ensure_module_defined[Stringex, :StringExtensions]
+ensure_module_defined[Stringex::StringExtensions, :PublicInstanceMethods]
+ensure_module_defined[Stringex::StringExtensions, :PublicClassMethods]
+
+String.send :include, Stringex::StringExtensions::PublicInstanceMethods
+String.send :extend, Stringex::StringExtensions::PublicClassMethods
diff --git a/lib/stringex/localization/backend/i18n.rb b/lib/stringex/localization/backend/i18n.rb
index d5be33a..2e1da37 100644
--- a/lib/stringex/localization/backend/i18n.rb
+++ b/lib/stringex/localization/backend/i18n.rb
@@ -5,6 +5,11 @@ module Stringex
LOAD_PATH_BASE = File.join(File.expand_path(File.dirname(__FILE__)), '..', '..', '..', '..', 'locales')
class << self
+ def reset!
+ super
+ ::I18n.reload! if defined?(::I18n) && ::I18n.respond_to?(:reload!)
+ end
+
def locale
@locale || ::I18n.locale
end
@@ -59,7 +64,7 @@ module Stringex
def ensure_locales_enforced_or_not
return unless ::I18n.respond_to?(:enforce_available_locales)
# Allow users to have set this to false manually but default to true
- return if ::I18n.enforce_available_locales != nil
+ return unless ::I18n.enforce_available_locales == nil
::I18n.enforce_available_locales = ::I18n.available_locales != []
end
end
diff --git a/lib/stringex/localization/conversion_expressions.rb b/lib/stringex/localization/conversion_expressions.rb
index 0e24dbe..c1c60bc 100644
--- a/lib/stringex/localization/conversion_expressions.rb
+++ b/lib/stringex/localization/conversion_expressions.rb
@@ -103,6 +103,8 @@ module Stringex
/…/ => "...",
}
+ UNREADABLE_CONTROL_CHARACTERS = /[[:cntrl:]]/
+
# Ordered by denominator then numerator of the value
VULGAR_FRACTIONS = {
:half => /(½|½|½)/,
@@ -138,6 +140,7 @@ module Stringex
html_entities
html_tag
smart_punctuation
+ unreadable_control_characters
vulgar_fractions
whitespace
}.each do |conversion_type|
diff --git a/lib/stringex/localization/converter.rb b/lib/stringex/localization/converter.rb
index 8c84f33..b9ad9ef 100644
--- a/lib/stringex/localization/converter.rb
+++ b/lib/stringex/localization/converter.rb
@@ -59,7 +59,11 @@ module Stringex
end
end
- protected
+ protected
+
+ def unreadable_control_characters
+ string.gsub! expressions.unreadable_control_characters, ''
+ end
def abbreviations
string.gsub! expressions.abbreviation do |x|
@@ -107,7 +111,7 @@ module Stringex
end
end
- private
+ private
def expressions
ConversionExpressions
@@ -122,4 +126,4 @@ module Stringex
end
end
end
-end
\ No newline at end of file
+end
diff --git a/lib/stringex/string_extensions.rb b/lib/stringex/string_extensions.rb
index 16d38af..2f0eb0c 100644
--- a/lib/stringex/string_extensions.rb
+++ b/lib/stringex/string_extensions.rb
@@ -93,18 +93,24 @@ module Stringex
end
end
+ def convert_unreadable_control_characters
+ stringex_convert do
+ translate! :unreadable_control_characters
+ end
+ end
+
# Returns the string limited in size to the value of limit.
- def limit(limit = nil, truncate_words = true)
+ def limit(limit = nil, truncate_words = true, whitespace_replacement_token = "-")
if limit.nil?
self
else
- truncate_words == false ? self.whole_word_limit(limit) : self[0...limit]
+ truncate_words == false ? self.whole_word_limit(limit, whitespace_replacement_token) : self[0...limit]
end
end
- def whole_word_limit(limit)
+ def whole_word_limit(limit, whitespace_replacement_token = "-")
whole_words = []
- words = self.split('-')
+ words = self.split(whitespace_replacement_token)
words.each do |word|
if word.size > limit
@@ -115,7 +121,7 @@ module Stringex
end
end
- whole_words.join('-')
+ whole_words.join(whitespace_replacement_token)
end
@@ -126,6 +132,7 @@ module Stringex
convert_smart_punctuation.
convert_accented_html_entities.
convert_vulgar_fractions.
+ convert_unreadable_control_characters.
convert_miscellaneous_html_entities.
convert_miscellaneous_characters(options).
to_ascii.
@@ -187,8 +194,8 @@ module Stringex
whitespace_replacement_token = options[:replace_whitespace_with]
dummy = remove_formatting(options).
replace_whitespace(whitespace_replacement_token).
- collapse("-").
- limit(options[:limit], options[:truncate_words])
+ collapse(whitespace_replacement_token).
+ limit(options[:limit], options[:truncate_words], whitespace_replacement_token)
dummy.downcase! unless options[:force_downcase] == false
dummy
end
diff --git a/lib/stringex/unidecoder.rb b/lib/stringex/unidecoder.rb
index 3271610..cccb161 100644
--- a/lib/stringex/unidecoder.rb
+++ b/lib/stringex/unidecoder.rb
@@ -1,6 +1,7 @@
# encoding: UTF-8
require 'yaml'
+require 'stringex/localization'
module Stringex
module Unidecoder
@@ -68,12 +69,14 @@ module Stringex
end
module Stringex
- module StringExtensions::PublicInstanceMethods
- # Returns string with its UTF-8 characters transliterated to ASCII ones. Example:
- #
- # "⠋⠗⠁⠝⠉⠑".to_ascii #=> "france"
- def to_ascii
- Stringex::Unidecoder.decode(self)
+ module StringExtensions
+ module PublicInstanceMethods
+ # Returns string with its UTF-8 characters transliterated to ASCII ones. Example:
+ #
+ # "⠋⠗⠁⠝⠉⠑".to_ascii #=> "france"
+ def to_ascii
+ Stringex::Unidecoder.decode(self)
+ end
end
end
end
diff --git a/lib/stringex/unidecoder_data/x03.yml b/lib/stringex/unidecoder_data/x03.yml
index 9cbb947..0561452 100644
--- a/lib/stringex/unidecoder_data/x03.yml
+++ b/lib/stringex/unidecoder_data/x03.yml
@@ -166,7 +166,7 @@
- T
- Y
- Ph
-- Ks
+- X
- Ps
- O
- I
@@ -253,4 +253,4 @@
- '[?]'
- '[?]'
- '[?]'
-- '[?]'
\ No newline at end of file
+- '[?]'
diff --git a/locales/fr.yml b/locales/fr.yml
new file mode 100644
index 0000000..a318c2b
--- /dev/null
+++ b/locales/fr.yml
@@ -0,0 +1,72 @@
+# NOTE: Some translation keys make use of matches from regular expressions
+# to manipulate whitespace and order. Please consult the source code for
+# Stringex::Localization::ConversionExpressions to see what those
+# regular expressions look like if you need to manipulate the order
+# differently than the usage below.
+fr:
+ stringex:
+ characters:
+ and: et
+ at: arobase
+ divide: divisé par
+ degrees: degrés
+ dot: \1 point \2
+ ellipsis: point point point
+ equals: égal
+ number: numéro
+ percent: pourcent
+ plus: plus
+ slash: slash
+ star: étoile
+ currencies:
+ generic: \1 livres
+ dollars: \1 dollars
+ dollars_cents: \1 dollars \2 cents
+ pounds: \1 livres
+ pounds_pence: \1 livres \2 pennies
+ euros: \1 euros
+ euros_cents: \1 euros \2 cents
+ yen: \1 yen
+ reais: \1 reais
+ reais_cents: \1 reais \2 cents
+ html_entities:
+ amp: et
+ cent: " cents"
+ copy: (c)
+ deg: " degrés "
+ divide: " divisé par "
+ double_quote: '"'
+ ellipsis: "..."
+ en_dash: "-"
+ em_dash: "--"
+ frac14: un quart
+ frac12: un demi
+ frac34: trois quarts
+ gt: ">"
+ lt: <
+ nbsp: " "
+ pound: " livres "
+ reg: (r)
+ single_quote: "'"
+ times: x
+ trade: (tm)
+ yen: " yen "
+ vulgar_fractions:
+ half: un demi
+ one_third: un tiers
+ two_thirds: deux tiers
+ one_fourth: un quart
+ three_fourths: trois quarts
+ one_fifth: un cinquième
+ two_fifths: deux cinquièmes
+ three_fifths: trois cinquièmes
+ four_fifths: quatre cinquièmes
+ one_sixth: un sixième
+ five_sixths: cinq sixièmes
+ one_eighth: un huitième
+ three_eighths: trois huitièmes
+ five_eighths: cinq huitièmes
+ seven_eighths: sept huitièmes
+ transliterations:
+ é: e
+ è: e
\ No newline at end of file
diff --git a/locales/nb.yml b/locales/nb.yml
new file mode 100644
index 0000000..3135b98
--- /dev/null
+++ b/locales/nb.yml
@@ -0,0 +1,76 @@
+# NOTE: Some translation keys make use of matches from regular expressions
+# to manipulate whitespace and order. Please consult the source code for
+# Stringex::Localization::ConversionExpressions to see what those
+# regular expressions look like if you need to manipulate the order
+# differently than the usage below.
+nb:
+ stringex:
+ characters:
+ and: og
+ at: krøllalfa
+ divide: delt på
+ degrees: grader
+ dot: \1 dot \2
+ ellipsis: prikk prikk prikk
+ equals: er lik
+ number: nummer
+ percent: prosent
+ plus: pluss
+ slash: skråstrek
+ star: stjerne
+ currencies:
+ generic: \1 kroner
+ dollars: \1 dollar
+ dollars_cents: \1 dollar \2 cent
+ pounds: \1 pund
+ pounds_pence: \1 pund \2 pence
+ euros: \1 euro
+ euros_cents: \1 euro \2 cent
+ yen: \1 yen
+ reais: \1 reais
+ reais_cents: \1 reais \2 cent
+ html_entities:
+ amp: og
+ cent: " cents"
+ copy: (c)
+ deg: " grader "
+ divide: " delt på "
+ double_quote: '"'
+ ellipsis: "..."
+ en_dash: "-"
+ em_dash: "--"
+ frac14: en fjerdedel
+ frac12: halv
+ frac34: tre fjerdedeler
+ gt: ">"
+ lt: <
+ nbsp: " "
+ pound: " pund "
+ reg: (r)
+ single_quote: "'"
+ times: x
+ trade: (tm)
+ yen: " yen "
+ vulgar_fractions:
+ half: halv
+ one_third: en tredjedel
+ two_thirds: to tredjedeler
+ one_fourth: en fjerdedel
+ three_fourths: tre fjerdedeler
+ one_fifth: en femtedel
+ two_fifths: to femtedeler
+ three_fifths: tre femtedeler
+ four_fifths: fire femtedeler
+ one_sixth: en sjettedel
+ five_sixths: fem sjettedeler
+ one_eighth: en åttendel
+ three_eighths: tre åttendeler
+ five_eighths: fem åttendeler
+ seven_eighths: sju åttendeler
+ transliterations:
+ Å: AA
+ Æ: AE
+ Ø: OE
+ å: aa
+ æ: ae
+ ø: oe
\ No newline at end of file
diff --git a/locales/no.yml b/locales/no.yml
new file mode 100644
index 0000000..eaa60d7
--- /dev/null
+++ b/locales/no.yml
@@ -0,0 +1,76 @@
+# NOTE: Some translation keys make use of matches from regular expressions
+# to manipulate whitespace and order. Please consult the source code for
+# Stringex::Localization::ConversionExpressions to see what those
+# regular expressions look like if you need to manipulate the order
+# differently than the usage below.
+'no':
+ stringex:
+ characters:
+ and: og
+ at: krøllalfa
+ divide: delt på
+ degrees: grader
+ dot: \1 dot \2
+ ellipsis: prikk prikk prikk
+ equals: er lik
+ number: nummer
+ percent: prosent
+ plus: pluss
+ slash: skråstrek
+ star: stjerne
+ currencies:
+ generic: \1 kroner
+ dollars: \1 dollar
+ dollars_cents: \1 dollar \2 cent
+ pounds: \1 pund
+ pounds_pence: \1 pund \2 pence
+ euros: \1 euro
+ euros_cents: \1 euro \2 cent
+ yen: \1 yen
+ reais: \1 reais
+ reais_cents: \1 reais \2 cent
+ html_entities:
+ amp: og
+ cent: " cents"
+ copy: (c)
+ deg: " grader "
+ divide: " delt på "
+ double_quote: '"'
+ ellipsis: "..."
+ en_dash: "-"
+ em_dash: "--"
+ frac14: en fjerdedel
+ frac12: halv
+ frac34: tre fjerdedeler
+ gt: ">"
+ lt: <
+ nbsp: " "
+ pound: " pund "
+ reg: (r)
+ single_quote: "'"
+ times: x
+ trade: (tm)
+ yen: " yen "
+ vulgar_fractions:
+ half: halv
+ one_third: en tredjedel
+ two_thirds: to tredjedeler
+ one_fourth: en fjerdedel
+ three_fourths: tre fjerdedeler
+ one_fifth: en femtedel
+ two_fifths: to femtedeler
+ three_fifths: tre femtedeler
+ four_fifths: fire femtedeler
+ one_sixth: en sjettedel
+ five_sixths: fem sjettedeler
+ one_eighth: en åttendel
+ three_eighths: tre åttendeler
+ five_eighths: fem åttendeler
+ seven_eighths: sju åttendeler
+ transliterations:
+ Å: AA
+ Æ: AE
+ Ø: OE
+ å: aa
+ æ: ae
+ ø: oe
diff --git a/metadata.yml b/metadata.yml
index 71a52ce..05d62d5 100644
--- a/metadata.yml
+++ b/metadata.yml
@@ -1,14 +1,14 @@
--- !ruby/object:Gem::Specification
name: stringex
version: !ruby/object:Gem::Version
- version: 2.5.2
+ version: 2.6.0
platform: ruby
authors:
- Russell Norris
autorequire:
bindir: bin
cert_chain: []
-date: 2014-04-09 00:00:00.000000000 Z
+date: 2016-01-29 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: jeweler
@@ -58,14 +58,28 @@ dependencies:
requirements:
- - '='
- !ruby/object:Gem::Version
- version: 1.3.7
+ version: 1.3.10
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - '='
- !ruby/object:Gem::Version
- version: 1.3.7
+ version: 1.3.10
+- !ruby/object:Gem::Dependency
+ name: test-unit
+ requirement: !ruby/object:Gem::Requirement
+ requirements:
+ - - '='
+ - !ruby/object:Gem::Version
+ version: 3.0.9
+ type: :development
+ prerelease: false
+ version_requirements: !ruby/object:Gem::Requirement
+ requirements:
+ - - '='
+ - !ruby/object:Gem::Version
+ version: 3.0.9
- !ruby/object:Gem::Dependency
name: activerecord
requirement: !ruby/object:Gem::Requirement
@@ -124,6 +138,7 @@ files:
- lib/stringex/configuration/configurator.rb
- lib/stringex/configuration/string_extensions.rb
- lib/stringex/configuration_lite.rb
+- lib/stringex/core_ext.rb
- lib/stringex/localization.rb
- lib/stringex/localization/backend/base.rb
- lib/stringex/localization/backend/i18n.rb
@@ -319,7 +334,10 @@ files:
- locales/da.yml
- locales/de.yml
- locales/en.yml
+- locales/fr.yml
+- locales/nb.yml
- locales/nl.yml
+- locales/no.yml
- locales/pl.yml
- locales/pt-BR.yml
- locales/ru.yml
@@ -336,6 +354,7 @@ files:
- test/unit/localization/de_test.rb
- test/unit/localization/default_test.rb
- test/unit/localization/en_test.rb
+- test/unit/localization/fr_test.rb
- test/unit/localization/nl_test.rb
- test/unit/localization/pl_test.rb
- test/unit/localization/pt_br_test.rb
diff --git a/stringex.gemspec b/stringex.gemspec
index 6f59345..ec2c1e8 100644
--- a/stringex.gemspec
+++ b/stringex.gemspec
@@ -2,16 +2,16 @@
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
-# stub: stringex 2.5.2 ruby lib
+# stub: stringex 2.6.0 ruby lib
Gem::Specification.new do |s|
s.name = "stringex"
- s.version = "2.5.2"
+ s.version = "2.6.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Russell Norris"]
- s.date = "2014-04-09"
+ s.date = "2016-01-29"
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]."
s.email = "rsl at luckysneaks.com"
s.extra_rdoc_files = [
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
"lib/stringex/configuration/configurator.rb",
"lib/stringex/configuration/string_extensions.rb",
"lib/stringex/configuration_lite.rb",
+ "lib/stringex/core_ext.rb",
"lib/stringex/localization.rb",
"lib/stringex/localization/backend/base.rb",
"lib/stringex/localization/backend/i18n.rb",
@@ -233,7 +234,10 @@ Gem::Specification.new do |s|
"locales/da.yml",
"locales/de.yml",
"locales/en.yml",
+ "locales/fr.yml",
+ "locales/nb.yml",
"locales/nl.yml",
+ "locales/no.yml",
"locales/pl.yml",
"locales/pt-BR.yml",
"locales/ru.yml",
@@ -250,6 +254,7 @@ Gem::Specification.new do |s|
"test/unit/localization/de_test.rb",
"test/unit/localization/default_test.rb",
"test/unit/localization/en_test.rb",
+ "test/unit/localization/fr_test.rb",
"test/unit/localization/nl_test.rb",
"test/unit/localization/pl_test.rb",
"test/unit/localization/pt_br_test.rb",
@@ -280,14 +285,16 @@ Gem::Specification.new do |s|
s.add_development_dependency(%q<jeweler>, ["= 2.0.1"])
s.add_development_dependency(%q<travis-lint>, ["= 1.7.0"])
s.add_development_dependency(%q<RedCloth>, ["= 4.2.9"])
- s.add_development_dependency(%q<sqlite3>, ["= 1.3.7"])
+ s.add_development_dependency(%q<sqlite3>, ["= 1.3.10"])
+ s.add_development_dependency(%q<test-unit>, ["= 3.0.9"])
s.add_development_dependency(%q<activerecord>, ["= 4.0.3"])
s.add_development_dependency(%q<i18n>, ["= 0.6.9"])
else
s.add_dependency(%q<jeweler>, ["= 2.0.1"])
s.add_dependency(%q<travis-lint>, ["= 1.7.0"])
s.add_dependency(%q<RedCloth>, ["= 4.2.9"])
- s.add_dependency(%q<sqlite3>, ["= 1.3.7"])
+ s.add_dependency(%q<sqlite3>, ["= 1.3.10"])
+ s.add_dependency(%q<test-unit>, ["= 3.0.9"])
s.add_dependency(%q<activerecord>, ["= 4.0.3"])
s.add_dependency(%q<i18n>, ["= 0.6.9"])
end
@@ -295,7 +302,8 @@ Gem::Specification.new do |s|
s.add_dependency(%q<jeweler>, ["= 2.0.1"])
s.add_dependency(%q<travis-lint>, ["= 1.7.0"])
s.add_dependency(%q<RedCloth>, ["= 4.2.9"])
- s.add_dependency(%q<sqlite3>, ["= 1.3.7"])
+ s.add_dependency(%q<sqlite3>, ["= 1.3.10"])
+ s.add_dependency(%q<test-unit>, ["= 3.0.9"])
s.add_dependency(%q<activerecord>, ["= 4.0.3"])
s.add_dependency(%q<i18n>, ["= 0.6.9"])
end
diff --git a/test/unit/acts_as_url_integration_test.rb b/test/unit/acts_as_url_integration_test.rb
index 08f6909..d4b28e3 100644
--- a/test/unit/acts_as_url_integration_test.rb
+++ b/test/unit/acts_as_url_integration_test.rb
@@ -376,4 +376,17 @@ class ActsAsUrlIntegrationTest < Test::Unit::TestCase
@doc = Document.create(:title => "title with many whole words")
assert_equal 'title-with-many', @doc.url
end
+
+ def test_should_allow_overriding_url_taken_method
+ Document.class_eval do
+ acts_as_url :title, :url_taken_method => :url_taken?
+
+ def url_taken?(url)
+ ["unique", "unique-1", "unique-2"].include?(url)
+ end
+ end
+
+ @doc = Document.create(:title => "unique")
+ assert_equal "unique-3", @doc.url
+ end
end
diff --git a/test/unit/localization/fr_test.rb b/test/unit/localization/fr_test.rb
new file mode 100644
index 0000000..660a5c6
--- /dev/null
+++ b/test/unit/localization/fr_test.rb
@@ -0,0 +1,118 @@
+# encoding: UTF-8
+
+require 'test_helper'
+require 'i18n'
+require 'stringex'
+
+class FrenchYAMLLocalizationTest < Test::Unit::TestCase
+ def setup
+ Stringex::Localization.reset!
+ Stringex::Localization.backend = :i18n
+ Stringex::Localization.backend.load_translations :fr
+ Stringex::Localization.locale = :fr
+ end
+
+ {
+ "foo & bar" => "foo et bar",
+ "AT&T" => "AT et T",
+ "99° est normal" => "99 degrés est normal",
+ "4 ÷ 2 is 2" => "4 divisé par 2 is 2",
+ "webcrawler.com" => "webcrawler point com",
+ "Well..." => "Well point point point",
+ "x=1" => "x égal 1",
+ "a #2 pencil" => "a numéro 2 pencil",
+ "100%" => "100 pourcent",
+ "cost+tax" => "cost plus tax",
+ "batman/robin fan fiction" => "batman slash robin fan fiction",
+ "dial *69" => "dial étoile 69",
+ " i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
+ }.each do |original, converted|
+ define_method "test_character_conversion: '#{original}'" do
+ assert_equal converted, original.convert_miscellaneous_characters
+ end
+ end
+
+ {
+ "¤20" => "20 livres",
+ "$100" => "100 dollars",
+ "$19.99" => "19 dollars 99 cents",
+ "£100" => "100 livres",
+ "£19.99" => "19 livres 99 pennies",
+ "€100" => "100 euros",
+ "€19.99" => "19 euros 99 cents",
+ "¥1000" => "1000 yen"
+ }.each do |original, converted|
+ define_method "test_currency_conversion: '#{original}'" do
+ assert_equal converted, original.convert_miscellaneous_characters
+ end
+ end
+
+ {
+ "Tea & Sympathy" => "Tea et Sympathy",
+ "10¢" => "10 cents",
+ "©2000" => "(c)2000",
+ "98° is fine" => "98 degrés is fine",
+ "10÷5" => "10 divisé par 5",
+ ""quoted"" => '"quoted"',
+ "to be continued…" => "to be continued...",
+ "2000–2004" => "2000-2004",
+ "I wish—oh, never mind" => "I wish--oh, never mind",
+ "½ ounce of gold" => "un demi ounce of gold",
+ "1 et ¼ d'once de platinium" => "1 et un quart d'once de platinium",
+ "9 et ¾ d'once de platinium" => "9 et trois quarts d'once de platinium",
+ "3>2" => "3>2",
+ "2<3" => "2<3",
+ "two words" => "two words",
+ "£100" => "livres 100",
+ "Walmart®" => "Walmart(r)",
+ "'single quoted'" => "'single quoted'",
+ "2×4" => "2x4",
+ "Programming™" => "Programming(tm)",
+ "¥20000" => "yen 20000",
+ " i leave whitespace on ends unchanged " => " i leave whitespace on ends unchanged "
+ }.each do |original, converted|
+ define_method "test_html_entity_conversion: '#{original}'" do
+ assert_equal converted, original.convert_miscellaneous_html_entities
+ end
+ end
+
+ {
+ "½" => "un demi",
+ "½" => "un demi",
+ "½" => "un demi",
+ "⅓" => "un tiers",
+ "⅓" => "un tiers",
+ "⅔" => "deux tiers",
+ "⅔" => "deux tiers",
+ "¼" => "un quart",
+ "¼" => "un quart",
+ "¼" => "un quart",
+ "¾" => "trois quarts",
+ "¾" => "trois quarts",
+ "¾" => "trois quarts",
+ "⅕" => "un cinquième",
+ "⅕" => "un cinquième",
+ "⅖" => "deux cinquièmes",
+ "⅖" => "deux cinquièmes",
+ "⅗" => "trois cinquièmes",
+ "⅗" => "trois cinquièmes",
+ "⅘" => "quatre cinquièmes",
+ "⅘" => "quatre cinquièmes",
+ "⅙" => "un sixième",
+ "⅙" => "un sixième",
+ "⅚" => "cinq sixièmes",
+ "⅚" => "cinq sixièmes",
+ "⅛" => "un huitième",
+ "⅛" => "un huitième",
+ "⅜" => "trois huitièmes",
+ "⅜" => "trois huitièmes",
+ "⅝" => "cinq huitièmes",
+ "⅝" => "cinq huitièmes",
+ "⅞" => "sept huitièmes",
+ "⅞" => "sept huitièmes"
+ }.each do |original, converted|
+ define_method "test_vulgar_fractions_conversion: #{original}" do
+ assert_equal converted, original.convert_vulgar_fractions
+ end
+ end
+end
diff --git a/test/unit/localization_test.rb b/test/unit/localization_test.rb
index 289ed1a..e6835e6 100644
--- a/test/unit/localization_test.rb
+++ b/test/unit/localization_test.rb
@@ -144,13 +144,16 @@ class LocalizationTest < Test::Unit::TestCase
end
end
- def test_defaults_enforce_available_locales_to_true
+ def test_enforce_available_locales_default
+ return unless I18n.respond_to?(:enforce_available_locales)
Stringex::Localization.backend = :i18n
+ assert_not_nil I18n.enforce_available_locales
'Some String'.to_url
- assert_equal true, I18n.enforce_available_locales
+ assert_not_nil I18n.enforce_available_locales
end
def test_respects_user_enforce_available_locales_setting
+ return unless I18n.respond_to?(:enforce_available_locales)
Stringex::Localization.backend = :i18n
I18n.enforce_available_locales = false
'Some String'.to_url
diff --git a/test/unit/string_extensions_test.rb b/test/unit/string_extensions_test.rb
index 2a1b7d1..8192675 100644
--- a/test/unit/string_extensions_test.rb
+++ b/test/unit/string_extensions_test.rb
@@ -1,4 +1,4 @@
-# encoding: UTF-8
+# encoding: utf-8
require "test_helper"
require "stringex"
@@ -118,6 +118,10 @@ class StringExtensionsTest < Test::Unit::TestCase
assert_equal "under_scores", "Under Scores".to_url(:replace_whitespace_with => "_")
end
+ def test_to_url_with_alternate_whitespace_replacement_and_with_limit_and_with_truncate_words_disabled
+ assert_equal "i_am_much", "I am much too long".to_url(:replace_whitespace_with => "_", :limit => 12, :truncate_words => false)
+ end
+
def test_remove_formatting
{
"<p>This has 100% too much <em>formatting</em></p>" =>
@@ -280,6 +284,14 @@ class StringExtensionsTest < Test::Unit::TestCase
end
end
+ def test_remove_nonreadable_characters
+ cases = { "Jörg Immendor\u0014. Les théâtres" => "jorg-immendor-les-theatres",
+ }
+ cases.each do |plain, converted|
+ assert_equal converted, plain.to_url
+ end
+ end
+
if defined?(RedCloth)
def test_to_html
{
diff --git a/test/unit/unicode_point_suite/basic_greek_test.rb b/test/unit/unicode_point_suite/basic_greek_test.rb
index f8efabc..7faf26a 100644
--- a/test/unit/unicode_point_suite/basic_greek_test.rb
+++ b/test/unit/unicode_point_suite/basic_greek_test.rb
@@ -45,7 +45,7 @@ class BasicGreekTest < Test::Unit::TestCase
"Ϋ" => "Y",
"Ύ" => "Y",
"Φ" => "Ph",
- "Χ" => "Ks",
+ "Χ" => "X",
"Ψ" => "Ps",
"Ω" => "O",
"Ώ" => "O",
diff --git a/test/unit/unidecoder_test.rb b/test/unit/unidecoder_test.rb
index 3c3659f..f090645 100644
--- a/test/unit/unidecoder_test.rb
+++ b/test/unit/unidecoder_test.rb
@@ -1,7 +1,7 @@
# encoding: UTF-8
require "test_helper"
-require "stringex"
+require "stringex/unidecoder"
class UnidecoderTest < Test::Unit::TestCase
# Silly phrases courtesy of Frank da Cruz
@@ -61,6 +61,7 @@ class UnidecoderTest < Test::Unit::TestCase
end
def test_to_ascii
+ require "stringex/core_ext"
DONT_CONVERT.each do |ascii|
assert_equal ascii, ascii.to_ascii
end
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/ruby-stringex.git
More information about the Pkg-ruby-extras-commits
mailing list