citeproc-ruby 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/BSDL CHANGED
@@ -1,7 +1,7 @@
1
1
  CiteProc-Ruby. A Ruby CSL cite processor.
2
2
 
3
3
  Copyright 2012 President and Fellows of Harvard College.
4
- Copyright 2009-2014 Sylvester Keil. All rights reserved.
4
+ Copyright 2009-2016 Sylvester Keil. All rights reserved.
5
5
 
6
6
  Redistribution and use in source and binary forms, with or without
7
7
  modification, are permitted provided that the following conditions are met:
data/README.md CHANGED
@@ -7,8 +7,9 @@ cite processor, please refer to the documentation of the
7
7
  [citeproc](https://rubygems.org/gems/citeproc) gem instead.
8
8
 
9
9
  [![Build Status](https://secure.travis-ci.org/inukshuk/citeproc-ruby.png)](http://travis-ci.org/inukshuk/citeproc-ruby)
10
- [![Coverage Status](https://coveralls.io/repos/inukshuk/citeproc-ruby/badge.png?branch=master)](https://coveralls.io/r/inukshuk/citeproc-ruby?branch=master)
11
- [![Dependency Status](https://gemnasium.com/inukshuk/citeproc-ruby.png)](https://gemnasium.com/inukshuk/citeproc-ruby)
10
+ [![Coverage Status](https://coveralls.io/repos/github/inukshuk/citeproc-ruby/badge.svg?branch=master)](https://coveralls.io/github/inukshuk/citeproc-ruby?branch=master)
11
+ [![Dependency Status](https://gemnasium.com/badges/github.com/inukshuk/citeproc-ruby.svg)](https://gemnasium.com/github.com/inukshuk/citeproc-ruby)
12
+ [![Code Climate](https://codeclimate.com/github/inukshuk/citeproc-ruby/badges/gpa.svg)](https://codeclimate.com/github/inukshuk/citeproc-ruby)
12
13
 
13
14
  Quickstart
14
15
  ----------
@@ -146,7 +147,7 @@ this project as part of [Google Summer of Code](https://developers.google.com/op
146
147
 
147
148
  Copyright
148
149
  ---------
149
- Copyright 2009-2015 Sylvester Keil. All rights reserved.
150
+ Copyright 2009-2016 Sylvester Keil. All rights reserved.
150
151
 
151
152
  Copyright 2012 President and Fellows of Harvard College.
152
153
 
@@ -251,7 +251,7 @@ module CiteProc
251
251
  if word_boundary == '.'
252
252
  word
253
253
  else
254
- "#{CiteProc.upcase($2)}#{$3}"
254
+ "#{CiteProc.upcase(first_letter)}#{rest_of_word}"
255
255
  end
256
256
  end
257
257
  end
@@ -17,6 +17,56 @@ module CiteProc
17
17
 
18
18
  end
19
19
 
20
+ class Sort < Text
21
+ #A special format to use when sorting which prevents formatting of extraneous things like quotes
22
+
23
+ def apply(input, node, locale = nil)
24
+ return '' if input.nil?
25
+ return input if input.empty? || node.nil?
26
+
27
+ return ArgumentError unless node.respond_to?(:formatting_options)
28
+
29
+
30
+ @input, @output, @node, @locale = input, input.dup, node, locale
31
+
32
+ setup!
33
+
34
+ # NB: Layout nodes apply formatting to
35
+ # affixes; all other nodes do not!
36
+ if node.is_a? CSL::Style::Layout
37
+ apply_prefix if options.key?(:prefix)
38
+ apply_suffix if options.key?(:suffix)
39
+ end
40
+
41
+ keys.each do |format|
42
+ if options.key?(format)
43
+ method = "apply_#{format}".tr('-', '_')
44
+ send method if respond_to?(method)
45
+ end
46
+ end unless options.empty?
47
+
48
+ output.gsub!(/\.+/, '') if node.strip_periods?
49
+
50
+ #Do not apply quotes when sorting
51
+ #apply_quotes if node.quotes? && !locale.nil?
52
+
53
+ finalize_content!
54
+
55
+ unless node.is_a? CSL::Style::Layout
56
+ apply_prefix if options.key?(:prefix)
57
+ apply_suffix if options.key?(:suffix)
58
+ end
59
+
60
+ apply_display if options.key?(:display)
61
+
62
+ finalize!
63
+
64
+ output
65
+ ensure
66
+ cleanup!
67
+ end
68
+ end
69
+
20
70
  class Debug < Format
21
71
  end
22
72
 
@@ -165,7 +165,7 @@ module CiteProc
165
165
  def attribute_assignments(options)
166
166
  return unless options
167
167
 
168
- options = options.select { |k, v| !v.nil? }
168
+ options = options.select { |_, v| !v.nil? }
169
169
 
170
170
  return unless !options.empty?
171
171
 
@@ -102,7 +102,7 @@ module CiteProc
102
102
  state.store! nil, key
103
103
 
104
104
  original_format = @format
105
- @format = Formats::Text.new
105
+ @format = Formats::Sort.new
106
106
 
107
107
  if a.is_a?(CiteProc::Names)
108
108
  [render_name(a, node), render_name(b, node)]
@@ -149,7 +149,8 @@ module CiteProc
149
149
  # Add spaces around connector
150
150
  connector = " #{connector} " unless connector.nil?
151
151
 
152
- rendered_names = case
152
+ rendered_names =
153
+ case
153
154
  when node.truncate?(names)
154
155
  truncated = node.truncate(names)
155
156
 
@@ -4,7 +4,7 @@ module CiteProc
4
4
  module SortItems
5
5
 
6
6
  def sort!(items, keys)
7
- return itmes unless !keys.nil? && !keys.empty?
7
+ return items unless !keys.nil? && !keys.empty?
8
8
 
9
9
  # TODO refactor
10
10
  if items.is_a?(CitationData)
@@ -41,7 +41,7 @@ module CiteProc
41
41
  # Return early if one side is nil. In this
42
42
  # case ascending/descending is irrelevant!
43
43
  return 1 if va.nil? || va.empty?
44
- return -1 if vb.nil? || va.empty?
44
+ return -1 if vb.nil? || vb.empty?
45
45
 
46
46
  result = case CiteProc::Variable.types[key.variable]
47
47
  when :names
@@ -1,5 +1,5 @@
1
1
  module CiteProc
2
2
  module Ruby
3
- VERSION = '1.1.4'
3
+ VERSION = '1.1.5'
4
4
  end
5
5
  end
@@ -27,7 +27,28 @@ module CiteProc
27
27
  expect(cp.bibliography(:none => {})).to be_empty
28
28
  end
29
29
  end
30
-
30
+ describe 'should order entries correctly' do
31
+ describe 'mla 8' do
32
+ let(:cp_mla) { CiteProc::Processor.new :style => 'modern-language-association-8th-edition', :format => 'html' }
33
+ before(:each) do
34
+ cp_mla << items(:aaron2).data
35
+ cp_mla << items(:abbott).data
36
+ cp_mla << items(:knuth1968).data
37
+ end
38
+
39
+ it 'should not add quotes around text items when rendering for sorting purposes' do
40
+ cp_bib1_hash = cp_mla.bibliography.to_citeproc
41
+ bib_entries = cp_bib1_hash[1]
42
+ expect(bib_entries[0]).to start_with('Aaron')
43
+ # no author specified on Abbott. In MLA8 title is a substitute for name, thus it was being rendered in text
44
+ # format to get a sortable value for author. This produced a string starting with a quote character which
45
+ # messed up sorting. Have created a special sort format which is overridden to not inject these quotes.
46
+ # may be other things that could be prevented here (suffix/prefix) but I haven't run across them yet
47
+ expect(bib_entries[1]).to start_with('“Abbott')
48
+ expect(bib_entries[2]).to start_with('Knuth')
49
+ end
50
+ end
51
+ end
31
52
  end
32
53
 
33
54
  describe '#render' do
@@ -85,8 +85,28 @@ module Fixtures
85
85
  :language => 'fr',
86
86
  :publisher => 'Éditions du Seuil',
87
87
  :'publisher-place' => 'Paris'
88
- )
88
+ ),
89
+
90
+ :aaron1 => CiteProc::Item.new(
91
+ type: 'website',
92
+ id: 2,
93
+ author: [{given: 'Hank', family: 'Aaron'}],
94
+ title: 'Spitball'
95
+ ),
89
96
 
97
+ :aaron2 => CiteProc::Item.new(
98
+ type: 'website',
99
+ id: 3,
100
+ author: [{given: 'Hank', family: 'Aaron'}],
101
+ title: 'Baseball Fever'
102
+ ),
103
+
104
+ :abbott => CiteProc::Item.new(
105
+ type: 'website',
106
+ id: 4,
107
+ title: 'Abbott and Costello',
108
+ :'container-title' => 'McMillan'
109
+ )
90
110
  }
91
111
  end
92
112
 
@@ -0,0 +1,293 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" demote-non-dropping-particle="never">
3
+ <info>
4
+ <title>Modern Language Association 8th edition</title>
5
+ <title-short>MLA</title-short>
6
+ <id>http://www.zotero.org/styles/modern-language-association-8th-edition</id>
7
+ <link href="http://www.zotero.org/styles/modern-language-association-8th-edition" rel="self"/>
8
+ <link href="http://style.mla.org" rel="documentation"/>
9
+ <author>
10
+ <name>Sebastian Karcher</name>
11
+ </author>
12
+ <category citation-format="author"/>
13
+ <category field="generic-base"/>
14
+ <summary>This style adheres to the MLA 8th edition handbook. Follows the structure of references as outlined in the MLA Manual closely</summary>
15
+ <updated>2014-07-06T20:05:10+00:00</updated>
16
+ <rights license="http://creativecommons.org/licenses/by-sa/3.0/">This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License</rights>
17
+ </info>
18
+ <locale xml:lang="en">
19
+ <date form="text">
20
+ <date-part name="day" suffix=" "/>
21
+ <date-part name="month" suffix=" " form="short"/>
22
+ <date-part name="year"/>
23
+ </date>
24
+ <terms>
25
+ <term name="month-01" form="short">Jan.</term>
26
+ <term name="month-02" form="short">Feb.</term>
27
+ <term name="month-03" form="short">Mar.</term>
28
+ <term name="month-04" form="short">Apr.</term>
29
+ <term name="month-05" form="short">May</term>
30
+ <term name="month-06" form="short">June</term>
31
+ <term name="month-07" form="short">July</term>
32
+ <term name="month-08" form="short">Aug.</term>
33
+ <term name="month-09" form="short">Sept.</term>
34
+ <term name="month-10" form="short">Oct.</term>
35
+ <term name="month-11" form="short">Nov.</term>
36
+ <term name="month-12" form="short">Dec.</term>
37
+ <term name="translator" form="short">trans.</term>
38
+ </terms>
39
+ </locale>
40
+ <macro name="author">
41
+ <names variable="author">
42
+ <name name-as-sort-order="first" and="text" delimiter-precedes-last="always" delimiter-precedes-et-al="always" initialize="false" initialize-with=". "/>
43
+ <label form="long" prefix=", "/>
44
+ <substitute>
45
+ <names variable="editor"/>
46
+ <names variable="translator"/>
47
+ <text macro="title-short"/>
48
+ </substitute>
49
+ </names>
50
+ </macro>
51
+ <macro name="author-short">
52
+ <group delimiter=", ">
53
+ <names variable="author">
54
+ <name form="short" initialize-with=". " and="text"/>
55
+ <substitute>
56
+ <names variable="editor"/>
57
+ <names variable="translator"/>
58
+ <text macro="title-short"/>
59
+ </substitute>
60
+ </names>
61
+ <choose>
62
+ <if disambiguate="true">
63
+ <text macro="title-short"/>
64
+ </if>
65
+ </choose>
66
+ </group>
67
+ </macro>
68
+ <macro name="title">
69
+ <choose>
70
+ <if variable="container-title" match="any">
71
+ <text variable="title" quotes="true"/>
72
+ </if>
73
+ <else>
74
+ <text variable="title" font-style="italic"/>
75
+ </else>
76
+ </choose>
77
+ </macro>
78
+ <macro name="title-short">
79
+ <choose>
80
+ <if variable="container-title" match="any">
81
+ <text variable="title" form="short" quotes="true"/>
82
+ </if>
83
+ <else>
84
+ <text variable="title" form="short" font-style="italic"/>
85
+ </else>
86
+ </choose>
87
+ </macro>
88
+ <macro name="container-title">
89
+ <text variable="container-title" font-style="italic"/>
90
+ </macro>
91
+ <macro name="other-contributors">
92
+ <choose>
93
+ <if variable="container-title" match="any">
94
+ <names variable="editor translator" delimiter=", ">
95
+ <label form="verb" suffix=" "/>
96
+ <name and="text"/>
97
+ </names>
98
+ </if>
99
+ <else>
100
+ <names variable="editor translator" delimiter=", ">
101
+ <label form="verb" suffix=" " text-case="capitalize-first"/>
102
+ <name and="text"/>
103
+ </names>
104
+ </else>
105
+ </choose>
106
+ </macro>
107
+ <macro name="version">
108
+ <group delimiter=", ">
109
+ <choose>
110
+ <if is-numeric="edition">
111
+ <group delimiter=" ">
112
+ <number variable="edition" form="ordinal"/>
113
+ <text term="edition" form="short"/>
114
+ </group>
115
+ </if>
116
+ <else>
117
+ <text variable="edition" text-case="capitalize-first"/>
118
+ </else>
119
+ </choose>
120
+ <text variable="version"/>
121
+ </group>
122
+ </macro>
123
+ <macro name="number">
124
+ <group delimiter=", ">
125
+ <group>
126
+ <choose>
127
+ <!--lowercase if we have a preceding element-->
128
+ <if variable="edition container-title" match="any">
129
+ <group delimiter=" ">
130
+ <text term="volume" form="short"/>
131
+ <text variable="volume"/>
132
+ </group>
133
+ </if>
134
+ <!--other contributors preceding the volume-->
135
+ <else-if variable="author editor" match="all">
136
+ <group delimiter=" ">
137
+ <text term="volume" form="short"/>
138
+ <text variable="volume"/>
139
+ </group>
140
+ </else-if>
141
+ <else>
142
+ <group delimiter=" ">
143
+ <text term="volume" form="short" text-case="capitalize-first"/>
144
+ <text variable="volume"/>
145
+ </group>
146
+ </else>
147
+ </choose>
148
+ </group>
149
+ <group delimiter=" ">
150
+ <text term="issue" form="short"/>
151
+ <text variable="issue"/>
152
+ </group>
153
+ <choose>
154
+ <if type="report">
155
+ <text variable="genre"/>
156
+ </if>
157
+ </choose>
158
+ <text variable="number"/>
159
+ </group>
160
+ </macro>
161
+ <macro name="publisher">
162
+ <text variable="publisher"/>
163
+ </macro>
164
+ <macro name="publication-date">
165
+ <choose>
166
+ <if type="book chapter paper-conference motion_picture" match="any">
167
+ <date variable="issued" form="numeric" date-parts="year"/>
168
+ </if>
169
+ <else-if type="article-journal article-magazine" match="any">
170
+ <date variable="issued" form="text" date-parts="year-month"/>
171
+ </else-if>
172
+ <else-if type="webpage" match="any">
173
+ <date variable="issued" form="text"/>
174
+ </else-if>
175
+ <else-if type="speech" match="none">
176
+ <date variable="issued" form="text"/>
177
+ </else-if>
178
+ </choose>
179
+ </macro>
180
+ <macro name="location">
181
+ <group delimiter=", ">
182
+ <group delimiter=" ">
183
+ <label variable="page" form="short"/>
184
+ <text variable="page"/>
185
+ </group>
186
+ <choose>
187
+ <if variable="source" match="none">
188
+ <choose>
189
+ <if variable="URL DOI" match="any">
190
+ <text macro="URI"/>
191
+ </if>
192
+ </choose>
193
+ </if>
194
+ </choose>
195
+ </group>
196
+ </macro>
197
+ <macro name="container2-title">
198
+ <group delimiter=", ">
199
+ <choose>
200
+ <if type="speech">
201
+ <text variable="event"/>
202
+ <date variable="event-date" form="text"/>
203
+ <text variable="event-place"/>
204
+ </if>
205
+ </choose>
206
+ <text variable="archive"/>
207
+ <text variable="archive-place"/>
208
+ <text variable="archive_location"/>
209
+ </group>
210
+ </macro>
211
+ <macro name="container2-location">
212
+ <choose>
213
+ <if variable="source">
214
+ <group delimiter=", ">
215
+ <text variable="source" font-style="italic"/>
216
+ <text macro="URI"/>
217
+ </group>
218
+ </if>
219
+ </choose>
220
+ </macro>
221
+ <macro name="URI">
222
+ <choose>
223
+ <if variable="DOI">
224
+ <text variable="DOI" prefix="doi:"/>
225
+ </if>
226
+ <else>
227
+ <text variable="URL"/>
228
+ </else>
229
+ </choose>
230
+ </macro>
231
+ <macro name="accessed">
232
+ <!--using accessed where we don't have an issued date; follows recommendation on p. 53 -->
233
+ <choose>
234
+ <if variable="issued" match="none">
235
+ <group delimiter=" ">
236
+ <text term="accessed" text-case="capitalize-first"/>
237
+ <date variable="accessed" form="text"/>
238
+ </group>
239
+ </if>
240
+ </choose>
241
+ </macro>
242
+ <citation et-al-min="3" et-al-use-first="1" disambiguate-add-names="true" disambiguate-add-givenname="true">
243
+ <layout prefix="(" suffix=")" delimiter="; ">
244
+ <choose>
245
+ <if locator="page">
246
+ <group delimiter=" ">
247
+ <text macro="author-short"/>
248
+ <text variable="locator"/>
249
+ </group>
250
+ </if>
251
+ <else>
252
+ <group delimiter=", ">
253
+ <text macro="author-short"/>
254
+ <group>
255
+ <label variable="locator" form="short"/>
256
+ <text variable="locator"/>
257
+ </group>
258
+ </group>
259
+ </else>
260
+ </choose>
261
+ </layout>
262
+ </citation>
263
+ <bibliography hanging-indent="true" et-al-min="3" et-al-use-first="1" line-spacing="2" entry-spacing="0" subsequent-author-substitute="---">
264
+ <sort>
265
+ <key macro="author"/>
266
+ <key variable="title"/>
267
+ </sort>
268
+ <layout suffix=".">
269
+ <group delimiter=". ">
270
+ <text macro="author"/>
271
+ <text macro="title"/>
272
+ <date variable="original-date" form="numeric" date-parts="year"/>
273
+ <group delimiter=", ">
274
+ <!---This group corresponds to MLA's "Container 1"-->
275
+ <text macro="container-title"/>
276
+ <text macro="other-contributors"/>
277
+ <text macro="version"/>
278
+ <text macro="number"/>
279
+ <text macro="publisher"/>
280
+ <text macro="publication-date"/>
281
+ <text macro="location"/>
282
+ </group>
283
+ <group delimiter=", ">
284
+ <!---This group corresponds to MLA's "Container 2"-->
285
+ <!--currently just using this one for archival info-->
286
+ <text macro="container2-title"/>
287
+ <text macro="container2-location"/>
288
+ </group>
289
+ <text macro="accessed"/>
290
+ </group>
291
+ </layout>
292
+ </bibliography>
293
+ </style>