csl 1.3.2 → 1.4.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: 0e30d2946a20188221543f891c506525015d014d
4
- data.tar.gz: 81aef0240b86caa2ad7d0cd18fe0922beb30d50f
3
+ metadata.gz: 4c96baa9f034b77ad151b2128a0fe71abdb5fcce
4
+ data.tar.gz: 0a6f6c77c9cafdaf1b17a2bdb409c027268c6128
5
5
  SHA512:
6
- metadata.gz: bbbfbb2549ab0f66796897d374d5e7a56541236670537c0cc390fdb11c93f9cb295bdc52e75bb606ffdbe0949c30aa67e50079ef82a4d759e216bce2cecb2a4f
7
- data.tar.gz: a63a040322afce1fdb1784a8acd22979209416f8e38aa81f07d358c998a0374849de73ef4fde7679161e6a560ab8f54abcf4c342a990e69efa9651b8128bfdaa
6
+ metadata.gz: fdc03ad00c37bb330330dcdb20bd5e7233cfb130aa8e57213c51db877e99a4520d86d65c3c6b7bf7c435d84c50a240e096eaea4d20f3394367c292e7fdfb4c8c
7
+ data.tar.gz: cb38396b2dc1608de0fbd61d42a6f0798ed7ece661def1e105d75fdc020fbaf5094d729dbd0361194a3ceb0692ac94ed3378fad3cb64f6c6fa579fc92aa0e948
@@ -41,7 +41,7 @@ Feature: Loading CSL Locales
41
41
  <multiple>Ref.</multiple>
42
42
  </term>
43
43
  <term name="retrieved">abgerufen</term>
44
-
44
+
45
45
  <!-- LONG ROLE FORMS -->
46
46
  <term name="author">
47
47
  <single/>
@@ -54,4 +54,4 @@ Feature: Loading CSL Locales
54
54
  And the region should be "AT"
55
55
  And the attribute "version" should be "1.0"
56
56
  And the locale should should have 14 terms
57
- And the plural of the term "reference" should be "Referenzen"
57
+ And the plural of the term "reference" should be "Referenzen"
@@ -1,35 +1,35 @@
1
1
  Feature: Parse CSL localized date elements
2
- As a hacker of CSL styles
3
- I want to be able to parse CSL localized date strings
4
-
5
- Scenario: A text date
6
- When I parse the CSL string in the Locale scope
7
- """
8
- <date form="text">
9
- <date-part name="month" suffix=" "/>
10
- <date-part name="day" form="numeric-leading-zeros" suffix=", "/>
11
- <date-part name="year"/>
12
- </date>
13
- """
14
- Then the nodename should be "date"
15
- And the attribute "form" should be "text"
16
- And the node should have 3 parts
17
- And text? should be "true"
18
- And the part number 1 should have the attribute "name" set to "month"
2
+ As a hacker of CSL styles
3
+ I want to be able to parse CSL localized date strings
4
+
5
+ Scenario: A text date
6
+ When I parse the CSL string in the Locale scope
7
+ """
8
+ <date form="text">
9
+ <date-part name="month" suffix=" "/>
10
+ <date-part name="day" form="numeric-leading-zeros" suffix=", "/>
11
+ <date-part name="year"/>
12
+ </date>
13
+ """
14
+ Then the nodename should be "date"
15
+ And the attribute "form" should be "text"
16
+ And the node should have 3 parts
17
+ And text? should be "true"
18
+ And the part number 1 should have the attribute "name" set to "month"
19
+
20
+ Scenario: A numeric date
21
+ When I parse the CSL string in the Locale scope
22
+ """
23
+ <date form="numeric">
24
+ <date-part name="month" form="numeric-leading-zeros" suffix="/"/>
25
+ <date-part name="day" form="numeric-leading-zeros" suffix="/"/>
26
+ <date-part name="year"/>
27
+ </date>
28
+ """
29
+ Then the nodename should be "date"
30
+ And the attribute "form" should be "numeric"
31
+ And the node should have 3 parts
32
+ And text? should be "false"
33
+ And numeric? should be "true"
34
+ And the part number 3 should have the attribute "name" set to "year"
19
35
 
20
- Scenario: A numeric date
21
- When I parse the CSL string in the Locale scope
22
- """
23
- <date form="numeric">
24
- <date-part name="month" form="numeric-leading-zeros" suffix="/"/>
25
- <date-part name="day" form="numeric-leading-zeros" suffix="/"/>
26
- <date-part name="year"/>
27
- </date>
28
- """
29
- Then the nodename should be "date"
30
- And the attribute "form" should be "numeric"
31
- And the node should have 3 parts
32
- And text? should be "false"
33
- And numeric? should be "true"
34
- And the part number 3 should have the attribute "name" set to "year"
35
-
@@ -1,7 +1,7 @@
1
1
  Feature: Parse CSL localized terms
