Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added label specs

  • Loading branch information...
commit b0c7002eb30fb0794c1002c9dac329ac5fab2aa1 1 parent 52c1ca2
Sylvester Keil authored
6 README.md
View
@@ -6,7 +6,8 @@ CiteProc-Ruby is a [Citation Style Language](http://citationstyles.org/) (CSL)
Development
-----------
-The CiteProc-Ruby source code is [hosted on GitHub](https://github.com/inukshuk/citeproc-ruby).
+The CiteProc-Ruby source code is
+[hosted on GitHub](https://github.com/inukshuk/citeproc-ruby).
You can check out a copy of the latest code using Git:
$ git clone https://github.com/inukshuk/citeproc-ruby.git
@@ -23,7 +24,8 @@ Or, for extra credit, clone the CiteProc-Ruby repository, write a failing
example, fix the bug and submit a pull request.
For the source code of the original CiteProc-Ruby release (gem versions
-0.0.x), please see the [0.0.x branch](https://github.com/inukshuk/citeproc-ruby/tree/0.0.x).
+0.0.x), please see the
+[0.0.x branch](https://github.com/inukshuk/citeproc-ruby/tree/0.0.x).
Copyright
1  lib/citeproc/ruby.rb
View
@@ -8,6 +8,7 @@
require 'citeproc/ruby/renderer'
require 'citeproc/ruby/renderer/text'
require 'citeproc/ruby/renderer/number'
+require 'citeproc/ruby/renderer/label'
require 'citeproc/ruby/renderer/date'
require 'citeproc/ruby/renderer/names'
require 'citeproc/ruby/renderer/layout'
2  lib/citeproc/ruby/renderer.rb
View
@@ -21,7 +21,7 @@ def render(data, node)
end
def translate(name, options = {})
- locale.translate options.merge(:name => name)
+ locale.translate options.merge(:name => name.to_s)
end
def ordinalize(number, options = {})
15 lib/citeproc/ruby/renderer/label.rb
View
@@ -9,12 +9,17 @@ class Renderer
def render_label(item, node)
return '' unless node.has_variable?
- if node.locator? || node.page?
- value = item.send node.variable
+ case
+ when node.page?
+ value, name = item.read_attribute(:page), node.variable
+ when node.locator?
+ value, name = item.locator, item.label
else
- value = item.data[node.variable].to_s
+ value, node = item.data[node.variable], node.variable
end
+ value = value.to_s
+
return '' if value.empty?
options = node.attributes_for :form
@@ -28,12 +33,12 @@ def render_label(item, node)
options[:plural] = pluralize?(value)
end
- translate node.variable, options
+ translate name, options
end
def pluralize?(string)
- string.to_s =~ /\S\s*[,&-]\s*\S|\df/
+ !!(string.to_s =~ /\S\s*[,&-]\s*\S|\df/)
end
end
49 spec/citeproc/ruby/renderer/label_spec.rb
View
@@ -0,0 +1,49 @@
+require 'spec_helper'
+
+module CiteProc
+ module Ruby
+
+ describe "Renderer#render_label" do
+ let(:renderer) { Renderer.new }
+
+ let(:node) { CSL::Style::Label.new }
+
+ let(:item) {
+ i = CiteProc::CitationItem.new(:id => 'ID-1')
+ i.data = CiteProc::Item.new(:id => 'ID-1')
+ i
+ }
+
+ describe 'given an empty node' do
+ it 'returns an empty string for an empty item' do
+ renderer.render_label(item, node).should == ''
+ end
+
+ it 'returns an empty string for an item with variables' do
+ item.data.edition = 'foo'
+ renderer.render_label(item, node).should == ''
+ end
+ end
+
+ describe "when the node's variable is set to :page" do
+ before(:each) { node[:variable] = :page }
+
+ describe "for an item with no page value" do
+ it 'returns an empty string' do
+ renderer.render_label(item, node).should == ''
+ end
+ end
+
+ describe "for an item with no page value" do
+ it 'returns the singular label for a number' do
+ item.write_attribute :page, '23'
+ renderer.render_label(item, node).should == 'p.'
+ end
+ end
+
+
+ end
+ end
+
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.