csl 1.0.0.pre13 → 1.0.0.pre14

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/Gemfile CHANGED
@@ -16,6 +16,7 @@ group :extra do
16
16
  gem 'guard', '~>1.2'
17
17
  gem 'guard-rspec', '~>1.1'
18
18
  gem 'guard-cucumber', '~>1.2'
19
+ gem 'rb-fsevent', '~>0.9.1', :platforms => [:mri_19, :rbx]
19
20
 
20
21
  gem 'yard', '~>0.8', :platforms => [:mri_19]
21
22
  gem 'redcarpet', '~>2.1', :platforms => [:mri_19]
data/lib/csl/loader.rb CHANGED
@@ -23,16 +23,22 @@ module CSL
23
23
  #
24
24
  # @note
25
25
  # The base class is exepcted to define a #parse method.
26
+ #
27
+ # @raise ParseError
28
+ #
29
+ # @return [Style, Locale] the parsed CSL resource
26
30
  def load(input)
27
31
  case
28
32
  when input.respond_to?(:read)
29
33
  data = input.read
30
34
  when input.to_s =~ /^\s*</
31
- data = input
35
+ data = input.to_s
32
36
  else
33
37
 
38
+ input = input.to_s
39
+
34
40
  case
35
- when File.exists?(input.to_s)
41
+ when File.exists?(input)
36
42
  location = input
37
43
  when File.exists?(extend_name(input))
38
44
  location = extend_name(input)
@@ -26,6 +26,8 @@ module CSL
26
26
  options = Term.specialize(options)
27
27
  options[:name] = name = name.to_s
28
28
 
29
+ # TODO default to long form
30
+
29
31
  term = registry[name].detect { |t| t.match?(options) }
30
32
  return term unless term.nil? && options.delete(:'gender-form')
31
33
 
@@ -8,20 +8,33 @@ module CSL
8
8
 
9
9
  has_no_children
10
10
 
11
+ @variables = [:locator, :page].concat(Schema.variables[:number]).freeze
12
+
13
+ class << self
14
+ attr_reader :variables
15
+ end
16
+
11
17
  def has_variable?
18
+ return parent.has_variable? if names_label?
12
19
  attribute?(:variable)
13
20
  end
14
21
 
22
+ # The value of the node's variable attribute. If the {Label}
23
+ # is the child of a {Names} node, returns the parent's variable
24
+ # attribute instead.
25
+ #
26
+ # @return [String] the value of the node's variable attribute
15
27
  def variable
28
+ return parent.variable if name_label?
16
29
  attributes[:variable]
17
30
  end
18
31
 
19
- def locator?
20
- variable.to_s =~ /^locator$/i
21
- end
32
+ Label.variables.each do |type|
33
+ pattern = Regexp.new("^#{type}", true)
22
34
 
23
- def page?
24
- variable.to_s =~ /^page$/i
35
+ define_method("#{type}?".tr('-', '_')) do
36
+ variable.to_s =~ pattern
37
+ end
25
38
  end
26
39
 
27
40
  def always_pluralize?
@@ -32,6 +45,12 @@ module CSL
32
45
  attributes[:plural].to_s =~ /^never$/i
33
46
  end
34
47
 
48
+ # @return [Boolean] whether or not the {Label} is inside a {Names} node
49
+ def names_label?
50
+ parent.is_a?(Names)
51
+ end
52
+ alias name_label? names_label?
53
+
35
54
  end
36
55
 
37
56
  end
@@ -1,26 +1,34 @@
1
1
  module CSL
2
2
  class Style
3
-
3
+
4
4
  class Names < Node
5
-
6
- attr_struct :variable, *Schema.attr(:names, :delimiter, :affixes, :display, :font)
7
-
5
+
6
+ attr_struct :variable, *Schema.attr(:names, :delimiter, :affixes, :display, :font)
7
+
8
8
  attr_children :name, :'et-al', :label, :substitute
