csl 1.0.2 → 1.1.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: b4f4e2dd15fcca560abf0a5d5527097bf02d95ba
4
- data.tar.gz: f8aa36164f892d1b45c86dc23d4f360d0c3c03c0
3
+ metadata.gz: 817790ad5486590a4f7f83ba761a6c80dd86c4e8
4
+ data.tar.gz: d2bbaa7cc6980ca486425e635378a4f7c5323ce3
5
5
  SHA512:
6
- metadata.gz: aad6d6d7102be615407a550b3cfbb7aeca23a5c3aff00b2d896b512f66325ee9fcb5fd61482976b63b91adc07eb03317648d609812f15df9fa244b17f4492200
7
- data.tar.gz: 691ec4b1b95f4d01e8cfa41f7ec60e49986eac63436313d6cea1122e0c46bb9f839fefc147d06aab21c4e83e7f1ce5da0e1c48b222a9205c51f9796869afbd9e
6
+ metadata.gz: 175868d94c06e78355ca2f511f0ce9c256d301f3e88dc83aa316cb6ace02c73a31b285b1b095e1d7639bfa2b32e958210723523e6ad11cba956c003f7a29b378
7
+ data.tar.gz: ba50730dee3d8c1735a79597ed5caae09d02162fdbbe4adcb4ec51e6af5d6f35db96b2a74043f304f70b8aa87c3111c0b225821e170628270098f9b9451b3925
@@ -0,0 +1 @@
1
+ service_name: travis-ci
data/.gitignore CHANGED
@@ -10,3 +10,4 @@ Gemfile.lock
10
10
  *.gem
11
11
  .ruby-version
12
12
  .rvm
13
+ .bundle
data/.simplecov CHANGED
@@ -1,2 +1,4 @@
1
1
  SimpleCov.start do
2
- end
2
+ add_filter 'spec/'
3
+ add_filter 'features/'
4
+ end
@@ -1,22 +1,16 @@
1
1
  language: ruby
2
2
  bundler_args: --without debug extra
3
+ script: bundle exec rake test_with_coveralls
3
4
  rvm:
5
+ - 2.1.0
4
6
  - 2.0.0
5
- - 1.9.2
6
7
  - 1.9.3
7
- - jruby-18mode
8
8
  - jruby-19mode
9
- - rbx-18mode
10
- - rbx-19mode
11
- - 1.8.7
12
- - ree
9
+ - jruby-head
10
+ - rbx
13
11
  notifications:
14
12
  email:
15
13
  recipients:
16
14
  - sylvester@keil.or.at
17
15
  on_success: change
18
16
  on_failure: always
19
- matrix:
20
- allow_failures:
21
- - rvm: jruby-19mode
22
- - rvm: rbx-19mode
data/AGPL CHANGED
@@ -631,7 +631,7 @@ the "copyright" line and a pointer to where the full notice is found.
631
631
 
632
632
  CSL-Ruby. A Ruby CSL parser and library.
633
633
  Copyright 2012 President and Fellows of Harvard College.
634
- Copyright 2009-2013 Sylvester Keil. All rights reserved.
634
+ Copyright 2009-2014 Sylvester Keil. All rights reserved.
635
635
 
636
636
  This program is free software: you can redistribute it and/or modify
637
637
  it under the terms of the GNU Affero General Public License as published by
data/BSDL CHANGED
@@ -1,7 +1,7 @@
1
1
  CSL-Ruby. A Ruby CSL parser and library.
2
2
 
3
3
  Copyright 2012 President and Fellows of Harvard College.
4
- Copyright 2009-2013 Sylvester Keil. All rights reserved.
4
+ Copyright 2009-2014 Sylvester Keil. All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
7
7
  modification, are permitted provided that the following conditions are met:
@@ -26,4 +26,4 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
26
 
27
27
  The views and conclusions contained in the software and documentation are
28
28
  those of the authors and should not be interpreted as representing official
29
- policies, either expressed or implied, of the copyright holder.
29
+ policies, either expressed or implied, of the copyright holder.
data/Gemfile CHANGED
@@ -5,28 +5,38 @@ group :development, :test do
5
5
  gem 'rake', '~>10.0'
6
6
  gem 'rspec', '~>2.13'
7
7
  gem 'cucumber', '~>1.2'
8
+ gem 'simplecov', '~>0.8', :require => false
9
+ gem 'rubinius-coverage', :platform => :rbx
10
+ gem 'coveralls', :require => false
8
11
  end
9
12
 
10
13
  group :debug do
11
- gem 'ruby-debug', :platforms => [:mri_18, :jruby]
12
- gem 'debugger', :platforms => [:mri_19]
13
- gem 'debugger2', :platforms => [:mri_20]
14
+ gem 'ruby-debug', :require => false, :platforms => [:jruby]
15
+ gem 'debugger', :require => false, :platforms => [:mri]
16
+ gem 'rubinius-debugger', :require => false, :platforms => :rbx
17
+ gem 'rubinius-compiler', :require => false, :platforms => :rbx
14
18
  end
15
19
 
16
20
  group :optional do
17
- gem 'nokogiri', '~>1.5'
21
+ gem 'nokogiri', '~> 1.6'
18
22
  end
19
23
 
20
24
  group :extra do
21
- gem 'simplecov', '~>0.6'
25
+ gem 'guard', '~>2.2'
26
+ gem 'guard-rspec'
27
+ gem 'guard-cucumber'
28
+ gem 'rb-fsevent', '~>0.9', :platforms => [:ruby]
22
29
 
23
- gem 'guard', '~>1.2'
24
- gem 'guard-rspec', '~>1.1'
25
- gem 'guard-cucumber', '~>1.2'
26
- gem 'rb-fsevent', '~>0.9.1', :platforms => [:mri_19, :mri_20, :rbx]
30
+ gem 'yard', '~>0.8', :platforms => [:mri]
31
+ gem 'redcarpet', '~>3.0', :platforms => [:mri]
32
+ end
27
33
 
28
- gem 'yard', '~>0.8', :platforms => [:mri_19, :mri_20]
29
- gem 'redcarpet', '~>2.1', :platforms => [:mri_19, :mri_20]
34
+ group :rbx do
35
+ platform :rbx do
36
+ gem 'rubysl', '~>2.0'
37
+ gem 'json', '~>1.8'
38
+ gem 'racc'
39
+ end
30
40
  end
31
41
 