2
2
  As a hacker of CSL styles
3
3
  I want to be able to parse CSL localized terms
4
-
4
+
5
5
  Scenario: A few standard terms
6
6
  When I parse the CSL string
7
7
  """
@@ -8,41 +8,41 @@ Feature: Loading CSL Style
8
8
  <?xml version="1.0" encoding="utf-8"?>
9
9
  <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="never">
10
10
  <info>
11
- <title>American Psychological Association 6th Edition</title>
12
- <id>http://www.zotero.org/styles/apa</id>
13
- <link href="http://www.zotero.org/styles/apa" rel="self"/>
14
- <link href="http://owl.english.purdue.edu/owl/resource/560/01/" rel="documentation"/>
15
- <author>
16
- <name>Simon Kornblith</name>
17
- <email>simon@simonster.com</email>
18
- </author>
19
- <contributor>
20
- <name>Bruce D'Arcus</name>
21
- </contributor>
22
- <contributor>
23
- <name>Curtis M. Humphrey</name>
24
- </contributor>
25
- <contributor>
26
- <name>Richard Karnesky</name>
27
- <email>karnesky+zotero@gmail.com</email>
28
- <uri>http://arc.nucapt.northwestern.edu/Richard_Karnesky</uri>
29
- </contributor>
30
- <contributor>
31
- <name>Sebastian Karcher</name>
32
- </contributor>
33
- <category field="psychology"/>
34
- <category field="generic-base"/>
35
- <category citation-format="author-date"/>
36
- <updated>2010-01-27T20:08:03+00:00</updated>
37
- <rights>This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/</rights>
11
+ <title>American Psychological Association 6th Edition</title>
12
+ <id>http://www.zotero.org/styles/apa</id>
13
+ <link href="http://www.zotero.org/styles/apa" rel="self"/>
14
+ <link href="http://owl.english.purdue.edu/owl/resource/560/01/" rel="documentation"/>
15
+ <author>
16
+ <name>Simon Kornblith</name>
17
+ <email>simon@simonster.com</email>
18
+ </author>
19
+ <contributor>
20
+ <name>Bruce D'Arcus</name>
21
+ </contributor>
22
+ <contributor>
23
+ <name>Curtis M. Humphrey</name>
24
+ </contributor>
25
+ <contributor>
26
+ <name>Richard Karnesky</name>
27
+ <email>karnesky+zotero@gmail.com</email>
28
+ <uri>http://arc.nucapt.northwestern.edu/Richard_Karnesky</uri>
29
+ </contributor>
30
+ <contributor>
31
+ <name>Sebastian Karcher</name>
32
+ </contributor>
33
+ <category field="psychology"/>
34
+ <category field="generic-base"/>
35
+ <category citation-format="author-date"/>
36
+ <updated>2010-01-27T20:08:03+00:00</updated>
37
+ <rights>This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License: http://creativecommons.org/licenses/by-sa/3.0/</rights>
38
38
  </info>
39
39
  <locale xml:lang="en">
40
- <terms>
41
- <term name="translator" form="short">
42
- <single>trans.</single>
43
- <multiple>trans.</multiple>
44
- </term>
45
- </terms>
40
+ <terms>
41
+ <term name="translator" form="short">
42
+ <single>trans.</single>
43
+ <multiple>trans.</multiple>
44
+ </term>
45
+ </terms>
46
46
  </locale>
47
47
  </style>
48
48
  """
data/lib/csl/locale.rb CHANGED
@@ -101,13 +101,13 @@ module CSL
101
101
  def initialize(*arguments)
102
102
  case arguments.length
103
103
  when 0
104
- locale, attributes, options = Locale.default, {}, nil
104
+ locale, attributes, options = nil, {}, nil
105
105
  when 1
106
106
  if arguments[0].is_a?(Hash)
107
107
  arguments[0] = arguments[0].symbolize_keys
108
108
 
109
109
  locale = arguments[0].delete(:lang) ||
110
- arguments[0].delete(:'xml:lang') || Locale.default
110
+ arguments[0].delete(:'xml:lang')
111
111
 
112
112
  attributes, options = arguments
113
113
  else
@@ -371,6 +371,17 @@ module CSL
371
371
  language && language == Locale.languages[region]