9
-
9
+
10
10
  alias labels label
11
-
11
+
12
12
  def initialize(attributes = {})
13
13
  super(attributes)
14
14
  children[:label] = []
15
-
15
+
16
16
  yield self if block_given?
17
17
  end
18
-
18
+
19
+ def has_variable?
20
+ attribute?(:variable)
21
+ end
22
+
23
+ def variable
24
+ attributes[:variable]
25
+ end
26
+
19
27
  end
20
-
21
-
28
+
29
+
22
30
  class Name < Node
23
-
31
+
24
32
  attr_struct :form, *Schema.attr(:name, :affixes, :font, :delimiter)
25
33
 
26
34
  attr_children :'name-part'
@@ -33,14 +41,14 @@ module CSL
33
41
 
34
42
  yield self if block_given?
35
43
  end
36
-
44
+
37
45
  end
38
46
 
39
47
  class NamePart < Node
40
48
  has_no_children
41
49
  attr_struct :name, :'text-case', *Schema.attr(:affixes, :font)
42
50
  end
43
-
51
+
44
52
  class EtAl < Node
45
53
  has_no_children
46
54
  attr_struct :term, *Schema.attr(:affixes, :font)
@@ -48,7 +56,7 @@ module CSL
48
56
 
49
57
  class Substitute < Node
50
58
  end
51
-
52
-
59
+
60
+
53
61
  end
54
62
  end
data/lib/csl/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module CSL
2
- VERSION = '1.0.0.pre13'.freeze
2
+ VERSION = '1.0.0.pre14'.freeze
3
3
  end
@@ -10,11 +10,17 @@ module CSL
10
10
 
11
11
  describe '#to_xml' do
12
12
  it 'returns an empty style' do
13
- Style.new.to_xml.should match(/<style[^>]*\/>/)
13
+ Style.new.to_xml.should match(/^<style[^>]*\/>/)
14
14
  end
15
15
 
16
16
  it 'supports round-trip for apa style' do
17
- Style.parse(Style.load(:apa).to_xml).should be_a(Style)
17
+ apa = Style.load(:apa)
18
+ apa.should be_a(Style)
19
+
20
+ xml = apa.to_xml
21
+ xml.should match(/^<style[^>]*>/)
22
+
23
+ Style.parse(xml).should be_a(Style)
18
24
  end
19
25
  end
20
26
 
@@ -73,23 +79,23 @@ module CSL
73
79
  it 'raises a validation error when adding a macro without name' do
74
80
  expect { Style.new << Style::Macro.new }.to raise_error(ValidationError)
75
81
  end
76
-
82
+
77
83
  describe 'when it has an "author" macro' do
78
84
  before(:all) { style << Style::Macro.new(:name => 'author') }
79
85
 
80
86
  it 'has macros' do
81
87
  style.should have_macros
82
88
  end
83
-
89
+
84
90
  it 'the macro is registered in the macros hash' do
85
91
  style.macros.should have_key('author')
86
92
  style.macros['author'].should be_a(Style::Macro)
87
93
  end
88
-
94
+
89
95
  it 'raises a validation error when adding a macro with a duplicate name' do
90
96
  expect { style << Style::Macro.new(:name => 'author') }.to raise_error(ValidationError)
91
97
  end
92
-
98
+
93
99
  it 'unregisters the macro when it is deleted' do
94
100
  expect { style.delete style.macros['author'] }.to change { style.macros.length }
95
101
  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.pre13
4
+ version: 1.0.0.pre14
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-17 00:00:00.000000000 Z
12
+ date: 2013-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: namae
@@ -182,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
182
182
  version: '0'
183
183
  segments:
184
184
  - 0
185
- hash: -2590038154395651463
185
+ hash: -4493018161482760031
186
186
  required_rubygems_version: !ruby/object:Gem::Requirement
187
187
  none: false
188
188
  requirements: