csl 1.1.0 → 1.2.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: 817790ad5486590a4f7f83ba761a6c80dd86c4e8
4
- data.tar.gz: d2bbaa7cc6980ca486425e635378a4f7c5323ce3
3
+ metadata.gz: d1cbdc6b606bf9f4652ad841cafd83edfc774fd2
4
+ data.tar.gz: 7f55aee76c232b8f3760ffa99a47e6f2ef7c7712
5
5
  SHA512:
6
- metadata.gz: 175868d94c06e78355ca2f511f0ce9c256d301f3e88dc83aa316cb6ace02c73a31b285b1b095e1d7639bfa2b32e958210723523e6ad11cba956c003f7a29b378
7
- data.tar.gz: ba50730dee3d8c1735a79597ed5caae09d02162fdbbe4adcb4ec51e6af5d6f35db96b2a74043f304f70b8aa87c3111c0b225821e170628270098f9b9451b3925
6
+ metadata.gz: e5c6c2daa0db1832bfcd0c6d63bf61fe7602818dfb233b4e6d05394695412b760bfbf09b312699f48f33e78e3685ccacd429c2e61d1acac1644b1e40df650ae5
7
+ data.tar.gz: 4b33db0d2bf6d84e0ee85d4327d227f19ee9e958d63c0c016a2a40db92392aa9e6b860b0a283336bfccba42390605acbcf381f08e20ffbeac376d3d17e7b6fb7
data/Gemfile CHANGED
@@ -24,6 +24,9 @@ end
24
24
  group :extra do
25
25
  gem 'guard', '~>2.2'
26
26
  gem 'guard-rspec'
27
+ gem 'bond'
28
+ gem 'diff-lcs'
29
+ gem 'pry'
27
30
  gem 'guard-cucumber'
28
31
  gem 'rb-fsevent', '~>0.9', :platforms => [:ruby]
29
32
 
data/Rakefile CHANGED
@@ -13,16 +13,14 @@ $:.unshift(File.join(File.dirname(__FILE__), './lib'))
13
13
  require 'csl/version'
14
14
 
15
15
 
16
- desc 'Run an IRB session with CSL loaded'
17
- task :console, [:script] do |t,args|
16
+ desc 'Run a Pry session with CSL loaded'
17
+ task :console do
18
18
  ARGV.clear
19
19
 
20
- require 'irb'
21
- require 'irb/completion'
20
+ require 'pry'
22
21
  require 'csl'
23
22
 
24
- IRB.conf[:SCRIPT] = args.script
25
- IRB.start
23
+ Pry.start
26
24
  end
27
25
 
28
26
  require 'rspec/core'
@@ -49,6 +47,16 @@ end
49
47
 
50
48
  task :default => [:spec, :cucumber]
51
49
 
50
+ task :check_warnings do
51
+ $VERBOSE = true
52
+ require 'csl'
53
+
54
+ CSL::Style.new
55
+ CSL::Locale.new
56
+
57
+ puts CSL::VERSION
58
+ end
59
+
52
60
  begin
53
61
  require 'yard'
54
62
  YARD::Rake::YardocTask.new
@@ -14,7 +14,7 @@ module CSL
14
14
  options
15
15
  end
16
16
  end
17
-
17
+
18
18
  def symbolize_keys!
19
19
  replace(symbolize_keys)
20
20
  end
@@ -54,10 +54,6 @@ class Hash
54
54
  include CSL::Extensions::StringifyKeys unless method_defined?(:stringify_keys)
55
55
  end
56
56
 
57
- class Module
58
- include CSL::Extensions::Nesting
59
- end
60
-
61
57
  class Object
62
58
  include CSL::Extensions::Blank unless method_defined?(:blank?)
63
59
  end
@@ -22,7 +22,7 @@ module CSL
22
22
  # Typically, this will return a new instance of the class.
23
23
  #
24
24
  # @note
25
- # The base class is exepcted to define a #parse method.
25
+ # The base class is expected to define a #parse method.
26
26
  #
