Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add compatibility fallbacks for unicode_utils.

UnicodeUtils doesn't build on Ruby 1.8.  This change will give
access to good upcase and downcase methods on ActiveSupport, as
well as fallbacks.
  • Loading branch information...
commit 6793df81ce99e0ce5a5311f2f12821358d9d1d1f 1 parent 60e62f5
@cpence cpence authored
View
1  Gemfile
@@ -8,3 +8,4 @@ group :development do
end
gem 'json', :platforms => [:ruby_18]
+gem 'unicode_utils', :platforms => [:ruby_19]
View
1  citeproc-ruby.gemspec
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency('logging', '~> 1.5')
s.add_runtime_dependency('nokogiri', '~> 1.4')
- s.add_runtime_dependency('unicode_utils', '~> 1.0')
s.add_development_dependency('bundler', '~> 1.0')
s.add_development_dependency('rdoc', '~> 2.5')
View
6 lib/citeproc.rb
@@ -7,11 +7,6 @@
require 'nokogiri'
require 'json'
-#require 'activesupport'
-
-require 'unicode_utils/upcase'
-require 'unicode_utils/downcase'
-
module CiteProc
@log = Logging.logger[self.name]
@@ -39,6 +34,7 @@ def log(*args)
require 'extensions/core'
require 'support/attributes'
require 'support/tree'
+require 'support/compatibility'
require 'csl/node'
require 'csl/term'
View
8 lib/plugins/formats/default.rb
@@ -102,14 +102,14 @@ def set_text_case(text_case)
case text_case
when 'lowercase'
- @tokens.each { |token| token.content = UnicodeUtils ? UnicodeUtils.downcase(token.content) : token.content.downcase }
+ @tokens.each { |token| token.content = Support.downcase(token.content) }
when 'uppercase'
- @tokens.each { |token| token.content = UnicodeUtils ? UnicodeUtils.upcase(token.content) : token.content.upcase }
+ @tokens.each { |token| token.content = Support.upcase(token.content) }
when 'capitalize-first'
token = @tokens.detect { |token| !token.annotations.include?('nocase') }
- token.content.sub!(/^./) { UnicodeUtils ? UnicodeUtils.upcase($&) : $&.upcase }
+ token.content.sub!(/^./) { Support.upcase($&) }
when 'capitalize-all'
# @tokens.each { |token| token.content.gsub!(/\b\w/) { $&.upcase } unless token.annotations.include?('nocase') }
@@ -117,7 +117,7 @@ def set_text_case(text_case)
# TODO exact specification?
when 'title'
- @tokens.each { |token| token.content = token.content.split(/(\s+)/).map { |w| w.match(/^(and|of|a|an|the)$/i) ? w : w.gsub(/\b\w/) { UnicodeUtils ? UnicodeUtils.upcase($&) : $&.upcase } }.join.sub(/^(\w)/) {$&.upcase} unless token.annotations.include?('nocase') }
+ @tokens.each { |token| token.content = token.content.split(/(\s+)/).map { |w| w.match(/^(and|of|a|an|the)$/i) ? w : w.gsub(/\b\w/) { Support.upcase($&) } }.join.sub(/^(\w)/) {$&.upcase} unless token.annotations.include?('nocase') }
# TODO exact specification?
when 'sentence'
View
42 lib/support/compatibility.rb
@@ -0,0 +1,42 @@
+
+begin
+ require 'unicode_utils'
+
+ module Support
+ def self.upcase(string)
+ UnicodeUtils.upcase(string)
+ end
+
+ def self.downcase(string)
+ UnicodeUtils.downcase(string)
+ end
+ end
+
+rescue LoadError
+ begin
+ require 'active_support/multibyte/chars'
+
+ module Support
+ def self.upcase(string)
+ ActiveSupport::Multibyte::Chars.new(string).upcase.to_s
+ end
+
+ def self.downcase(string)
+ ActiveSupport::Multibyte::Chars.new(string).downcase.to_s
+ end
+ end
+
+ rescue LoadError
+
+ module Support
+ def self.upcase(string)
+ string.upcase
+ end
+
+ def self.downcase(string)
+ string.downcase
+ end
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.