csl 1.0.0.pre14 → 1.0.0.pre15
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/csl/style/label.rb +24 -0
- data/lib/csl/version.rb +1 -1
- data/spec/csl/style/label_spec.rb +51 -1
- metadata +2 -2
data/lib/csl/style/label.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
module CSL
|
2
2
|
class Style
|
3
3
|
|
4
|
+
# Labels are used for printing the term matching the variable selected
|
5
|
+
# with the required variable attribute, which must be set to "locator,
|
6
|
+
# "page", or one of the number variables.
|
7
|
+
#
|
8
|
+
# The term is only rendered if the selected variable is non-empty.
|
9
|
+
#
|
10
|
+
# If the {Label} is the child of a {Names} node, the parent's variable
|
11
|
+
# is used instead of the local attribute.
|
4
12
|
class Label < Node
|
5
13
|
|
6
14
|
attr_struct :variable, :form, :plural,
|
@@ -10,8 +18,21 @@ module CSL
|
|
10
18
|
|
11
19
|
@variables = [:locator, :page].concat(Schema.variables[:number]).freeze
|
12
20
|
|
21
|
+
@terms = Hash.new { |h,k| h[k] = k }
|
22
|
+
|
23
|
+
@terms['number-of-pages'] = 'page'
|
24
|
+
@terms['number-of-volumes'] = 'volume'
|
25
|
+
@terms['chapter-number'] = 'chapter'
|
26
|
+
@terms['collection-number'] = 'collection'
|
27
|
+
|
13
28
|
class << self
|
29
|
+
# @!attribute [r] variables
|
30
|
+
# @return [Array<Symbol>] a list of valid label variable values
|
14
31
|
attr_reader :variables
|
32
|
+
|
33
|
+
# @!attribute [r] terms
|
34
|
+
# @return [Hash<String, String>] a cache for variable-term mapping
|
35
|
+
attr_reader :terms
|
15
36
|
end
|
16
37
|
|
17
38
|
def has_variable?
|
@@ -51,6 +72,9 @@ module CSL
|
|
51
72
|
end
|
52
73
|
alias name_label? names_label?
|
53
74
|
|
75
|
+
def term
|
76
|
+
Label.terms[variable]
|
77
|
+
end
|
54
78
|
end
|
55
79
|
|
56
80
|
end
|
data/lib/csl/version.rb
CHANGED
@@ -2,6 +2,56 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module CSL
|
4
4
|
describe Style::Label do
|
5
|
-
|
5
|
+
|
6
|
+
it { should_not be_names_label }
|
7
|
+
it { should_not be_always_pluralize }
|
8
|
+
it { should_not be_never_pluralize }
|
9
|
+
|
10
|
+
describe '.terms' do
|
11
|
+
Hash[%w{
|
12
|
+
page page
|
13
|
+
issue issue
|
14
|
+
edition edition
|
15
|
+
number-of-pages page
|
16
|
+
number-of-volumes volume
|
17
|
+
chapter-number chapter
|
18
|
+
}].each do |variable, term|
|
19
|
+
it "returns #{term.inspect} for #{variable.inspect}" do
|
20
|
+
Label.terms[variable].should == term
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'a label inside a names node' do
|
26
|
+
before(:each) { Style::Names.new << subject }
|
27
|
+
|
28
|
+
it { should be_names_label }
|
29
|
+
|
30
|
+
describe '#variable' do
|
31
|
+
before(:each) { subject.parent[:variable] = 'editor' }
|
32
|
+
|
33
|
+
it 'returns the names variable(s)' do
|
34
|
+
subject.variable.should == 'editor'
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns the names variable(s) even when the local attribute is set' do
|
38
|
+
subject[:variable] = 'page'
|
39
|
+
subject.variable.should == 'editor'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#term' do
|
45
|
+
it { should be_empty }
|
46
|
+
|
47
|
+
it 'returns the term for the current variable' do
|
48
|
+
subject[:variable] = 'page'
|
49
|
+
subject.term.should == 'page'
|
50
|
+
|
51
|
+
subject[:variable] = 'number-of-volumes'
|
52
|
+
subject.term.should == 'volume'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
6
56
|
end
|
7
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.pre15
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -182,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '0'
|
183
183
|
segments:
|
184
184
|
- 0
|
185
|
-
hash:
|
185
|
+
hash: 3229480668265481885
|
186
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
187
|
none: false
|
188
188
|
requirements:
|