27
27
  # @raise ParseError
28
28
  #
@@ -88,4 +88,4 @@ module CSL
88
88
  end
89
89
  end
90
90
 
91
- end
91
+ end
@@ -130,6 +130,10 @@ module CSL
130
130
  yield self if block_given?
131
131
  end
132
132
 
133
+ def initialize_copy(other)
134
+ @parent, @ancestors, @descendants, @siblings, @root, @depth = nil
135
+ initialize(other.attributes.to_hash.merge(:lang => other.to_s))
136
+ end
133
137
 
134
138
  def added_to(node)
135
139
  raise ValidationError, "not allowed to add locale to #{node.nodename}" unless
@@ -33,7 +33,7 @@ module CSL
33
33
 
34
34
  style ||= root
35
35
 
36
- if !root? && style.respond_to?(inheritable_options)
36
+ if !style.equal?(self) && style.respond_to?(inheritable_options)
37
37
  options = style.send(inheritable_options).merge(options)
38
38
  end
39
39
 
@@ -3,6 +3,7 @@ module CSL
3
3
  class Node
4
4
 
5
5
  extend Forwardable
6
+ extend Extensions::Nesting
6
7
 
7
8
  include Enumerable
8
9
  include Comparable
@@ -233,7 +234,7 @@ module CSL
233
234
  end
234
235
 
235
236
  def initialize_copy(other)
236
- super
237
+ @parent, @ancestors, @descendants, @siblings, @root, @depth = nil
237
238
  initialize(other.attributes)
238
239
  end
239
240
 
@@ -431,7 +432,7 @@ module CSL
431
432
  }.compact]
432
433
  end
433
434
 
434
-
435
+
435
436
  # @return [Hash] the node's formatting options
436
437
  def formatting_options
437
438
  options = attributes_for Schema.attr(:formatting)
@@ -567,7 +568,7 @@ module CSL
567
568
 
568
569
  def initialize(argument = '')
569
570
  case
570
- when argument.is_a?(Hash)
571
+ when argument.respond_to?(:each_pair)
571
572
  super
572
573
  when argument.respond_to?(:to_s)
573
574
  super({})
@@ -578,6 +579,11 @@ module CSL
578
579
  end
579
580
  end
580
581
 
582
+ def initialize_copy(other)
583
+ super
584
+ @text = other.text
585
+ end
586
+
581
587
  def textnode?
582
588
  true
583
589
  end
@@ -22,7 +22,7 @@ module CSL
22
22
 
23
23
  def sort_keys
24
24
  return [] unless sort?
25
- children[:sort].descendants
25
+ children[:sort].sort_keys
26
26
  end
27
27
 
28
28
  def substitute_subsequent_authors?
@@ -10,6 +10,11 @@ module CSL
10
10
  attr_children :sort, :layout
11
11
 
12
12
  alias sort? has_sort?
13
+
14
+ def sort_keys
15
+ return [] unless sort?
16
+ children[:sort].sort_keys
17
+ end
13
18
  end
14
19
 
15
20
  end
@@ -12,15 +12,15 @@ module CSL
12
12
 
13
13
  inherits :names_options
14
14
 
15
- alias labels label
16
-
17
15
  def initialize(attributes = {})
18
16
  super(attributes)
19
- children[:label] = []
20
-
21
17
  yield self if block_given?
22
18
  end
23
19
 
20
+ def prefix_label?
21
+ has_label? && has_name? && children.index(label) < children.index(name)
22
+ end
23
+
24
24
  def delimiter(node = nil, style = nil)
25
25
  attributes.fetch(:delimiter) do
26
26
  inherited_names_options(node, style)[:delimiter] || ''
@@ -97,7 +97,7 @@ module CSL
97
97
  def truncate(names, subsequent = false)
98
98
  limit = truncate_at(subsequent)
99
99
 
100
- return names if limit.zero?
100
+ return [] if limit.zero?
101
101
  names.take limit
