citeproc-ruby 0.0.3 → 0.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.
data/README.md CHANGED
@@ -14,11 +14,19 @@ and `citeproc-js` gems; meanwhile, however, these gems are not compatible, so if
14
14
  you want to use the current `citeproc-ruby` gem, make sure that neither of the
15
15
  other gems is installed.
16
16
 
17
+ Unicode support may be provided by the `unicode-utils` gem (on Ruby 1.9 only),
18
+ by ActiveSupport, by the `unicode` gem (on Ruby 1.8 only), by the Java-based
19
+ support in JRuby, or naively by the `upcase` and `downcase` methods present
20
+ in Ruby by default. These gems are not installed automatically; install one
21
+ manually if you want enhanced Unicode support.
22
+
17
23
 
18
24
  Quickstart
19
25
  ----------
20
26
 
21
27
  $ [sudo] gem install citeproc-ruby
28
+ $ [sudo] gem install unicode-utils # Ruby 1.9
29
+ $ [sudo] gem install unicode # Ruby 1.8
22
30
  $ irb
23
31
  >> require 'citeproc'
24
32
  >> book = {
data/lib/citeproc.rb CHANGED
@@ -1,17 +1,14 @@
1
1
  $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
+ $KCODE = 'UTF-8' if RUBY_VERSION < '1.9.0' && $KCODE.nil?
5
+
4
6
  require 'open-uri'
5
7
 
6
8
  require 'logging'
7
9
  require 'nokogiri'
8
10
  require 'json'
9
11
 
10
- #require 'activesupport'
11
-
12
- require 'unicode_utils/upcase'
13
- require 'unicode_utils/downcase'
14
-
15
12
  module CiteProc
16
13
 
17
14
  @log = Logging.logger[self.name]
@@ -39,6 +36,7 @@ end
39
36
  require 'extensions/core'
40
37
  require 'support/attributes'
41
38
  require 'support/tree'
39
+ require 'support/compatibility'
42
40
 
43
41
  require 'csl/node'
44
42
  require 'csl/term'
@@ -1,3 +1,3 @@
1
1
  module CiteProc
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.4'.freeze
3
3
  end
data/lib/csl/nodes.rb CHANGED
@@ -368,7 +368,8 @@ module CSL
368
368
  def format_page_range(value, format)
369
369
  return value unless value.match(/([a-z]*)(\d+)\s*\D\s*([a-z]*)(\d+)/i)
370
370
 
371
- tokens = [$1, $2, "\u2013", $3, $4]
371
+ tokens = [$1, $2, "\xe2\x80\x93", $3, $4]
372
+ tokens[2].force_encoding("UTF-8") if RUBY_VERSION >= '1.9.0'
372
373
 
373
374
  # normalize page range to expanded form
374
375
  f, t = tokens[1].chars.to_a, tokens[4].chars.to_a
@@ -620,7 +621,10 @@ module CSL
620
621
  protected
621
622
 
622
623
  def set_defaults
623
- self['range-delimiter'] ||= "\u2013"
624
+ unless self['range-delimiter']
625
+ self['range-delimiter'] = "\xe2\x80\x93"
626
+ self['range-delimiter'].force_encoding("UTF-8") if RUBY_VERSION >= '1.9.0'
627
+ end
624
628
  end
625
629
  end
626
630
 
data/lib/csl/sort.rb CHANGED
@@ -11,7 +11,15 @@ module CSL
11
11
  keys.each do |key|
12
12
  this, that = key.convert(a, processor), key.convert(b, processor)
13
13
 
14
- comparison = this <=> that
14
+ # Duplicate Ruby 1.9's <=> behavior for nil
15
+ if this.nil? && that.nil?
16
+ comparison = 0
17
+ elsif this.nil? || that.nil?
18
+ comparison = nil
19
+ else
20
+ comparison = this <=> that
21
+ end
22
+
15
23
  comparison = comparison * -1 if comparison && key.descending?
16
24
 
17
25
  comparison = comparison ? comparison : that.nil? ? -1 : 1
@@ -102,14 +102,14 @@ module CiteProc
102
102
 
103
103
  case text_case
104
104
  when 'lowercase'
105
- @tokens.each { |token| token.content = UnicodeUtils ? UnicodeUtils.downcase(token.content) : token.content.downcase }
105
+ @tokens.each { |token| token.content = Support.downcase(token.content) }
106
106
 
107
107
  when 'uppercase'
108
- @tokens.each { |token| token.content = UnicodeUtils ? UnicodeUtils.upcase(token.content) : token.content.upcase }
108
+ @tokens.each { |token| token.content = Support.upcase(token.content) }
109
109
 
110
110
  when 'capitalize-first'
111
111
  token = @tokens.detect { |token| !token.annotations.include?('nocase') }
112
- token.content.sub!(/^./) { UnicodeUtils ? UnicodeUtils.upcase($&) : $&.upcase }
112
+ token.content.sub!(/^./) { Support.upcase($&) }
113
113
 
114
114
  when 'capitalize-all'
115
115
  # @tokens.each { |token| token.content.gsub!(/\b\w/) { $&.upcase } unless token.annotations.include?('nocase') }
@@ -117,7 +117,7 @@ module CiteProc
117
117
 
118
118
  # TODO exact specification?
119
119
  when 'title'
120
- @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') }
120
+ @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') }
121
121
 
122
122
  # TODO exact specification?
123
123
  when 'sentence'
@@ -0,0 +1,83 @@
1
+
2
+ # Remove the 'id' and 'type' methods in Ruby 1.8, as they're used all over
3
+ # the source
4
+ if RUBY_VERSION < "1.9.0"
5
+ class Object
6
+ undef_method :id
7
+ undef_method :type
8
+ end
9
+ end
10
+
11
+ # Robust solutions for Unicode
12
+ if RUBY_PLATFORM == 'java'
13
+ require 'java'
14
+
15
+ module Support
16
+ def self.upcase(string)
17
+ java.lang.String.new(string).to_upper_case(java.util.Locale::ENGLISH).to_s
18
+ end
19
+
20
+ def self.downcase(string)
21
+ java.lang.String.new(string).to_lower_case(java.util.Locale::ENGLISH).to_s
22
+ end
23
+ end
24
+
25
+ else
26
+
27
+ begin
28
+ require 'unicode'
29
+
30
+ module Support
31
+ def self.upcase(string)
32
+ Unicode.upcase(string)
33
+ end
34
+
35
+ def self.downcase(string)
36
+ Unicode.downcase(string)
37
+ end
38
+ end
39
+
40
+ rescue LoadError
41
+ begin
42
+ require 'unicode_utils'
43
+
44
+ module Support
45
+ def self.upcase(string)
46
+ UnicodeUtils.upcase(string)
47
+ end
48
+
49
+ def self.downcase(string)
50
+ UnicodeUtils.downcase(string)
51
+ end
52
+ end
53
+
54
+ rescue LoadError
55
+ begin
56
+ require 'active_support/multibyte/chars'
57
+
58
+ module Support
59
+ def self.upcase(string)
60
+ ActiveSupport::Multibyte::Chars.new(string).upcase.to_s
61
+ end
62
+
63
+ def self.downcase(string)
64
+ ActiveSupport::Multibyte::Chars.new(string).downcase.to_s
65
+ end
66
+ end
67
+
68
+ rescue LoadError
69
+
70
+ module Support
71
+ def self.upcase(string)
72
+ string.upcase
73
+ end
74
+
75
+ def self.downcase(string)
76
+ string.downcase
77
+ end
78
+ end
79
+
80
+ end
81
+ end
82
+ end
83
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: citeproc-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-07 00:00:00.000000000Z
12
+ date: 2012-02-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: logging
16
- requirement: &2156697820 !ruby/object:Gem::Requirement
16
+ requirement: &2152765020 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156697820
24
+ version_requirements: *2152765020
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &2156696820 !ruby/object:Gem::Requirement
27
+ requirement: &2152764360 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,21 +32,10 @@ dependencies:
32
32
  version: '1.4'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156696820
36
- - !ruby/object:Gem::Dependency
37
- name: unicode_utils
38
- requirement: &2156695620 !ruby/object:Gem::Requirement
39
- none: false
40
- requirements:
41
- - - ~>
42
- - !ruby/object:Gem::Version
43
- version: '1.0'
44
- type: :runtime
45
- prerelease: false
46
- version_requirements: *2156695620
35
+ version_requirements: *2152764360
47
36
  - !ruby/object:Gem::Dependency
48
37
  name: bundler
49
- requirement: &2156694820 !ruby/object:Gem::Requirement
38
+ requirement: &2152763640 !ruby/object:Gem::Requirement
50
39
  none: false
51
40
  requirements:
52
41
  - - ~>
@@ -54,10 +43,10 @@ dependencies:
54
43
  version: '1.0'
55
44
  type: :development
56
45
  prerelease: false
57
- version_requirements: *2156694820
46
+ version_requirements: *2152763640
58
47
  - !ruby/object:Gem::Dependency
59
48
  name: rdoc
60
- requirement: &2156693940 !ruby/object:Gem::Requirement
49
+ requirement: &2152762940 !ruby/object:Gem::Requirement
61
50
  none: false
62
51
  requirements:
63
52
  - - ~>
@@ -65,10 +54,10 @@ dependencies:
65
54
  version: '2.5'
66
55
  type: :development
67
56
  prerelease: false
68
- version_requirements: *2156693940
57
+ version_requirements: *2152762940
69
58
  - !ruby/object:Gem::Dependency
70
59
  name: rake
71
- requirement: &2156693120 !ruby/object:Gem::Requirement
60
+ requirement: &2152762240 !ruby/object:Gem::Requirement
72
61
  none: false
73
62
  requirements:
74
63
  - - ! '>='
@@ -76,10 +65,10 @@ dependencies:
76
65
  version: 0.8.0
77
66
  type: :development
78
67
  prerelease: false
79
- version_requirements: *2156693120
68
+ version_requirements: *2152762240
80
69
  - !ruby/object:Gem::Dependency
81
70
  name: rspec
82
- requirement: &2156692500 !ruby/object:Gem::Requirement
71
+ requirement: &2152761540 !ruby/object:Gem::Requirement
83
72
  none: false
84
73
  requirements:
85
74
  - - ~>
@@ -87,10 +76,10 @@ dependencies:
87
76
  version: '2.5'
88
77
  type: :development
89
78
  prerelease: false
90
- version_requirements: *2156692500
79
+ version_requirements: *2152761540
91
80
  - !ruby/object:Gem::Dependency
92
81
  name: cucumber
93
- requirement: &2156691860 !ruby/object:Gem::Requirement
82
+ requirement: &2152761000 !ruby/object:Gem::Requirement
94
83
  none: false
95
84
  requirements:
96
85
  - - ~>
@@ -98,7 +87,7 @@ dependencies:
98
87
  version: '0.3'
99
88
  type: :development
100
89
  prerelease: false
101
- version_requirements: *2156691860
90
+ version_requirements: *2152761000
102
91
  description: A CSL (Citation Style Language) Processor
103
92
  email:
104
93
  - http://sylvester.keil.or.at
@@ -130,6 +119,7 @@ files:
130
119
  - lib/plugins/formats/default.rb
131
120
  - lib/plugins/formats/html.rb
132
121
  - lib/support/attributes.rb
122
+ - lib/support/compatibility.rb
133
123
  - lib/support/tree.rb
134
124
  - resource/locale/locales-af-ZA.xml
135
125
  - resource/locale/locales-ar-AR.xml