citeproc-rb 0.0.1
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/README +93 -0
- data/Rakefile +73 -0
- data/TODO +25 -0
- data/VERSION +1 -0
- data/data/locales/locales_en.xml +89 -0
- data/data/locales/locales_nl.xml +96 -0
- data/data/styles/ama.csl +184 -0
- data/data/styles/apa.csl +230 -0
- data/data/styles/apsa.csl +175 -0
- data/data/styles/asa.csl +215 -0
- data/data/styles/chicago-author-date.csl +361 -0
- data/data/styles/chicago-fullnote-bibliography.csl +665 -0
- data/data/styles/chicago-note-bibliography.csl +437 -0
- data/data/styles/chicago-note.csl +383 -0
- data/data/styles/harvard.csl +185 -0
- data/data/styles/ieee.csl +111 -0
- data/data/styles/mhra.csl +317 -0
- data/data/styles/mla.csl +173 -0
- data/data/styles/nature.csl +87 -0
- data/data/styles/nlm.csl +118 -0
- data/examples/citeproc_driver.rb +174 -0
- data/lib/citeproc.rb +28 -0
- data/lib/citeproc/csl.rb +647 -0
- data/lib/citeproc/csl_parser.rb +479 -0
- data/lib/citeproc/csl_processor.rb +485 -0
- data/lib/citeproc/csl_reference.rb +228 -0
- data/lib/citeproc/filters/bibo/bibo.rb +635 -0
- data/lib/citeproc/filters/bibo/bibo_input_filter.rb +242 -0
- data/lib/citeproc/filters/bibo/bibo_utils.rb +75 -0
- data/lib/citeproc/filters/csl_citation/csl_citation.rb +137 -0
- data/lib/citeproc/filters/csl_citation/csl_citation_input_filter.rb +274 -0
- data/lib/citeproc/formatters/base_formatter.rb +115 -0
- data/lib/citeproc/formatters/xhtml_formatter.rb +144 -0
- data/lib/citeproc/input_filter.rb +97 -0
- data/test/fixtures/bibo_test_data.n3 +191 -0
- data/test/fixtures/bibo_test_data.yaml +96 -0
- data/test/fixtures/bibo_test_how_to_cook.n3 +63 -0
- data/test/fixtures/bibo_test_zotero.rdf +129 -0
- data/test/fixtures/csl_test_data.json +62 -0
- data/test/fixtures/csl_test_data.yaml +8 -0
- data/test/fixtures/locales/test_locale_en.xml +89 -0
- data/test/fixtures/styles/test_csl_parse.csl +230 -0
- data/test/fixtures/styles/test_groups.csl +32 -0
- data/test/fixtures/styles/test_names.csl +46 -0
- data/test/fixtures/styles/test_sort.csl +125 -0
- data/test/fixtures/styles/test_text_terms.csl +40 -0
- data/test/test_all.rb +14 -0
- data/test/test_bibo.rb +20 -0
- data/test/test_csl.rb +136 -0
- data/test/test_csl_parser.rb +222 -0
- data/test/test_sample_bibo.rb +82 -0
- metadata +101 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<?oxygen RNGSchema="http://xbiblio.svn.sourceforge.net/viewvc/*checkout*/xbiblio/csl/schema/trunk/csl.rnc" type="compact"?>
|
|
3
|
+
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" xml:lang="en">
|
|
4
|
+
<info>
|
|
5
|
+
</info>
|
|
6
|
+
<macro name="foo">
|
|
7
|
+
<text prefix="' " value="appear in the"/>
|
|
8
|
+
</macro>
|
|
9
|
+
<macro name="bar">
|
|
10
|
+
<text prefix=" " value="citation" suffix="."/>
|
|
11
|
+
</macro>
|
|
12
|
+
<citation>
|
|
13
|
+
<layout suffix=".">
|
|
14
|
+
</layout>
|
|
15
|
+
</citation>
|
|
16
|
+
<bibliography>
|
|
17
|
+
<layout suffix=".">
|
|
18
|
+
<group>
|
|
19
|
+
<text value="test"/>
|
|
20
|
+
<text variable="URL"/>
|
|
21
|
+
<text macro="foo"/>
|
|
22
|
+
<text macro="bar"/>
|
|
23
|
+
</group>
|
|
24
|
+
<group>
|
|
25
|
+
<text value="The words" suffix=" '"/>
|
|
26
|
+
<text variable="title"/>
|
|
27
|
+
<text macro="foo"/>
|
|
28
|
+
<text macro="bar"/>
|
|
29
|
+
</group>
|
|
30
|
+
</layout>
|
|
31
|
+
</bibliography>
|
|
32
|
+
</style>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" xml:lang="en">
|
|
3
|
+
<info>
|
|
4
|
+
<title>American Medical Association</title>
|
|
5
|
+
<id>http://www.zotero.org/styles/ama</id>
|
|
6
|
+
<link href="http://www.zotero.org/styles/ama"/>
|
|
7
|
+
<author>
|
|
8
|
+
<name>Julian Onions</name>
|
|
9
|
+
<email>julian.onions@gmail.com</email>
|
|
10
|
+
</author>
|
|
11
|
+
<category term="numeric"/>
|
|
12
|
+
<category term="medicine"/>
|
|
13
|
+
<updated>2008-03-08T20:38:52+00:00</updated>
|
|
14
|
+
<summary>The American Medical Association style as used in JAMA.</summary>
|
|
15
|
+
<link href="http://www.samford.edu/schools/pharmacy/dic/amaquickref07.pdf" rel="documentation"/>
|
|
16
|
+
</info>
|
|
17
|
+
<macro name="editor">
|
|
18
|
+
<names variable="editor">
|
|
19
|
+
<name name-as-sort-order="all" sort-separator=" " initialize-with="" delimiter=", " delimiter-precedes-last="always"/>
|
|
20
|
+
<label form="short" prefix=", " text-case="lowercase" suffix="."/>
|
|
21
|
+
</names>
|
|
22
|
+
</macro>
|
|
23
|
+
<macro name="anon">
|
|
24
|
+
<text term="anonymous" form="short" text-case="capitalize-first"/>
|
|
25
|
+
</macro>
|
|
26
|
+
<macro name="author">
|
|
27
|
+
<group suffix=".">
|
|
28
|
+
<names variable="author">
|
|
29
|
+
<name name-as-sort-order="all" sort-separator=" " initialize-with=""
|
|
30
|
+
delimiter=", " delimiter-precedes-last="always"/>
|
|
31
|
+
<label form="short" prefix=" " suffix="" text-case="lowercase"/>
|
|
32
|
+
<substitute>
|
|
33
|
+
<names variable="editor"/>
|
|
34
|
+
<text macro="anon"/>
|
|
35
|
+
</substitute>
|
|
36
|
+
</names>
|
|
37
|
+
</group>
|
|
38
|
+
</macro>
|
|
39
|
+
<citation>
|
|
40
|
+
</citation>
|
|
41
|
+
<bibliography>
|
|
42
|
+
<layout>
|
|
43
|
+
<text macro="author" suffix=""/>
|
|
44
|
+
</layout>
|
|
45
|
+
</bibliography>
|
|
46
|
+
</style>
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<style xmlns="http://purl.org/net/xbiblio/csl" xml:lang="en" class="in-text" >
|
|
3
|
+
<info>
|
|
4
|
+
<title>Chicago Manual of Style (Author-Date format)</title>
|
|
5
|
+
<id>http://www.zotero.org/styles/chicago-author-date</id>
|
|
6
|
+
<link href="http://www.zotero.org/styles/chicago-author-date"/>
|
|
7
|
+
<author>
|
|
8
|
+
<name>Julian Onions</name>
|
|
9
|
+
<email>julian.onions@gmail.com</email>
|
|
10
|
+
</author>
|
|
11
|
+
<category term="author-date"/>
|
|
12
|
+
<category term="generic-base"/>
|
|
13
|
+
<updated>2008-05-13T12:42:52+00:00</updated>
|
|
14
|
+
<summary>The author-date variant of the Chicago style</summary>
|
|
15
|
+
<link href="http://www.chicagomanualofstyle.org/tools_citationguide.html" rel="documentation"/>
|
|
16
|
+
</info>
|
|
17
|
+
<macro name="anon">
|
|
18
|
+
<choose>
|
|
19
|
+
<if variable="author editor translator" match="none">
|
|
20
|
+
<text term="anonymous" form="short" text-case="capitalize-first"/>
|
|
21
|
+
</if>
|
|
22
|
+
</choose>
|
|
23
|
+
</macro>
|
|
24
|
+
<macro name="editor">
|
|
25
|
+
<names variable="editor">
|
|
26
|
+
<name name-as-sort-order="first" and="text" sort-separator=", " delimiter=", " delimiter-precedes-last="always"/>
|
|
27
|
+
<label form="short" prefix=", " suffix="."/>
|
|
28
|
+
</names>
|
|
29
|
+
</macro>
|
|
30
|
+
<macro name="translator">
|
|
31
|
+
<names variable="translator">
|
|
32
|
+
<name name-as-sort-order="first" and="text" sort-separator=", " delimiter=", " delimiter-precedes-last="always"/>
|
|
33
|
+
<label form="verb-short" prefix=", " suffix="."/>
|
|
34
|
+
</names>
|
|
35
|
+
</macro>
|
|
36
|
+
<macro name="recipient">
|
|
37
|
+
<choose>
|
|
38
|
+
<if type="personal_communication">
|
|
39
|
+
<choose>
|
|
40
|
+
<if variable="genre">
|
|
41
|
+
<text variable="genre" text-case="capitalize-first"/>
|
|
42
|
+
</if>
|
|
43
|
+
<else>
|
|
44
|
+
<text term="letter" text-case="capitalize-first"/>
|
|
45
|
+
</else>
|
|
46
|
+
</choose>
|
|
47
|
+
</if>
|
|
48
|
+
</choose>
|
|
49
|
+
<names variable="recipient" delimiter=", ">
|
|
50
|
+
<label form="verb" prefix=" " text-case="lowercase" suffix=" "/>
|
|
51
|
+
<name and="text" delimiter=", "/>
|
|
52
|
+
</names>
|
|
53
|
+
</macro>
|
|
54
|
+
<macro name="contributors">
|
|
55
|
+
<names variable="author">
|
|
56
|
+
<name and="text" name-as-sort-order="first" sort-separator=", " delimiter=", "
|
|
57
|
+
delimiter-precedes-last="always"/>
|
|
58
|
+
<label form="verb-short" prefix=", " suffix="." text-case="lowercase"/>
|
|
59
|
+
<substitute>
|
|
60
|
+
<text macro="editor"/>
|
|
61
|
+
<text macro="translator"/>
|
|
62
|
+
</substitute>
|
|
63
|
+
</names>
|
|
64
|
+
<text macro="anon"/>
|
|
65
|
+
<text macro="recipient"/>
|
|
66
|
+
</macro>
|
|
67
|
+
<macro name="contributors-short">
|
|
68
|
+
<names variable="author">
|
|
69
|
+
<name form="short" and="text" delimiter=", "/>
|
|
70
|
+
<substitute>
|
|
71
|
+
<names variable="editor"/>
|
|
72
|
+
<names variable="translator"/>
|
|
73
|
+
</substitute>
|
|
74
|
+
</names>
|
|
75
|
+
<text macro="anon"/>
|
|
76
|
+
</macro>
|
|
77
|
+
<macro name="interviewer">
|
|
78
|
+
<names variable="interviewer" delimiter=", ">
|
|
79
|
+
<label form="verb" prefix=" " text-case="capitalize-first" suffix=" "/>
|
|
80
|
+
<name and="text" delimiter=", "/>
|
|
81
|
+
</names>
|
|
82
|
+
</macro>
|
|
83
|
+
<macro name="title">
|
|
84
|
+
<choose>
|
|
85
|
+
<if variable="title" match="none">
|
|
86
|
+
<choose>
|
|
87
|
+
<if type="personal_communication" match="none">
|
|
88
|
+
<text variable="genre" text-case="capitalize-first"/>
|
|
89
|
+
</if>
|
|
90
|
+
</choose>
|
|
91
|
+
</if>
|
|
92
|
+
<else-if type="book">
|
|
93
|
+
<text variable="title" font-style="italic"/>
|
|
94
|
+
</else-if>
|
|
95
|
+
<else>
|
|
96
|
+
<text variable="title"/>
|
|
97
|
+
</else>
|
|
98
|
+
</choose>
|
|
99
|
+
</macro>
|
|
100
|
+
<macro name="point-locators">
|
|
101
|
+
<group>
|
|
102
|
+
<choose>
|
|
103
|
+
<if locator="page" match="none">
|
|
104
|
+
<label variable="locator" form="short" include-period="true" suffix=" "/>
|
|
105
|
+
</if>
|
|
106
|
+
</choose>
|
|
107
|
+
<text variable="locator"/>
|
|
108
|
+
</group>
|
|
109
|
+
</macro>
|
|
110
|
+
<citation>
|
|
111
|
+
<layout>
|
|
112
|
+
</layout>
|
|
113
|
+
</citation>
|
|
114
|
+
<bibliography>
|
|
115
|
+
<sort>
|
|
116
|
+
<key macro="contributors"/>
|
|
117
|
+
<key variable="issued"/>
|
|
118
|
+
</sort>
|
|
119
|
+
<layout suffix=".">
|
|
120
|
+
<text macro="contributors" suffix=". "/>
|
|
121
|
+
<text macro="date" suffix=". "/>
|
|
122
|
+
<text macro="title"/>
|
|
123
|
+
</layout>
|
|
124
|
+
</bibliography>
|
|
125
|
+
</style>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<?oxygen RNGSchema="http://xbiblio.svn.sourceforge.net/viewvc/*checkout*/xbiblio/csl/schema/trunk/csl.rnc" type="compact"?>
|
|
3
|
+
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" xml:lang="en">
|
|
4
|
+
<info>
|
|
5
|
+
<title>American Psychological Association</title>
|
|
6
|
+
<id>http://www.zotero.org/styles/apa</id>
|
|
7
|
+
<link href="http://www.zotero.org/styles/apa"/>
|
|
8
|
+
<author>
|
|
9
|
+
<name>Simon Kornblith</name>
|
|
10
|
+
<email>simon@simonster.com</email>
|
|
11
|
+
</author>
|
|
12
|
+
<contributor>
|
|
13
|
+
<name>Bruce D'Arcus</name>
|
|
14
|
+
</contributor>
|
|
15
|
+
<category term="psychology"/>
|
|
16
|
+
<category term="generic-base"/>
|
|
17
|
+
<category term="author-date"/>
|
|
18
|
+
<updated>2008-05-07T12:08:52+00:00</updated>
|
|
19
|
+
</info>
|
|
20
|
+
<macro name="container-contributors">
|
|
21
|
+
<text term="in" text-case="capitalize-first" suffix=" "/>
|
|
22
|
+
<choose>
|
|
23
|
+
<if type="chapter">
|
|
24
|
+
<names variable="editor translator" delimiter=", " suffix=", ">
|
|
25
|
+
<name and="symbol" initialize-with=". " delimiter=", "/>
|
|
26
|
+
<label form="short" prefix=" (" text-case="capitalize-first" suffix=".)"/>
|
|
27
|
+
</names>
|
|
28
|
+
</if>
|
|
29
|
+
</choose>
|
|
30
|
+
</macro>
|
|
31
|
+
<citation>
|
|
32
|
+
<layout suffix=".">
|
|
33
|
+
</layout>
|
|
34
|
+
</citation>
|
|
35
|
+
<bibliography>
|
|
36
|
+
<layout suffix=".">
|
|
37
|
+
<text macro="container-contributors"/>
|
|
38
|
+
</layout>
|
|
39
|
+
</bibliography>
|
|
40
|
+
</style>
|
data/test/test_all.rb
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
#$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib") if __FILE__ == $0
|
|
4
|
+
|
|
5
|
+
#require 'test/test_sample_bibo'
|
|
6
|
+
|
|
7
|
+
puts "Checking for test cases:"
|
|
8
|
+
Dir['test/test_*.rb'].each do |testcase|
|
|
9
|
+
unless testcase == __FILE__
|
|
10
|
+
puts "\t#{testcase}"
|
|
11
|
+
require testcase
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
puts " "
|
data/test/test_bibo.rb
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require 'citeproc'
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class TestBibo < Test::Unit::TestCase
|
|
9
|
+
# Sets up a document with a range of relational and literal properties
|
|
10
|
+
def setup
|
|
11
|
+
@model = Bibo::BiboUtils::from_rdf('file:test/fixtures/bibo_test_data.n3', 'turtle')
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Test the basic document properties
|
|
16
|
+
def test_model
|
|
17
|
+
assert_not_nil(@model)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
data/test/test_csl.rb
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require 'citeproc'
|
|
6
|
+
|
|
7
|
+
class TestCsl < Test::Unit::TestCase
|
|
8
|
+
FIXTURES = { :csl_json => 'test/fixtures/csl_test_data.json' }
|
|
9
|
+
|
|
10
|
+
def get_csl(path)
|
|
11
|
+
styles = {}
|
|
12
|
+
Dir[path + '/*.csl'].each do |f|
|
|
13
|
+
styles[f.match(/test_(.*)\.csl/)[1].to_sym] = Citeproc::CslParser.new(f).style
|
|
14
|
+
end
|
|
15
|
+
styles
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def setup
|
|
20
|
+
@styles = get_csl('test/fixtures/styles')
|
|
21
|
+
@locales = get_csl('test/fixtures/locales')
|
|
22
|
+
@input_filter = CSL::CslInputFilter.new
|
|
23
|
+
@input_filter.parse(FIXTURES[:csl_json], { :content_type => 'json' })
|
|
24
|
+
@processor = Citeproc::CslProcessor.new
|
|
25
|
+
@formatter = Citeproc::BaseFormatter.new
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_sort
|
|
30
|
+
sort_style = @styles[:sort]
|
|
31
|
+
@processor.init_process(@input_filter, sort_style, @locales[:locale_en])
|
|
32
|
+
citations = @input_filter.citations.values
|
|
33
|
+
keyset = @processor.generate_sort_keys(sort_style.bibliography)
|
|
34
|
+
sorted_citations = @input_filter.sorted_citations(keyset)
|
|
35
|
+
|
|
36
|
+
#puts citations.collect {|c| c.authors.collect {|a| a.name} if c.authors }
|
|
37
|
+
#puts sorted_citations.collect {|c| c.authors.collect {|a| a.name} if c.authors }
|
|
38
|
+
assert(citations[4] == sorted_citations[1])
|
|
39
|
+
assert(citations[1] == sorted_citations[2])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_name_sort
|
|
43
|
+
sort_style = @styles[:sort]
|
|
44
|
+
@processor.init_process(@input_filter, sort_style, @locales[:locale_en])
|
|
45
|
+
citations = @input_filter.citations.values
|
|
46
|
+
|
|
47
|
+
second_citation = citations[2]
|
|
48
|
+
unsorted = second_citation.contributors("author")
|
|
49
|
+
sorted_by_first = second_citation.contributors("author", "first")
|
|
50
|
+
sorted_by_all = second_citation.contributors("author", "all")
|
|
51
|
+
|
|
52
|
+
assert(unsorted[0] == sorted_by_first[0])
|
|
53
|
+
assert(unsorted[0] == sorted_by_all[1])
|
|
54
|
+
assert(unsorted[1] == sorted_by_first[1])
|
|
55
|
+
assert(unsorted[1] == sorted_by_all[0])
|
|
56
|
+
assert(unsorted[2] == sorted_by_first[2])
|
|
57
|
+
assert(unsorted[2] == sorted_by_all[2])
|
|
58
|
+
assert(unsorted[3] == sorted_by_first[3])
|
|
59
|
+
assert(unsorted[3] == sorted_by_all[3])
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_names
|
|
64
|
+
# Tests with AMA-style names
|
|
65
|
+
names_style = @styles[:names]
|
|
66
|
+
nodes = @processor.process_bibliography(@input_filter, names_style, @locales[:locale_en])
|
|
67
|
+
results = @formatter.format(nodes)
|
|
68
|
+
puts
|
|
69
|
+
puts "Testing name values:"
|
|
70
|
+
puts results
|
|
71
|
+
lines = results.split("\n")
|
|
72
|
+
assert(lines[0].strip.empty?)
|
|
73
|
+
|
|
74
|
+
# Assert full stop
|
|
75
|
+
assert(lines[1][lines[1].length - 1..lines[1].length - 1] == '.')
|
|
76
|
+
assert(lines[2][lines[2].length - 1..lines[2].length - 1] == '.')
|
|
77
|
+
assert(lines[3][lines[3].length - 1..lines[3].length - 1] == '.')
|
|
78
|
+
assert(lines[4][lines[4].length - 1..lines[4].length - 1] == '.')
|
|
79
|
+
|
|
80
|
+
# Assert spaces
|
|
81
|
+
assert(lines[1].split.length == 2)
|
|
82
|
+
assert(lines[2].split.length == 8)
|
|
83
|
+
|
|
84
|
+
# Assert values
|
|
85
|
+
assert(lines[1] == "Doniger W.")
|
|
86
|
+
assert(lines[2] == "Gagnon JH, Laumann EO, Michael RT, Michaels S.")
|
|
87
|
+
assert(lines[3] == "Smith JM.")
|
|
88
|
+
assert(lines[4] == "Doe J, Smith J.")
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# Assert spaces
|
|
92
|
+
#puts lines[1]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_group
|
|
97
|
+
groups_style = @styles[:groups]
|
|
98
|
+
nodes = @processor.process_bibliography(@input_filter, groups_style, @locales[:locale_en])
|
|
99
|
+
|
|
100
|
+
# Get the first node
|
|
101
|
+
first_node = nodes[0]
|
|
102
|
+
|
|
103
|
+
# Get the first group node
|
|
104
|
+
group_node = first_node.children[0]
|
|
105
|
+
results = @formatter.format(group_node)
|
|
106
|
+
assert(results.empty?)
|
|
107
|
+
|
|
108
|
+
group_node = first_node.children[1]
|
|
109
|
+
results = @formatter.format(group_node)
|
|
110
|
+
assert_equal("The words 'Some Title' appear in the citation.", results)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def test_macro_expansion
|
|
114
|
+
assert(true)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_labels
|
|
119
|
+
assert(true)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_substitutions
|
|
124
|
+
assert(true)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_grouping
|
|
129
|
+
assert(true)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_formatting
|
|
134
|
+
assert(true)
|
|
135
|
+
end
|
|
136
|
+
end
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
#! /usr/bin/env ruby
|
|
2
|
+
$:.unshift File.join(File.dirname(__FILE__),'..','lib')
|
|
3
|
+
|
|
4
|
+
require 'test/unit'
|
|
5
|
+
require 'citeproc'
|
|
6
|
+
|
|
7
|
+
class TestCslParser < Test::Unit::TestCase
|
|
8
|
+
def stub_csl_files
|
|
9
|
+
[
|
|
10
|
+
"test/fixtures/styles/test_csl_parse.csl"
|
|
11
|
+
]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def stub_locale_files
|
|
15
|
+
[
|
|
16
|
+
"test/fixtures/locales/test_locale_en.xml"
|
|
17
|
+
]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def setup
|
|
22
|
+
@csl_style = Citeproc::CslParser.new(stub_csl_files[0]).style
|
|
23
|
+
@terms = Citeproc::CslParser.new(stub_locale_files[0]).style
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Tests the core Style object
|
|
27
|
+
def test_style
|
|
28
|
+
assert_not_nil(@csl_style)
|
|
29
|
+
assert_equal(@csl_style.lang, "en")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Tests the Info object
|
|
33
|
+
def test_info
|
|
34
|
+
assert_not_nil(@csl_style.info)
|
|
35
|
+
assert_not_nil(@csl_style.info.id)
|
|
36
|
+
assert_not_nil(@csl_style.info.authors)
|
|
37
|
+
|
|
38
|
+
assert_equal "American Psychological Association", @csl_style.info.title.text
|
|
39
|
+
assert_equal "http://www.zotero.org/styles/apa", @csl_style.info.id
|
|
40
|
+
assert_equal "http://www.zotero.org/styles/apa", @csl_style.info.links[0].to_s
|
|
41
|
+
|
|
42
|
+
assert_equal "Simon Kornblith", @csl_style.info.authors[0].name
|
|
43
|
+
assert_equal "simon@simonster.com", @csl_style.info.authors[0].email
|
|
44
|
+
assert_equal "psychology", @csl_style.info.categories[0].term
|
|
45
|
+
assert_equal "generic-base", @csl_style.info.categories[1].term
|
|
46
|
+
assert_equal "author-date", @csl_style.info.categories[2].term
|
|
47
|
+
|
|
48
|
+
assert_kind_of Time, @csl_style.info.updated
|
|
49
|
+
# Need to convert date formats prior to comparison
|
|
50
|
+
#assert_equal @csl_style.info.updated.to_s, "2007-09-06T06:36:07+00:00"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Tests the Macros object
|
|
54
|
+
def test_macros
|
|
55
|
+
assert_not_nil(@csl_style.macros)
|
|
56
|
+
assert_equal(13, @csl_style.macros.size)
|
|
57
|
+
|
|
58
|
+
# First macro
|
|
59
|
+
assert_equal("container-contributors", @csl_style.macros[0].name)
|
|
60
|
+
# assert_equal("(", @csl_style.macros[0].names[0].prefix)
|
|
61
|
+
# assert_equal(")", @csl_style.macros[0].names[0].suffix)
|
|
62
|
+
# assert_equal(", ", @csl_style.macros[0].names[0].delimiter)
|
|
63
|
+
# assert_equal("symbol", @csl_style.macros[0].names[0].name.and)
|
|
64
|
+
# assert_equal(". ", @csl_style.macros[0].names[0].name.initialize_with)
|
|
65
|
+
# assert_equal(", ", @csl_style.macros[0].names[0].name.delimiter)
|
|
66
|
+
# assert_equal("short", @csl_style.macros[0].names[0].labels[0].form)
|
|
67
|
+
# assert_equal(", ", @csl_style.macros[0].names[0].labels[0].prefix)
|
|
68
|
+
# assert_equal("capitalize", @csl_style.macros[0].names[0].labels[0].text_transform)
|
|
69
|
+
# assert_equal(".", @csl_style.macros[0].names[0].labels[0].suffix)
|
|
70
|
+
#
|
|
71
|
+
# # Second macro
|
|
72
|
+
# assert_equal("author", @csl_style.macros[1].name)
|
|
73
|
+
# assert_equal("author", @csl_style.macros[1].names[0].variable)
|
|
74
|
+
# assert_equal("all", @csl_style.macros[1].names[0].name.name_as_sort_order)
|
|
75
|
+
# assert_equal("symbol", @csl_style.macros[1].names[0].name.and)
|
|
76
|
+
# assert_equal(", ", @csl_style.macros[1].names[0].name.sort_separator)
|
|
77
|
+
# assert_equal(". ", @csl_style.macros[1].names[0].name.initialize_with)
|
|
78
|
+
# assert_equal(", ", @csl_style.macros[1].names[0].name.delimiter)
|
|
79
|
+
# assert_equal("always", @csl_style.macros[1].names[0].name.delimiter_precedes_last)
|
|
80
|
+
#
|
|
81
|
+
# assert_equal("short", @csl_style.macros[1].names[0].labels[0].form)
|
|
82
|
+
# assert_equal(" (", @csl_style.macros[1].names[0].labels[0].prefix)
|
|
83
|
+
# assert_equal(".)", @csl_style.macros[1].names[0].labels[0].suffix)
|
|
84
|
+
# assert_equal("capitalize", @csl_style.macros[1].names[0].labels[0].text_transform)
|
|
85
|
+
#
|
|
86
|
+
# assert_equal("editor", @csl_style.macros[1].names[0].substitute.names[0].variable)
|
|
87
|
+
# assert_equal("translator", @csl_style.macros[1].names[0].substitute.names[1].variable)
|
|
88
|
+
# assert_equal("title", @csl_style.macros[1].names[0].substitute.texts[0].macro)
|
|
89
|
+
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Tests the Citation object
|
|
93
|
+
def test_citation
|
|
94
|
+
assert_not_nil(@csl_style.citation)
|
|
95
|
+
assert_not_nil(@csl_style.citation.options)
|
|
96
|
+
assert_not_nil(@csl_style.citation.sort)
|
|
97
|
+
assert_not_nil(@csl_style.citation.layout)
|
|
98
|
+
|
|
99
|
+
# Test the options
|
|
100
|
+
assert_equal "6", @csl_style.citation.option("et-al-min")
|
|
101
|
+
assert_equal "6", @csl_style.citation.et_al_min
|
|
102
|
+
assert_equal "1", @csl_style.citation.et_al_use_first
|
|
103
|
+
assert_equal "3", @csl_style.citation.et_al_subsequent_min
|
|
104
|
+
assert_equal "1", @csl_style.citation.et_al_subsequent_use_first
|
|
105
|
+
assert_equal "true", @csl_style.citation.disambiguate_add_year_suffix
|
|
106
|
+
assert_equal "true", @csl_style.citation.disambiguate_add_names
|
|
107
|
+
assert_equal "true", @csl_style.citation.disambiguate_add_givenname
|
|
108
|
+
assert_equal "year", @csl_style.citation.collapse
|
|
109
|
+
|
|
110
|
+
# Test the sort keys
|
|
111
|
+
# assert_equal "macro", @csl_style.citation.sort_options[0].type
|
|
112
|
+
# assert_equal "author", @csl_style.citation.sort_options[0].value
|
|
113
|
+
# assert_equal "variable", @csl_style.citation.sort_options[1].type
|
|
114
|
+
# assert_equal "issued", @csl_style.citation.sort_options[1].value
|
|
115
|
+
|
|
116
|
+
# Test the layout attributes
|
|
117
|
+
assert_equal "(", @csl_style.citation.layout.prefix
|
|
118
|
+
assert_equal ")", @csl_style.citation.layout.suffix
|
|
119
|
+
assert_equal "; ", @csl_style.citation.layout.delimiter
|
|
120
|
+
|
|
121
|
+
# Test the layout object graph
|
|
122
|
+
assert_equal ", ", @csl_style.citation.layout.groups[0].delimiter
|
|
123
|
+
assert_not_nil @csl_style.citation.layout.groups[0].texts[0]
|
|
124
|
+
|
|
125
|
+
assert_kind_of Citeproc::MacroText, @csl_style.citation.layout.groups[0].texts[0]
|
|
126
|
+
assert_equal "author-short", @csl_style.citation.layout.groups[0].texts[0].macro
|
|
127
|
+
assert_equal "author-short", @csl_style.citation.layout.groups[0].texts[0].value
|
|
128
|
+
|
|
129
|
+
# No longer here?
|
|
130
|
+
# assert_kind_of Citeproc::Date, @csl_style.citation.layout.groups[0].dates[0]
|
|
131
|
+
# assert_equal "issued", @csl_style.citation.layout.groups[0].dates[0].variable
|
|
132
|
+
# assert_equal "issued", @csl_style.citation.layout.groups[0].dates[0].value
|
|
133
|
+
# assert_equal "year", @csl_style.citation.layout.groups[0].dates[0].dateparts[0].name
|
|
134
|
+
|
|
135
|
+
# assert_not_nil @csl_style.citation.layout.groups[0].groups[0].labels[0]
|
|
136
|
+
# assert_equal "locator", @csl_style.citation.layout.groups[0].groups[0].labels[0].variable
|
|
137
|
+
# assert_equal "true", @csl_style.citation.layout.groups[0].groups[0].labels[0].include_period
|
|
138
|
+
# assert_equal "short", @csl_style.citation.layout.groups[0].groups[0].labels[0].form
|
|
139
|
+
|
|
140
|
+
# assert_not_nil @csl_style.citation.layout.groups[0].groups[0].texts[0]
|
|
141
|
+
# assert_kind_of Citeproc::VariableText, @csl_style.citation.layout.groups[0].groups[0].texts[0]
|
|
142
|
+
# assert_equal "locator", @csl_style.citation.layout.groups[0].groups[0].texts[0].variable
|
|
143
|
+
# assert_equal " ", @csl_style.citation.layout.groups[0].groups[0].texts[0].prefix
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Tests the Bibliography object
|
|
147
|
+
def test_bibliography
|
|
148
|
+
assert_not_nil(@csl_style.bibliography)
|
|
149
|
+
assert_not_nil(@csl_style.bibliography.options)
|
|
150
|
+
assert_not_nil(@csl_style.bibliography.sort)
|
|
151
|
+
assert_not_nil(@csl_style.bibliography.layout)
|
|
152
|
+
assert_not_nil(@csl_style.bibliography.layout.conditionals)
|
|
153
|
+
|
|
154
|
+
# Test one of the options
|
|
155
|
+
assert_equal "true", @csl_style.bibliography.option("hanging-indent")
|
|
156
|
+
assert_equal "true", @csl_style.bibliography.hanging_indent
|
|
157
|
+
assert_equal "6", @csl_style.bibliography.et_al_min
|
|
158
|
+
assert_equal "6", @csl_style.bibliography.et_al_use_first
|
|
159
|
+
|
|
160
|
+
# Test the sort keys
|
|
161
|
+
# assert_equal "macro", @csl_style.bibliography.sort_options[0].type
|
|
162
|
+
# assert_equal "author", @csl_style.bibliography.sort_options[0].value
|
|
163
|
+
# assert_equal "variable", @csl_style.bibliography.sort_options[1].type
|
|
164
|
+
# assert_equal "issued", @csl_style.bibliography.sort_options[1].value
|
|
165
|
+
|
|
166
|
+
# Test the layout object graph
|
|
167
|
+
assert_kind_of Citeproc::MacroText, @csl_style.bibliography.layout.texts[0]
|
|
168
|
+
assert_equal "author", @csl_style.bibliography.layout.texts[0].value
|
|
169
|
+
assert_equal ".", @csl_style.bibliography.layout.texts[0].suffix
|
|
170
|
+
|
|
171
|
+
# Dates no longer here?
|
|
172
|
+
# assert_kind_of Citeproc::Date, @csl_style.bibliography.layout.dates[0]
|
|
173
|
+
# assert_equal "issued", @csl_style.bibliography.layout.dates[0].value
|
|
174
|
+
# assert_equal " (", @csl_style.bibliography.layout.dates[0].prefix
|
|
175
|
+
# assert_equal ").", @csl_style.bibliography.layout.dates[0].suffix
|
|
176
|
+
# assert_equal "year", @csl_style.bibliography.layout.dates[0].dateparts[0].name
|
|
177
|
+
|
|
178
|
+
# if
|
|
179
|
+
# assert_equal "book", @csl_style.bibliography.layout.conditionals[0].conditions[0].type
|
|
180
|
+
# assert_equal ".", @csl_style.bibliography.layout.conditionals[0].conditions[0].groups[0].suffix
|
|
181
|
+
# assert_equal "title", @csl_style.bibliography.layout.conditionals[0].conditions[0].groups[0].texts[0].macro
|
|
182
|
+
# assert_equal " ", @csl_style.bibliography.layout.conditionals[0].conditions[0].groups[0].texts[0].prefix
|
|
183
|
+
# assert_equal "editor-translator", @csl_style.bibliography.layout.conditionals[0].conditions[0].groups[0].texts[1].macro
|
|
184
|
+
# assert_equal " ", @csl_style.bibliography.layout.conditionals[0].conditions[0].groups[0].texts[1].prefix
|
|
185
|
+
# assert_equal " ", @csl_style.bibliography.layout.conditionals[0].conditions[0].texts[0].prefix
|
|
186
|
+
# assert_equal ".", @csl_style.bibliography.layout.conditionals[0].conditions[0].texts[0].suffix
|
|
187
|
+
# assert_equal "publisher", @csl_style.bibliography.layout.conditionals[0].conditions[0].texts[0].macro
|
|
188
|
+
|
|
189
|
+
# else-if
|
|
190
|
+
# assert_equal "chapter", @csl_style.bibliography.layout.conditionals[0].conditions[1].type
|
|
191
|
+
# assert_equal "title", @csl_style.bibliography.layout.conditionals[0].conditions[1].texts[0].macro
|
|
192
|
+
# assert_equal " ", @csl_style.bibliography.layout.conditionals[0].conditions[1].texts[0].prefix
|
|
193
|
+
# assert_equal "container", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].class_name
|
|
194
|
+
# assert_equal "in", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].texts[0].term
|
|
195
|
+
# assert_equal "capitalize", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].texts[0].text_transform
|
|
196
|
+
# assert_nil @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].prefix
|
|
197
|
+
# assert_equal ", ", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].delimiter
|
|
198
|
+
# assert_equal ".", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].suffix
|
|
199
|
+
# assert_equal "editor translator", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].names[0].variable
|
|
200
|
+
# assert_equal " ", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].names[0].prefix
|
|
201
|
+
# assert_equal ", ", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].names[0].delimiter
|
|
202
|
+
# assert_equal "symbol", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].names[0].name.and
|
|
203
|
+
# assert_equal ", ", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].names[0].name.sort_separator
|
|
204
|
+
# assert_equal ". ", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].names[0].name.initialize_with
|
|
205
|
+
# assert_equal " ", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].groups[0].groups[0].delimiter
|
|
206
|
+
|
|
207
|
+
# else
|
|
208
|
+
# assert_equal ". ", @csl_style.bibliography.layout.conditionals[0].conditions[1].groups[0].prefix
|
|
209
|
+
# assert_equal ".", @csl_style.bibliography.layout.conditionals[0].conditions[2].groups[0].suffix
|
|
210
|
+
# assert_equal "container", @csl_style.bibliography.layout.conditionals[0].conditions[2].groups[1].class_name
|
|
211
|
+
# assert_equal " ", @csl_style.bibliography.layout.conditionals[0].conditions[2].groups[1].prefix
|
|
212
|
+
# assert_equal ".", @csl_style.bibliography.layout.conditionals[0].conditions[2].groups[1].suffix
|
|
213
|
+
|
|
214
|
+
# Check element order
|
|
215
|
+
assert_kind_of Citeproc::MacroText, @csl_style.bibliography.layout.elements[0]
|
|
216
|
+
assert_kind_of Citeproc::MacroText, @csl_style.bibliography.layout.elements[1]
|
|
217
|
+
assert_kind_of Citeproc::MacroText, @csl_style.bibliography.layout.elements[2]
|
|
218
|
+
assert_kind_of Citeproc::MacroText, @csl_style.bibliography.layout.elements[3]
|
|
219
|
+
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
end
|