102
102
  end
103
103
 
@@ -3,21 +3,22 @@ module CSL
3
3
 
4
4
  class Sort < Node
5
5
 
6
- attr_children :key
7
-
8
- alias keys key
6
+ #attr_children :key
7
+ #alias_child :sort_keys, :key
9
8
 
10
9
  def initialize(attributes = {})
11
10
  super(attributes)
12
- children[:key] = []
13
-
14
11
  yield self if block_given?
15
12
  end
16
13
 
14
+ alias sort_keys children
15
+ alias sort_keys? has_children?
16
+ alias has_sort_keys? has_children?
17
+
17
18
  class Key < Node
18
19
 
19
20
  attr_struct :variable, :macro, :sort,
20
- :'names-use-min', :'names-use-first', :'names-use-last'
21
+ :'names-min', :'names-use-first', :'names-use-last'
21
22
 
22
23
  attr_defaults :sort => 'ascending'
23
24
 
@@ -26,8 +27,8 @@ module CSL
26
27
  def name_options
27
28
  options = {}
28
29
 
29
- options[:'et-al-use-min'] = options[:'et-al-subsequent-use-min'] =
30
- attributes[:'names-use-min'] if attribute? :'names-use-min'
30
+ options[:'et-al-min'] = options[:'et-al-subsequent-min'] =
31
+ attributes[:'names-min'] if attribute? :'names-min'
31
32
 
32
33
  options[:'et-al-use-first'] = options[:'et-al-subsequent-use-first'] =
33
34
  attributes[:'names-use-first'] if attribute? :'names-use-first'
@@ -354,6 +354,11 @@ module CSL
354
354
 
355
355
  def initialize(attrs = {})
356
356
  super(*attrs.symbolize_keys.values_at(*keys))
357
+ @order = []
358
+ end
359
+
360
+ def index(node, &block)
361
+ @order.index(node, &block)
357
362
  end
358
363
 
359
364
  # @return [<Symbol>] a list of symbols representing the names/keys
@@ -362,23 +367,19 @@ module CSL
362
367
  __class__.keys
363
368
  end
364
369
 
365
- alias original_each each
366
370
 
367
371
  def count
368
- values.reject { |c| c.nil? || c.empty? }.length
372
+ values.reject { |c| c.nil? || c.is_a?(Array) && c.empty? }.length
369
373
  end
370
374
 
375
+ alias original_each each
376
+
371
377
  # Iterates through all children. Nil values are skipped and Arrays
372
378
  # expanded.
373
379
  def each
374
380
  if block_given?
375
- original_each do |node|
376
- if node.kind_of?(Array)
377
- node.select { |n| !n.nil? }.each(&Proc.new)
378
- else
379
- yield node unless node.nil?
380
- end
381
- end
381
+ order.each(&Proc.new)
382
+ self
382
383
  else
383
384
  to_enum
384
385
  end
@@ -407,6 +408,9 @@ module CSL
407
408
  self[node.nodename] = [current, node]
408
409
  end
409
410
 
411
+ # Add to @order to keep track of node ordering
412
+ @order << node
413
+
410
414
  self
411
415
  end
412
416
 
@@ -430,6 +434,9 @@ module CSL
430
434
  end
431
435
  end
432
436
 
437
+ # Delete node from ordered list as well
438
+ @order.delete(node)
439
+
433
440
  if deleted.nil? && block_given?
434
441
  yield
435
442
  else
@@ -445,6 +452,10 @@ module CSL
445
452
  end
446
453
  end
447
454
 
455
+ protected
456
+
457
+ attr_reader :order
458
+
448
459
  private
449
460
 
450
461
  def resolve(nodename)
@@ -1,3 +1,3 @@
1
1
  module CSL
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'.freeze
3
3
  end
@@ -145,6 +145,30 @@ module CSL
145
145
  end
146
146
  end
147
147
 