372
372
  end
373
373
 
374
+ def like?(other)
375
+ return false unless other.is_a? Locale
376
+ return true if universal? || other.universal?
377
+
378
+ language == other.language
379
+ end
380
+
381
+ def universal?
382
+ language.nil?
383
+ end
384
+
374
385
  def validate
375
386
  Schema.validate self
376
387
  end
@@ -389,6 +400,7 @@ module CSL
389
400
  others.each do |other|
390
401
  merge_options other
391
402
  merge_dates other
403
+ merge_terms other
392
404
  end
393
405
 
394
406
  self
@@ -485,6 +497,16 @@ module CSL
485
497
 
486
498
  self
487
499
  end
500
+
501
+ def merge_terms(other)
502
+ return self unless other.has_terms?
503
+
504
+ other.each_term do |term|
505
+ store term.deep_copy
506
+ end
507
+
508
+ self
509
+ end
488
510
  end
489
511
 
490
512
  end
data/lib/csl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSL
2
- VERSION = '1.3.2'.freeze
2
+ VERSION = '1.4.0'.freeze
3
3
  end
@@ -48,12 +48,12 @@ module CSL
48
48
  describe '.new' do
49
49
  it { is_expected.not_to be_nil }
50
50
 
51
- it 'defaults to default language' do
52
- expect(Locale.new.language).to eq(Locale.default.split(/-/)[0].to_sym)
51
+ it 'has no language' do
52
+ expect(Locale.new.language).to be_nil
53
53
  end
54
54
 
55
- it 'defaults to default region' do
56
- expect(Locale.new.region).to eq(Locale.default.split(/-/)[1].to_sym)
55
+ it 'has no region' do
56
+ expect(Locale.new.region).to be_nil
57
57
  end
58
58
 
59
59
  it 'contains no dates by default' do
@@ -87,6 +87,12 @@ module CSL
87
87
 
88
88
  end
89
89
 
90
+ describe '.parse' do
91
+ it 'does not set a default language' do
92
+ expect(Locale.parse('<locale/>').language).to be_nil
93
+ end
94
+ end
95
+
90
96
  describe '#set' do
91
97
 
92
98
  it 'when passed "en-GB" sets language to :en and region to :GB' do
@@ -149,6 +155,29 @@ module CSL
149
155
  expect(locale).to have_dates
150
156
  end
151
157
  end
158
+
159
+ describe 'terms' do
160
+ let(:us) { Locale.load('en-US') }
161
+
162
+ it 'does not change the terms if none are set on either locale' do
163
+ expect { locale.merge!(Locale.new) }.not_to change { locale.terms.to_s }
164
+ end
165
+
166
+ it 'overrides terms with those of the other locale' do
167
+ expect(locale).not_to have_terms
168
+
169
+ locale.merge! us
170
+ expect(locale).to have_terms
171
+ end
172
+
173
+ it 'makes copies of the terms' do
174
+ locale.merge! us
175
+ expect(locale).to have_terms
176
+
177
+ expect(locale.terms.first).to eq(us.terms.first)
178
+ expect(locale.terms.first).not_to be(us.terms.first)
179
+ end
180
+ end
152
181
  end
153
182
 
154
183
  describe '#legacy?' do
@@ -2,30 +2,28 @@ require 'spec_helper'
2
2
 
3
3
  module CSL
4
4
  describe Style do
5
- before do
6
- @style = Style.new
7
- end
5
+ let(:style) { Style.new }
8
6
 
9
7
  it 'has a 1.x version by default' do
10
- expect(@style[:version]).to match(/1\.\d+(\.\d+)?/)
8
+ expect(style[:version]).to match(/1\.\d+(\.\d+)?/)
11
9
  end
12
10
 
13
11
  it 'has the default version' do
14
- expect(@style.default_attribute?(:version)).to be_truthy
12
+ expect(style.default_attribute?(:version)).to be_truthy
15
13
  end
16
14
 
17
15
  it 'has a the default namespace attribute' do
18
- expect(@style[:xmlns]).to eq(CSL::Schema.namespace)
19
- expect(@style.default_attribute?(:xmlns)).to be_truthy
16
+ expect(style[:xmlns]).to eq(CSL::Schema.namespace)
17
+ expect(style.default_attribute?(:xmlns)).to be_truthy
20
18
  end
21
19
 
22
20
  describe '#to_xml' do
23
21
  it 'returns an empty style' do