32
- # vim: syntax=ruby
42
+ # vim: syntax=ruby
data/README.md CHANGED
@@ -4,7 +4,9 @@ CSL-Ruby provides a Ruby parser and a comprehensive API for the
4
4
  [Citation Style Language](http://citationstyles.org) (CSL), an XML-based
5
5
  format to describe the formatting of citations, notes and bibliographies.
6
6
 
7
- [![Build Status](https://secure.travis-ci.org/inukshuk/csl-ruby.png?branch=master)](http://travis-ci.org/inukshuk/csl-ruby)
7
+ [![Build Status](https://secure.travis-ci.org/inukshuk/csl-ruby.png)](http://travis-ci.org/inukshuk/csl-ruby)
8
+ [![Coverage Status](https://coveralls.io/repos/inukshuk/csl-ruby/badge.png?branch=master)](https://coveralls.io/r/inukshuk/csl-ruby?branch=master)
9
+ [![Dependency Status](https://gemnasium.com/inukshuk/csl-ruby.png)](https://gemnasium.com/inukshuk/csl-ruby)
8
10
 
9
11
  Styles and Locales
10
12
  ------------------
@@ -31,7 +33,7 @@ manipulate, query or otherwise work with them using a dedicated API: that is
31
33
  to say, you do not have to resort to XML-related methods of access, but can
32
34
  make use of a large set of library methods which are specific to CSL. This
33
35
  is useful, primarily, for citation processors like
34
- [CiteProc-Ruby](https://github.com/inukshuk/citeproc-ruby).
36
+ [CiteProc-Ruby](https://github.com/inukshuk/citeproc).
35
37
 
36
38
  On the other hand, CSL-Ruby makes it easy to create new styles and locales
37
39
  using Ruby; this is useful, for example, if you need to change or adapt
@@ -56,9 +58,9 @@ available features, please consult the
56
58
 
57
59
  # Load another style
58
60
  amc = CSL::Style.load 'http://zotero.org/styles/applied-mathematics-and-computation'
59
-
61
+
60
62
  amc.independent? #-> false
61
-
63
+
62
64
  # Load the independent parent style
63
65
  parent = amc.independent_parent
64
66
  parent.title #-> "Elsevier (numeric, with titles)"
@@ -73,31 +75,31 @@ available features, please consult the
73
75
  # Fetch the a macro
74
76
  authors = apa.macros['authors'].children[0]
75
77
  #-> #<CSL::Style::Names variable="author" children=[2]>
76
-
78
+
77
79
  # Load a locally installed locale
78
80
  fr = CSL::Locale.load :fr
79
-
81
+
80
82
  # Translate a term
81
83
  fr.translate 'editor' #-> "éditeur"
82
84
  fr.translate 'editor', plural: true #-> "éditeurs"
83
85
  fr.translate 'editor', form: 'short' #-> "éd."
84
-
86
+
85
87
  # Ordinalize a number
86
88
  fr.ordinalize 42 #=> "42ᵉ"
87
89
  fr.ordinalize 3, form: 'long' => "troisième"
88
90
 
89
91
  # Create a new style
90
92
  style = CSL::Style.new
91
-
93
+
92
94
  style.id = 'http://www.zotero.org/styles/my-style'
93
95
  style.title = 'My Style'
94
96
 
95
97
  # Add the default license for CSL styles
96
98
  style.default_license!
97
-
99
+
98
100
  # Access the style as XML
99
101
  style.to_xml
100
-
102
+
101
103
  # Access the style as XML (pretty printed)
102
104
  style.to_s
103
105
 
@@ -127,10 +129,17 @@ If you've found a bug or have a question, please open an issue on the
127
129
  Or, for extra credit, clone the CSL-Ruby repository, write a failing
128
130
  example, fix the bug and submit a pull request.
129
131
 
132
+ Credits
133
+ -------
134
+ Thanks to Rintze M. Zelle, Sebastian Karcher, Frank G. Bennett, Jr.,
135
+ and Bruce D'Arcus of CSL and citeproc-js fame for their support!
136
+
137
+ Thanks to Google and the Berkman Center at Harvard University for supporting
138
+ this project as part of [Google Summer of Code](https://developers.google.com/open-source/soc/).
130
139
 
131
140
  Copyright
132
141
  ---------
133
- Copyright 2009-2013 Sylvester Keil. All rights reserved.
142
+ Copyright 2009-2014 Sylvester Keil. All rights reserved.
134
143
 
135
144
  Copyright 2012 President and Fellows of Harvard College.
136
145
 
data/Rakefile CHANGED
@@ -18,8 +18,9 @@ task :console, [:script] do |t,args|
18
18
  ARGV.clear
19
19
 
20
20
  require 'irb'
21
+ require 'irb/completion'
21
22
  require 'csl'
22
-
23
+
23
24
  IRB.conf[:SCRIPT] = args.script
24
25
  IRB.start
25
26
  end
@@ -35,6 +36,10 @@ Cucumber::Rake::Task.new(:cucumber) do |t|
35
36
  t.profile = 'default'
36
37
  end
37
38
 
39
+ require 'coveralls/rake/task'
40
+ Coveralls::RakeTask.new
41
+ task :test_with_coveralls => [:spec, :cucumber, 'coveralls:push']
42
+
38
43
  task :release do |t|
39
44
  system "gem build csl.gemspec"
40
45
  system "git tag #{CSL::VERSION}"
@@ -22,6 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.license = 'AGPL'
23
23
  s.date = Time.now.strftime('%Y-%m-%d')
24
24
 
25
+ s.required_ruby_version = '>= 1.9.3'
26
+
25
27
  s.add_dependency('namae', ['~>0.7'])
26
28
 
27
29
  s.files = `git ls-files`.split("\n")
@@ -29,7 +31,7 @@ Gem::Specification.new do |s|
29
31
  s.executables = []
30
32
  s.require_path = 'lib'
31
33
 
32
- s.has_rdoc = 'yard'
34
+ s.has_rdoc = 'yard'
33
35
  end
34
36
 
35
- # vim: syntax=ruby
37
+ # vim: syntax=ruby
@@ -0,0 +1,16 @@
1
+ Feature: Parse CSL choose nodes
2
+ As a hacker of CSL styles
3
+ I want to be able to parse CSL choose nodes
4
+
5
+ Scenario: Single if nodes
6
+ When I parse the CSL string
7
+ """
8
+ <choose>
9
+ <if type="bill legal_case legislation" match="none"></if>
10
+ </choose>
11
+ """
12
+ Then the nodename should be "choose"
13
+ And the node should have 1 blocks
14
+ And the block number 1's nodename should be "if"
15
+ And the block number 1's class should be "CSL::Style::Choose::Block"
16
+
@@ -28,3 +28,13 @@ end
28
28
  Then /^the (\w+) number (\d+) should( not)? be a (\w+)$/ do |name, offset, negate, predicate|
29
29
  @csl.send("#{name}s")[offset.to_i - 1].send("#{predicate}?").should == negate.nil?
30
30
  end
31
+
32
+ Then /^the (\w+) number (\d+)'s (\w+) should( not)? be "([^"]*)"$/ do |name, offset, method, negate, expected|
33
+ actual = @csl.send("#{name}s")[offset.to_i - 1].send(method).to_s
34
+
35
+ if negate.nil?
36
+ actual.should == expected
37
+ else
38
+ actual.should_not == expected
39
+ end
40
+ end
@@ -1,8 +1,22 @@
1
1
  begin
2
2
  require 'simplecov'
3
- require 'debugger'
3
+ require 'coveralls' if ENV['CI']
4
4
  rescue LoadError
5
5
  # ignore
6
6
  end
7
7
 
8
- require 'csl'
8
+ begin
9
+ case
10
+ when RUBY_PLATFORM < 'java'
11
+ require 'debug'
12
+ Debugger.start
13
+ when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
14
+ require 'rubinius/debugger'
15
+ else
16
+ require 'debugger'
17
+ end
18
+ rescue LoadError
19
+ # ignore
20
+ end
21
+
22
+ require 'csl'
data/lib/csl.rb CHANGED
@@ -30,9 +30,12 @@ require 'csl/locale/date'
30
30
  require 'csl/locale/term'
31
31
  require 'csl/locale/style_options'
32
32
 
33
+ require 'csl/name_options'
34
+
33
35
  require 'csl/style'
34
36
  require 'csl/style/bibliography'
35
37
  require 'csl/style/citation'
38
+ require 'csl/style/sort'
36
39
  require 'csl/style/choose'
37
40
  require 'csl/style/date'
38
41
  require 'csl/style/group'
@@ -44,9 +47,9 @@ require 'csl/style/number'
44
47
  require 'csl/style/text'
45
48
 
46
49
  module CSL
47
-
50
+
48
51
  module_function
49
-
52
+
50
53
  def parse(*arguments)
51
54
  Parser.instance.parse(*arguments)
52
55
  end
@@ -54,7 +57,7 @@ module CSL
54
57
  def parse!(*arguments)
55
58
  Parser.instance.parse!(*arguments)
56
59
  end
57
-
60
+
58
61
  def validate(node)
59
62
  Schema.validate(node)
60
63
  end
@@ -63,4 +66,4 @@ module CSL
63
66
  Schema.valid?(node)
64
67
  end
65
68
 
66
- end
69
+ end
@@ -1,19 +1,13 @@
1
+ module CSL
2
+ module_function
1
3
 
2
- class Symbol
3
- include Comparable
4
-
5
- def <=>(other)
6
- return unless other.kind_of?(Symbol)
7
- to_s <=> other.to_s
8
- end
9
-
10
- def match(pattern)
11
- to_s.match(pattern)
4
+ def silence_warnings
5
+ original_verbosity, $VERBOSE = $VERBOSE, nil
6
+ yield
7
+ ensure
8
+ $VERBOSE = original_verbosity
12
9
  end
13
-
14
- alias =~ match
15
-
16
- end unless Symbol.is_a?(Comparable)
10
+ end
17
11
 
18
12
  class Module
19
13
  if RUBY_VERSION < '1.9'
@@ -51,11 +45,11 @@ module CSL
51
45
  end
52
46
  else
53
47
  def encode_xml_text(string)
54
- string.encode(:xml => :text)
48
+ string.encode(string.encoding, :xml => :text)
55
49
  end
56
50
 
57
51
  def encode_xml_attr(string)
58
- string.encode(:xml => :attr)
52
+ string.encode(string.encoding, :xml => :attr)
59
53
  end
60
54
  end
61
55
  end
@@ -86,8 +86,9 @@ module CSL
86
86
  end
87
87
 
88
88
  # Ruby 1.8 still has Object#id methods so the attr_children generator
89
- # has not created those; since #id is deprecated in 1.8.7 we're
89
+ # may not have created those; since #id is deprecated in 1.8.7 we're
90
90
  # forcing the override anyway. Live dangerously!
91
+ remove_method :id
91
92
 
92
93
  # @return [Id] the id text node
93
94
  def id
@@ -280,4 +281,4 @@ module CSL
280
281
  end
281
282
 
282
283
 
283
- end
284
+ end
@@ -20,10 +20,9 @@ module CSL
20
20
  # Default languages/regions.
21
21
  # Auto-detection is based on these lists.
22
22
  @regions = Hash[*%w{
23
- af ZA ar AR bg BG ca AD cs CZ da DK de DE el GR en US es ES et EE fa IR
24
- fr FR he IL hu HU is IS it IT ja JP km KH ko KR mn MN nb NO nl NL nn NO
25
- pl PL pt PT ro RO ru RU sk SK sl SI sr RS sv SE th TH tr TR uk UA vi VN
26
- zh CN
23
+ af ZA bg BG ca AD cs CZ da DK de DE el GR en US es ES et EE fa IR fr FR
24
+ he IL hu HU is IS it IT ja JP km KH ko KR mn MN nb NO nl NL nn NO pl PL
25
+ pt PT ro RO ru RU sk SK sl SI sr RS sv SE th TH tr TR uk UA vi VN zh CN
27
26
  }.map(&:to_sym)].freeze
28
27
 
29
28
  @languages = @regions.invert.merge(Hash[*%w{
@@ -37,9 +36,10 @@ module CSL
37
36
  attr_accessor :default
38
37
  attr_reader :languages, :regions
39
38
 
40
- def load(input = Locale.default)
41
- input = normalize input if input.to_s =~ tag_pattern
42
- super
39
+ def load(input = nil)
40
+ input ||= Locale.default
41
+ input = normalize input if input.to_s =~ @tag_pattern
42
+ super(input)
43
43
  end
44
44
 
45
45
  # Normalizes an IETF tag; adds a language's default region or a
@@ -57,7 +57,7 @@ module CSL
57
57
  tag = tag.to_s.strip
58
58
 
59
59
  raise ArgumentError, "not a valid IETF tag: #{tag.inspect}" unless
60
- tag =~ tag_pattern
60
+ tag =~ @tag_pattern
61
61
 
62
62
  language, region = tag.split(/-/)
63
63
 
@@ -66,10 +66,6 @@ module CSL
66
66
 
67
67
  tag
68
68
  end
69
-
70
- private
71
-
72
- attr_reader :tag_pattern
73
69
  end
74
70
 
75
71
  attr_defaults :version => Schema.major_version,
@@ -134,11 +130,6 @@ module CSL
134
130
  yield self if block_given?
135
131
  end
136
132
 
137
- def initialize_copy(other)
138
- super
139
- @language, @region = other.language, other.region
140
- end
141
-
142
133
 
143
134
  def added_to(node)
144
135
  raise ValidationError, "not allowed to add locale to #{node.nodename}" unless
@@ -200,11 +191,25 @@ module CSL
200
191
 
201
192
  # @return [String, nil] the term's translation
202
193
  def translate(name, options = {})
194
+ return unless has_terms?
195
+
203
196
  term = terms.lookup name, options
204
197
  term && term.to_s(options)
205
198
  end
206
199
  alias t translate
207
200
 
201
+ # Stores a translation in the locale's term registry.
202
+ # @see Terms#store
203
+ def store(*arguments)
204
+ unless has_terms?
205
+ self << CSL::Locale::Terms.new
206
+ end
207
+
208
+ terms.store(*arguments)
209
+ self
210
+ end
211
+ alias learn store
212
+
208
213
  # Ordinalizes the passed-in number using either the ordinal or
209
214
  # long-ordinal forms defined by the locale. If a long-ordinal form is
210
215
  # requested but not available, the regular ordinal will be returned
@@ -250,6 +255,72 @@ module CSL
250
255
  [number, ordinal.to_s(options)].join
251
256
  end
252
257
 
258
+ # @return [Boolean] true when the option limit-day-ordinals-to-day-1 is true
259
+ def limit_day_ordinals?
260
+ return false unless has_options? && options.attribute?(:'limit-day-ordinals-to-day-1')
261
+ !!(options[:'limit-day-ordinals-to-day-1'].to_s =~ /^true$/i)
262
+ end
263
+
264
+ def limit_day_ordinals!
265
+ unless has_options?
266
+ children[:'style-options'] = StyleOptions.new
267
+ end
268
+
269
+ options[:'limit-day-ordinals-to-day-1'] = true
270
+ end
271
+
272
+ # @return [Boolean] true when the option punctuation-in-quote is true
273
+ def punctuation_in_quote?
274
+ return false unless has_options? && options.attribute?(:'punctuation-in-quote')
275
+ !!(options[:'punctuation-in-quote'].to_s =~ /^true$/i)
276
+ end
277
+ alias punctuation_in_quotes? punctuation_in_quote?
278
+
279
+ def punctuation_in_quote!
280
+ unless has_options?
281
+ children[:'style-options'] = StyleOptions.new
282
+ end
283
+
284
+ options[:'punctuation-in-quote'] = true
285
+ end
286
+ alias punctuation_in_quotes! punctuation_in_quote!
287
+
288
+ # Puts localized quotes around the passed-in string.
289
+ # @return [String] the quoted string
290
+ def quote(string, escape = false)
291
+ oq, cq = t('open-quote'), t('close-quote')
292
+
293
+ return string if oq.nil? || cq.nil? || (oq.empty? && cq.empty?)
294
+
295
+ if escape
296
+ oq = CSL.encode_xml_text(oq)
297
+ cq = CSL.encode_xml_text(cq)
298
+ end
299
+
300
+ string = replace_with_inner_quotes(string, oq, cq, escape)
301
+
302
+ if punctuation_in_quotes?
303
+ "#{oq}#{string}#{cq}"
304
+ else
305
+ string, punctuation = string.split(/([\.,])$/, 2)
306
+
307
+ "#{oq}#{string}#{cq}#{punctuation}"
308
+ end
309
+ end
310
+
311
+ def replace_with_inner_quotes(string, open, close, escape = false)
312
+ oq, cq = t('open-inner-quote'), t('close-inner-quote')
313
+
314
+ return string if oq.nil? || cq.nil? || (oq.empty? && cq.empty?)
315
+
316
+ if escape
317
+ oq = CSL.encode_xml_text(oq)
318
+ cq = CSL.encode_xml_text(cq)
319
+ end
320
+
321
+ string.gsub(/(#{open}|"\b)/, oq).gsub(/(#{close}|\b")/, cq)
322
+ end
323
+
253
324
  # @example
254
325
  # locale.each_term { |term| block } #-> locale
255
326
  # locale.each_term #-> enumerator
@@ -364,9 +435,11 @@ module CSL
364
435
 
365
436
  private
366
437
 
438
+ alias original_locale_attribute_assignments attribute_assignments
439
+
367
440
  def attribute_assignments
368
441
  if root?
369
- super.push('xml:lang="%s"' % to_s)
442
+ original_locale_attribute_assignments
370
443
  else
371
444
  'xml:lang="%s"' % to_s
372
445
  end
@@ -410,4 +483,4 @@ module CSL
410
483
  end
411
484
  end
412
485
 
413
- end
486
+ end