148
+ describe '#dup' do
149
+ it 'does not copy ancestors' do
150
+ apa = Style.load(:apa).info
151
+ apa.should be_a(Info)
152
+
153
+ apa.should_not be_root
154
+ apa.dup.should be_root
155
+ end
156
+ end
157
+
158
+ describe '#deep_copy' do
159
+ it 'copies the full sub-tree' do
160
+ apa = Style.load(:apa).info
161
+ apa.should be_a(Info)
162
+
163
+ xml = apa.to_xml
164
+
165
+ copy = apa.deep_copy
166
+
167
+ apa.to_xml.should == xml # original unchanged!
168
+ copy.to_xml.should == xml
169
+ end
170
+ end
171
+
148
172
  describe '#pretty_print' do
149
173
  it 'returns an empty info element by default' do
150
174
  subject.pretty_print.should == '<info/>'
@@ -172,8 +196,8 @@ module CSL
172
196
 
173
197
  let(:poe) {
174
198
  Info::Author.new { |a|
175
- a.email = 'poe@baltimore.com'
176
199
  a.name = 'E. A. Poe'
200
+ a.email = 'poe@baltimore.com'
177
201
  }
178
202
  }
179
203
 
@@ -236,4 +260,19 @@ module CSL
236
260
 
237
261
  end
238
262
 
239
- end
263
+ describe Info::Rights do
264
+ it { should_not be_nil }
265
+
266
+ describe '#dup' do
267
+ it 'copies attributes and text' do
268
+ r = Info::Rights.new('foo')
269
+ r[:license] = 'bar'
270
+
271
+ c = r.dup
272
+ c.text.should == 'foo'
273
+ c[:license].should == 'bar'
274
+ end
275
+ end
276
+ end
277
+
278
+ end
@@ -2,6 +2,6 @@ require 'spec_helper'
2
2
 
3
3
  module CSL
4
4
  describe Style::Citation do
5
-
5
+
6
6
  end
7
- end
7
+ end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module CSL
4
4
  describe Style::Sort do
5
-
5
+ it { should_not have_sort_keys }
6
6
  end
7
7
 
8
8
  describe Style::Sort::Key do
@@ -39,6 +39,20 @@ module CSL
39
39
  end
40
40
  end
41
41
 
42
+ describe '#deep_copy' do
43
+ it 'works on apa style' do
44
+ apa = Style.load(:apa)
45
+ apa.should be_a(Style)
46
+
47
+ xml = apa.to_xml
48
+
49
+ copy = apa.deep_copy
50
+
51
+ apa.to_xml.should == xml # original unchanged!
52
+ copy.to_xml.should == xml
53
+ end
54
+ end
55
+
42
56
  describe '#children' do
43
57
 
44
58
  it { should_not have_info }
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvester Keil
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-28 00:00:00.000000000 Z
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: namae
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.7'
27
27
  description: "\n\t\tA Ruby parser and full API for the Citation Style Language (CSL),\n\t\tan
@@ -32,13 +32,13 @@ executables: []
32
32
  extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
- - ".coveralls.yml"
36
- - ".document"
37
- - ".gitignore"
38
- - ".rspec"
39
- - ".simplecov"
40
- - ".travis.yml"
41
- - ".yardopts"
35
+ - .coveralls.yml
36
+ - .document
37
+ - .gitignore
38
+ - .rspec
39
+ - .simplecov
40
+ - .travis.yml
41
+ - .yardopts
42
42
  - AGPL
43
43
  - BSDL
44
44
  - Gemfile
@@ -131,17 +131,17 @@ require_paths:
131
131
  - lib
132
132
  required_ruby_version: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - ">="
134
+ - - '>='
135
135
  - !ruby/object:Gem::Version
136
136
  version: 1.9.3
137
137
  required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  requirements:
139
- - - ">="
139
+ - - '>='
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
143
  rubyforge_project:
144
- rubygems_version: 2.2.1
144
+ rubygems_version: 2.0.14
145
145
  signing_key:
146
146
  specification_version: 4
147
147
  summary: A Ruby CSL parser and library