24
- expect(@style.to_xml).to match(/^<style[^>]*\/>/)
22
+ expect(style.to_xml).to match(/^<style[^>]*\/>/)
25
23
  end
26
24
 
27
25
  it 'includes the xml namespace' do
28
- expect(@style.to_xml).to match(CSL::Schema.namespace)
26
+ expect(style.to_xml).to match(CSL::Schema.namespace)
29
27
  end
30
28
 
31
29
  it 'supports round-trip for apa style' do
@@ -62,52 +60,52 @@ module CSL
62
60
  it { is_expected.not_to have_bibliography }
63
61
 
64
62
  describe 'when it has a title' do
65
- before { @style.title = 'foo' }
63
+ before { style.title = 'foo' }
66
64
 
67
- it { expect(@style).to have_info }
65
+ it { expect(style).to have_info }
68
66
 
69
67
  it 'info.title is a text node' do
70
- expect(@style.info.title).to be_a(TextNode)
68
+ expect(style.info.title).to be_a(TextNode)
71
69
  end
72
70
 
73
71
  it '#title returns the title as a string' do
74
- expect(@style.title).to be_a(String)
72
+ expect(style.title).to be_a(String)
75
73
  end
76
74
  end
77
75
  end
78
76
 
79
77
  describe '#id accessor' do
80
78
  it 'returns nil by default' do
81
- expect(@style.id).to be_nil
79
+ expect(style.id).to be_nil
82
80
  end
83
81
 
84
82
  it 'writer sets the id to the passed-in string' do
85
- expect { @style.id = 'foobar' }.to change { @style.id }.from(nil).to('foobar')
83
+ expect { style.id = 'foobar' }.to change { style.id }.from(nil).to('foobar')
86
84
  end
87
85
  end
88
86
 
89
87
  describe 'independent and dependent styles' do
90
88
  it 'styles are independent by default' do
91
- expect(@style).to be_independent
89
+ expect(style).to be_independent
92
90
  end
93
91
 
94
92
  it 'styles do not have independent-parent links by default' do
95
- expect(@style).not_to have_independent_parent_link
93
+ expect(style).not_to have_independent_parent_link
96
94
  end
97
95
 
98
96
  it 'when setting an independet-parent link a style becomes dependent' do
99
- expect { @style.independent_parent_link = 'foo' }.to change { @style.independent? }
97
+ expect { style.independent_parent_link = 'foo' }.to change { style.independent? }
100
98
  end
101
99
 
102
100
  it 'looks up independent styles parents locally first' do
103
- @style.independent_parent_link = 'http://example.com/non-existent/styles/apa'
104
- expect(@style.independent_parent).to eq Style.load('apa')
101
+ style.independent_parent_link = 'http://example.com/non-existent/styles/apa'
102
+ expect(style.independent_parent).to eq Style.load('apa')
105
103
  end
106
104
  end
107
105
 
108
106
  describe 'macros' do
109
107
  it 'has no macros by default' do
110
- expect(@style).not_to have_macros
108
+ expect(style).not_to have_macros
111
109
  end
112
110
 
113
111
  it 'raises a validation error when adding a macro without name' do
@@ -115,23 +113,23 @@ module CSL
115
113
  end
116
114
 
117
115
  describe 'when it has an "author" macro' do
118
- before { @style << Style::Macro.new(:name => 'author') }
116
+ before { style << Style::Macro.new(:name => 'author') }
119
117
 
120
118
  it 'has macros' do
121
- expect(@style).to have_macros
119
+ expect(style).to have_macros
122
120
  end
123
121
 
124
122
  it 'the macro is registered in the macros hash' do
125
- expect(@style.macros).to have_key('author')
126
- expect(@style.macros['author']).to be_a(Style::Macro)
123
+ expect(style.macros).to have_key('author')
124
+ expect(style.macros['author']).to be_a(Style::Macro)
127
125
  end
128
126
 
129
127
  it 'raises a validation error when adding a macro with a duplicate name' do
130
- expect { @style << Style::Macro.new(:name => 'author') }.to raise_error(ValidationError)
128
+ expect { style << Style::Macro.new(:name => 'author') }.to raise_error(ValidationError)
131
129
  end
132
130
 
133
131
  it 'unregisters the macro when it is deleted' do
134
- expect { @style.delete @style.macros['author'] }.to change { @style.macros.length }
132
+ expect { style.delete style.macros['author'] }.to change { style.macros.length }
135
133
  end
136
134
  end
137
135
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: csl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.2
4
+ version: 1.4.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: 2015-04-09 00:00:00.000000000 Z
11
+ date: 2015-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: namae