citeproc-ruby 0.0.6 → 1.0.0

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.
Files changed (186) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +1 -0
  3. data/.document +4 -0
  4. data/.gitignore +10 -0
  5. data/.rspec +3 -0
  6. data/.simplecov +4 -0
  7. data/.travis.yml +17 -0
  8. data/.yardopts +2 -0
  9. data/AGPL +662 -0
  10. data/BSDL +29 -0
  11. data/Gemfile +42 -0
  12. data/Guardfile +14 -0
  13. data/README.md +32 -76
  14. data/Rakefile +60 -0
  15. data/citeproc-ruby.gemspec +46 -0
  16. data/cucumber.yml +1 -0
  17. data/features/bibliography.feature +25 -0
  18. data/features/name_options.feature +37 -0
  19. data/features/names.feature +192 -0
  20. data/features/renderer.feature +74 -0
  21. data/features/sort.feature +50 -0
  22. data/features/step_definitions/renderer.rb +80 -0
  23. data/features/support/env.rb +33 -0
  24. data/features/support/hooks.rb +10 -0
  25. data/lib/citeproc/ruby.rb +32 -0
  26. data/lib/citeproc/ruby/engine.rb +122 -0
  27. data/lib/citeproc/ruby/format.rb +303 -0
  28. data/lib/citeproc/ruby/formats/default.rb +25 -0
  29. data/lib/citeproc/ruby/formats/html.rb +221 -0
  30. data/lib/citeproc/ruby/renderer.rb +140 -0
  31. data/lib/citeproc/ruby/renderer/choose.rb +106 -0
  32. data/lib/citeproc/ruby/renderer/date.rb +90 -0
  33. data/lib/citeproc/ruby/renderer/format.rb +129 -0
  34. data/lib/citeproc/ruby/renderer/group.rb +34 -0
  35. data/lib/citeproc/ruby/renderer/history.rb +40 -0
  36. data/lib/citeproc/ruby/renderer/label.rb +66 -0
  37. data/lib/citeproc/ruby/renderer/layout.rb +20 -0
  38. data/lib/citeproc/ruby/renderer/locale.rb +26 -0
  39. data/lib/citeproc/ruby/renderer/macro.rb +20 -0
  40. data/lib/citeproc/ruby/renderer/names.rb +401 -0
  41. data/lib/citeproc/ruby/renderer/number.rb +41 -0
  42. data/lib/citeproc/ruby/renderer/observer.rb +44 -0
  43. data/lib/citeproc/ruby/renderer/state.rb +96 -0
  44. data/lib/citeproc/ruby/renderer/text.rb +62 -0
  45. data/lib/citeproc/ruby/sort.rb +82 -0
  46. data/lib/citeproc/ruby/version.rb +5 -0
  47. data/spec/citeproc/ruby/engine_spec.rb +94 -0
  48. data/spec/citeproc/ruby/formats/default_spec.rb +159 -0
  49. data/spec/citeproc/ruby/formats/html_spec.rb +162 -0
  50. data/spec/citeproc/ruby/renderer/choose_spec.rb +293 -0
  51. data/spec/citeproc/ruby/renderer/date_spec.rb +173 -0
  52. data/spec/citeproc/ruby/renderer/group_spec.rb +88 -0
  53. data/spec/citeproc/ruby/renderer/history_spec.rb +38 -0
  54. data/spec/citeproc/ruby/renderer/label_spec.rb +225 -0
  55. data/spec/citeproc/ruby/renderer/layout_spec.rb +41 -0
  56. data/spec/citeproc/ruby/renderer/macro_spec.rb +31 -0
  57. data/spec/citeproc/ruby/renderer/names_spec.rb +396 -0
  58. data/spec/citeproc/ruby/renderer/number_spec.rb +120 -0
  59. data/spec/citeproc/ruby/renderer/text_spec.rb +120 -0
  60. data/spec/citeproc/ruby/renderer_spec.rb +65 -0
  61. data/spec/fixtures/items.rb +80 -0
  62. data/{resource/locale → spec/fixtures/locales}/locales-en-US.xml +2 -11
  63. data/{resource/locale → spec/fixtures/locales}/locales-fr-FR.xml +77 -66
  64. data/{resource/style → spec/fixtures/styles}/apa.csl +5 -5
  65. data/spec/spec_helper.rb +67 -14
  66. metadata +121 -211
  67. data/lib/citeproc.rb +0 -100
  68. data/lib/citeproc/bibliography.rb +0 -57
  69. data/lib/citeproc/data.rb +0 -149
  70. data/lib/citeproc/date.rb +0 -133
  71. data/lib/citeproc/formatter.rb +0 -38
  72. data/lib/citeproc/item.rb +0 -53
  73. data/lib/citeproc/name.rb +0 -284
  74. data/lib/citeproc/processor.rb +0 -166
  75. data/lib/citeproc/selector.rb +0 -61
  76. data/lib/citeproc/variable.rb +0 -82
  77. data/lib/citeproc/version.rb +0 -3
  78. data/lib/csl/locale.rb +0 -223
  79. data/lib/csl/node.rb +0 -72
  80. data/lib/csl/nodes.rb +0 -1418
  81. data/lib/csl/renderer.rb +0 -88
  82. data/lib/csl/sort.rb +0 -61
  83. data/lib/csl/style.rb +0 -110
  84. data/lib/csl/term.rb +0 -124
  85. data/lib/extensions/core.rb +0 -43
  86. data/lib/plugins/filters/bibtex.rb +0 -12
  87. data/lib/plugins/formats/default.rb +0 -134
  88. data/lib/plugins/formats/html.rb +0 -67
  89. data/lib/support/attributes.rb +0 -99
  90. data/lib/support/compatibility.rb +0 -83
  91. data/lib/support/tree.rb +0 -80
  92. data/resource/locale/locales-af-ZA.xml +0 -305
  93. data/resource/locale/locales-ar-AR.xml +0 -306
  94. data/resource/locale/locales-bg-BG.xml +0 -305
  95. data/resource/locale/locales-ca-AD.xml +0 -305
  96. data/resource/locale/locales-cs-CZ.xml +0 -305
  97. data/resource/locale/locales-da-DK.xml +0 -305
  98. data/resource/locale/locales-de-AT.xml +0 -304
  99. data/resource/locale/locales-de-CH.xml +0 -304
  100. data/resource/locale/locales-de-DE.xml +0 -332
  101. data/resource/locale/locales-el-GR.xml +0 -305
  102. data/resource/locale/locales-en-GB.xml +0 -304
  103. data/resource/locale/locales-es-ES.xml +0 -305
  104. data/resource/locale/locales-et-EE.xml +0 -304
  105. data/resource/locale/locales-eu.xml +0 -305
  106. data/resource/locale/locales-fa-IR.xml +0 -304
  107. data/resource/locale/locales-fi-FI.xml +0 -304
  108. data/resource/locale/locales-fr-CA.xml +0 -306
  109. data/resource/locale/locales-he-IL.xml +0 -304
  110. data/resource/locale/locales-hu-HU.xml +0 -305
  111. data/resource/locale/locales-is-IS.xml +0 -304
  112. data/resource/locale/locales-it-IT.xml +0 -305
  113. data/resource/locale/locales-ja-JP.xml +0 -305
  114. data/resource/locale/locales-kh-KH.xml +0 -303
  115. data/resource/locale/locales-km-KH.xml +0 -304
  116. data/resource/locale/locales-ko-KR.xml +0 -305
  117. data/resource/locale/locales-mn-MN.xml +0 -306
  118. data/resource/locale/locales-nb-NO.xml +0 -304
  119. data/resource/locale/locales-nl-NL.xml +0 -304
  120. data/resource/locale/locales-nn-NO.xml +0 -304
  121. data/resource/locale/locales-pl-PL.xml +0 -305
  122. data/resource/locale/locales-pt-BR.xml +0 -304
  123. data/resource/locale/locales-pt-PT.xml +0 -305
  124. data/resource/locale/locales-ro-RO.xml +0 -305
  125. data/resource/locale/locales-ru-RU.xml +0 -306
  126. data/resource/locale/locales-sk-SK.xml +0 -304
  127. data/resource/locale/locales-sl-SI.xml +0 -305
  128. data/resource/locale/locales-sr-RS.xml +0 -305
  129. data/resource/locale/locales-sv-SE.xml +0 -305
  130. data/resource/locale/locales-th-TH.xml +0 -304
  131. data/resource/locale/locales-tr-TR.xml +0 -305
  132. data/resource/locale/locales-uk-UA.xml +0 -306
  133. data/resource/locale/locales-vi-VN.xml +0 -305
  134. data/resource/locale/locales-zh-CN.xml +0 -304
  135. data/resource/locale/locales-zh-TW.xml +0 -305
  136. data/resource/schema/csl-categories.rnc +0 -39
  137. data/resource/schema/csl-data.rnc +0 -98
  138. data/resource/schema/csl-terms.rnc +0 -106
  139. data/resource/schema/csl-types.rnc +0 -39
  140. data/resource/schema/csl-variables.rnc +0 -182
  141. data/resource/schema/csl.rnc +0 -941
  142. data/resource/style/bibtex.csl +0 -177
  143. data/resource/style/chicago-annotated-bibliography.csl +0 -513
  144. data/resource/style/chicago-author-date-basque.csl +0 -707
  145. data/resource/style/chicago-author-date-de.csl +0 -394
  146. data/resource/style/chicago-author-date-listing.csl +0 -434
  147. data/resource/style/chicago-author-date.csl +0 -425
  148. data/resource/style/chicago-dated-note-biblio-no-ibid.csl +0 -472
  149. data/resource/style/chicago-fullnote-bibliography-bb.csl +0 -928
  150. data/resource/style/chicago-fullnote-bibliography-delimiter-fixes.csl +0 -972
  151. data/resource/style/chicago-fullnote-bibliography-no-ibid-delimiter-fixes.csl +0 -963
  152. data/resource/style/chicago-fullnote-bibliography-no-ibid.csl +0 -785
  153. data/resource/style/chicago-fullnote-bibliography.csl +0 -803
  154. data/resource/style/chicago-library-list.csl +0 -511
  155. data/resource/style/chicago-note-biblio-no-ibid.csl +0 -514
  156. data/resource/style/chicago-note-bibliography.csl +0 -530
  157. data/resource/style/chicago-note.csl +0 -388
  158. data/resource/style/chicago-quick-copy.csl +0 -685
  159. data/resource/style/ieee.csl +0 -299
  160. data/resource/style/mla-notes.csl +0 -796
  161. data/resource/style/mla-underline.csl +0 -175
  162. data/resource/style/mla-url.csl +0 -214
  163. data/resource/style/mla.csl +0 -394
  164. data/resource/style/vancouver-brackets.csl +0 -256
  165. data/resource/style/vancouver-superscript-bracket-only-year.csl +0 -165
  166. data/resource/style/vancouver-superscript.csl +0 -256
  167. data/resource/style/vancouver.csl +0 -256
  168. data/spec/citeproc/bibliography_spec.rb +0 -45
  169. data/spec/citeproc/citeproc_spec.rb +0 -80
  170. data/spec/citeproc/date_spec.rb +0 -89
  171. data/spec/citeproc/formatter_spec.rb +0 -101
  172. data/spec/citeproc/item_spec.rb +0 -71
  173. data/spec/citeproc/name_spec.rb +0 -30
  174. data/spec/citeproc/processor_spec.rb +0 -61
  175. data/spec/citeproc/selector_spec.rb +0 -82
  176. data/spec/citeproc/variable_spec.rb +0 -69
  177. data/spec/csl/locale_spec.rb +0 -208
  178. data/spec/csl/node_spec.rb +0 -25
  179. data/spec/csl/nodes_spec.rb +0 -145
  180. data/spec/csl/style_spec.rb +0 -62
  181. data/spec/csl/term_spec.rb +0 -56
  182. data/spec/fixtures/dates.yaml +0 -80
  183. data/spec/fixtures/names.yaml +0 -115
  184. data/spec/fixtures/nodes.yaml +0 -245
  185. data/spec/support/attributes_spec.rb +0 -39
  186. data/spec/support/tree_spec.rb +0 -163
data/lib/citeproc.rb DELETED
@@ -1,100 +0,0 @@
1
- $:.unshift(File.dirname(__FILE__)) unless
2
- $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
-
4
- $KCODE = 'UTF-8' if RUBY_VERSION < '1.9.0' && $KCODE.nil?
5
-
6
- require 'open-uri'
7
-
8
- require 'logging'
9
- require 'nokogiri'
10
- require 'json'
11
-
12
- module CiteProc
13
-
14
- @log = Logging.logger[self.name]
15
- @log.add_appenders(Logging.appenders.stderr)
16
-
17
- @log.level = ENV.has_key?('DEBUG') ? :debug : :info
18
-
19
- class << self
20
- def log(*args)
21
- return @log if args.empty?
22
-
23
- level, message, exception = args
24
-
25
- @log.send(level, [message, exception && exception.message || nil].compact.join(': '))
26
- @log.debug exception.backtrace[0,10].join("\n\t") unless exception.nil?
27
- end
28
- end
29
-
30
- end
31
-
32
- # Load debugger
33
- # require 'ruby-debug'
34
- # Debugger.start
35
-
36
- require 'extensions/core'
37
- require 'support/attributes'
38
- require 'support/tree'
39
- require 'support/compatibility'
40
-
41
- require 'csl/node'
42
- require 'csl/term'
43
- require 'csl/locale'
44
- require 'csl/nodes'
45
- require 'csl/sort'
46
- require 'csl/renderer'
47
- require 'csl/style'
48
-
49
- require 'citeproc/version'
50
- require 'citeproc/variable'
51
- require 'citeproc/name'
52
- require 'citeproc/date'
53
- require 'citeproc/data'
54
- require 'citeproc/selector'
55
- require 'citeproc/item'
56
- require 'citeproc/bibliography'
57
- require 'citeproc/formatter'
58
- require 'citeproc/processor'
59
-
60
-
61
- require 'plugins/formats/default'
62
-
63
- # Load filter and format plugins
64
- Dir.glob("#{File.expand_path('..', __FILE__)}/plugins/formats/*.rb").each do |format|
65
- require format
66
- end
67
-
68
-
69
- Dir.glob("#{File.expand_path('..', __FILE__)}/plugins/filters/*.rb").each do |format|
70
- require format
71
- end
72
-
73
-
74
- # Top-level CSL utility functions
75
-
76
- module CiteProc
77
-
78
- module_function
79
-
80
- def default_format; Format.default; end
81
-
82
- def process(*arguments, &block); Processor.process(*arguments, &block); end
83
-
84
- end
85
-
86
- module CSL
87
-
88
- module_function
89
-
90
- def default_locale
91
- Locale.new(Locale.default)
92
- end
93
-
94
- def default_style
95
- Style.new(Style.default)
96
- end
97
-
98
- def process(*arguments, &block); CiteProc.process(*arguments, &block); end
99
-
100
- end
@@ -1,57 +0,0 @@
1
- module CiteProc
2
-
3
- # A bibliography is an array of bibliographic entries and, optionally,
4
- # a list of errors. The bibliography should be format agnostic; it is
5
- # simply encapsulates two lists.
6
- class Bibliography
7
-
8
- def initialize(*args)
9
- args.each { |argument| parse_argument(argument) }
10
-
11
- yield self if block_given?
12
- end
13
-
14
- def data; @data ||= []; end
15
- def errors; @errors ||= []; end
16
- def options; @options ||= {}; end
17
-
18
- # @data proxy
19
- [:[], :[]=, :<<, :map, :each, :empty?, :push, :pop, :unshift, :+, :concat].each do |method_id|
20
- define_method method_id do |*args, &block|
21
- @data.send(method_id, *args, &block)
22
- end
23
- end
24
-
25
- def to_json
26
- [options.merge('bibliography-errors' => errors), data].to_json
27
- end
28
-
29
- def to_s
30
- [options['bibstart'] || '<div class="csl-bib-body">', data.map { |d| " <div class=\"csl-entry\">#{d}</div>" }, options['bibend'] || '</div>'].flatten.join("\n")
31
- end
32
-
33
- protected
34
-
35
- def parse_argument(argument)
36
- case
37
- when argument.is_a?(String)
38
- parse_argument(JSON.parse(argument))
39
- when argument.is_a?(Hash)
40
- parse_attributes(argument)
41
- when argument.is_a?(Array) && argument.length == 2 && argument[0].is_a?(Hash) && argument[1].is_a?(Array)
42
- parse_attributes(argument[0])
43
- @data = argument[1]
44
- when argument.is_a?(Array)
45
- @data = argument
46
- else
47
- CiteProc.log.warn "failed to initialize Bibliography from argument #{ argument.inspect }." unless argument.nil?
48
- end
49
- end
50
-
51
- def parse_attributes(attributes)
52
- @errors = attributes.delete('bibliography-errors') || []
53
- @options = {}.merge(attributes)
54
- end
55
-
56
- end
57
- end
data/lib/citeproc/data.rb DELETED
@@ -1,149 +0,0 @@
1
- module CiteProc
2
-
3
-
4
- # == CiteProc::Data
5
- #
6
- # A minimal citation data object, used as input by both the
7
- # processCitationCluster() and appendCitationCluster() command, has the
8
- # following form:
9
- #
10
- # {
11
- # "citationItems": [ { "id": "ITEM-1" } ],
12
- # "properties": {"noteIndex": 1 }
13
- # }
14
- #
15
- # The citationItems array is a list of one or more citation item objects,
16
- # each containing an id used to retrieve the bibliographic details of the
17
- # target resource. A citation item object may contain one or more
18
- # additional optional values:
19
- #
20
- # * locator: a string identifying a page number or other pinpoint location
21
- # or range within the resource;
22
- # * label: a label type, indicating whether the locator is to a page, a
23
- # chapter, or other subdivision of the target resource. Valid labels are
24
- # defined in the link CSL specification.
25
- # * suppress-author: if true, author names will not be included in the
26
- # citation output for this cite;
27
- # * author-only: if true, only the author name will be included in the
28
- # citation output for this cite -- this optional parameter provides a
29
- # means for certain demanding styles that require the processor output
30
- # to be divided between the main text and a footnote.
31
- # * prefix: a string to print before this cite item;
32
- # * suffix: a string to print after this cite item.
33
- #
34
- # In the properties portion of a citation, the noteIndex value indicates
35
- # the footnote number in which the citation is located within the
36
- # document. Citations within the main text of the document have a
37
- # noteIndex of zero.
38
- #
39
- # The processor will add a number of data items to a citation during
40
- # processing. Values added at the top level of the citation structure
41
- # include:
42
- #
43
- # * citationID: A unique ID assigned to the citation, for internal use by
44
- # the processor. This ID may be assigned by the calling application, but
45
- # it must uniquely identify the citation, and it must not be changed
46
- # during processing or during an editing session.
47
- # * sortedItems: This is an array of citation objects and accompanying
48
- # bibliographic data objects, sorted as required by the configured
49
- # style. Calling applications should not need to access the data in this
50
- # array directly.
51
- #
52
- # Values added to individual citation item objects may include:
53
- #
54
- # * sortkeys: an array of sort keys used by the processor to produce the
55
- # sorted list in sortedItems. Calling applications should not need to
56
- # touch this array directly.
57
- # * position: an integer flag that indicates whether the cite item should
58
- # be rendered as a first reference, an immediately-following reference
59
- # (i.e. ibid), an immediately-following reference with locator
60
- # information, or a subsequent reference.
61
- # * first-reference-note-number: the number of the noteIndex of the first
62
- # reference to this resource in the document.
63
- # * near-note: a boolean flag indicating whether another reference to this
64
- # resource can be found within a specific number of notes, counting back
65
- # from the current position. What is "near" in this sense is
66
- # style-dependent.
67
- # * unsorted: a boolean flag indicating whether sorting imposed by the
68
- # style should be suspended for this citation. When true, cites are
69
- # rendered in the order in which they are presented in citationItems.
70
- #
71
- class CitationData
72
- include Support::Attributes
73
-
74
- attr_fields %w{ citation-id citation-items properites sorted-items }
75
-
76
-
77
- def initialize(attributes={})
78
-
79
- self.key_filter = Hash.new do |hash, key|
80
- hash[key] = key.to_s.gsub(/([[:lower:]])([[:upper:]])/, '\1-\2').downcase
81
- end
82
-
83
- merge!(attributes)
84
-
85
- yield self if block_given?
86
- end
87
-
88
- # @returns a list of citation data
89
- def self.parse(argument)
90
- return [] if argument.nil?
91
- argument = [argument] unless argument.kind_of?(Array)
92
- argument.map { |d| CitationData.new(d) }
93
- end
94
-
95
- #
96
- # Merges the argument into the citation data. The argument can be a list
97
- # of citation items (hashes), a single citation item (hash), another
98
- # citation data instance or hash, or a single id of a citation item.
99
- #
100
- def merge!(argument)
101
- case
102
- when argument.is_a?(Array) && argument.map(&:class).uniq == [Hash]
103
- super('citation-items' => argument.map { |argument| Item.new(argument) })
104
-
105
- when argument.is_a?(Array) && (argument.empty? || argument.map(&:class).uniq == [Item])
106
- super('citation-items' => argument)
107
-
108
- when argument.is_a?(Hash)
109
- argument.has_key?('id') ? super('citation-items' => [Item.new(argument)]) : super(argument)
110
-
111
- when argument.is_a?(String) || argument.is_a?(Symbol)
112
- super('citation-items' => [{ 'id' => argument.to_s }])
113
-
114
- when argument.is_a?(CitationData)
115
- super(argument.attributes)
116
-
117
- else
118
- raise(ArgumentError, "unable to merge #{argument.inspect} into citation data")
119
- end
120
- end
121
-
122
- def citation_items
123
- attributes['citation-items'] ||= []
124
- end
125
-
126
- def populate!(items)
127
- citation_items.each { |item| item.reverse_merge!(items[item.id.to_s]) }
128
- self
129
- end
130
-
131
- def properties
132
- self.attributes['properties'] ||= {}
133
- end
134
-
135
- [[:items, :citation_items], [:id, :citation_id]].each do |a, m|
136
- alias_method a, m
137
- alias_method "#{a}=", "#{m}="
138
- alias_method "#{a}?", "#{m}?"
139
- end
140
-
141
- [:each, :map, :empty?, :first, :last, :sort].each do |method_id|
142
- define_method method_id do |*args, &block|
143
- self.items.send(method_id, *args, &block)
144
- end
145
- end
146
-
147
- end
148
-
149
- end
data/lib/citeproc/date.rb DELETED
@@ -1,133 +0,0 @@
1
- require 'date'
2
-
3
- module CiteProc
4
-
5
-
6
- # == Date Variables
7
- #
8
- # Date objects wrap an underlying JavaScript object, within which the
9
- # "date-parts" element is a nested JavaScript array containing a start date
10
- # and optional end date, each of which consists of a year, an optional month
11
- # and an optional day, in that order if present. Additionally, the string
12
- # fields "season", "literal", as well as the boolean field "circa" are
13
- # supported.
14
- #
15
- class Date < Variable
16
-
17
- attr_fields %w{ date-parts season circa literal }
18
-
19
- Variable.date_fields.each { |field| Variable.types[field] = Date }
20
-
21
- [:year, :month, :day].each_with_index do |method_id, index|
22
- define_method method_id do
23
- date_parts[0].nil? ? nil : date_parts[0][index]
24
- end
25
-
26
- define_method [method_id, '='].join do |value|
27
- date_parts[0] = [] if date_parts[0].nil?
28
- date_parts[0][index] = value.to_i
29
- end
30
- end
31
-
32
- def defaults
33
- Hash['delimiter', '-']
34
- end
35
-
36
- def parse!(argument)
37
- return super unless argument.is_a?(::Date) || argument.is_a?(String)
38
- parse_date!(argument)
39
- end
40
-
41
- def merge!(argument)
42
- case
43
- when argument.has_key?('raw')
44
- parse_date!(argument.delete('raw'))
45
- argument.delete('date-parts')
46
- when argument.has_key?('date-parts')
47
- argument['date-parts'].map! { |parts| parts.map(&:to_i) }
48
- end
49
- super
50
- end
51
-
52
- def parse_date!(date)
53
- # TODO find out what the Ruby parser can do
54
- date = ::Date.parse(date) unless date.is_a?(::Date)
55
- date_parts[0] = [date.year, date.month, date.day]
56
- self
57
- end
58
-
59
- def date_parts
60
- attributes['date-parts'] ||= []
61
- end
62
-
63
- alias :parts :date_parts
64
- alias :parts= :date_parts=
65
-
66
- def range?
67
- parts[1] && !parts[1].empty?
68
- end
69
-
70
- def open_range?
71
- self.range? && parts[1].uniq == [0]
72
- end
73
-
74
- def uncertain!; self['circa'] = true; end
75
-
76
- def bc?; year && year < 0; end
77
- def ad?; !bc? && year < 1000; end
78
-
79
- alias :uncertain? :circa?
80
-
81
- def from
82
- parts[0] || []
83
- end
84
-
85
- def to
86
- Date.new('date-parts' => [parts[1] || []])
87
- end
88
-
89
- # @returns a value in 0..3 depending on how many of the date parts in the
90
- # range match.
91
- def range_match
92
- parts[0].zip(parts[1] || []).take_while { |p| p[0] == p[1] }.length
93
- end
94
-
95
- def display_parts
96
- rm = range_match
97
-
98
- case
99
- when !range? || open_range?
100
- [%w{day month year}, []]
101
- when rm == 1
102
- [%w{day month}, %w{day month year} ]
103
- when rm == 2
104
- [%w{day}, %w{day month year} ]
105
- else
106
- [%w{day month year}, %w{day month year} ]
107
- end
108
- end
109
-
110
- def display(options={})
111
- options = defaults.merge(options)
112
- from.compact.join(options['delimiter'])
113
- end
114
-
115
- def to_s
116
- literal || attributes.inspect
117
- end
118
-
119
- def value; self; end
120
-
121
- def numeric?; false; end
122
-
123
- def sort_order
124
- "%04d%02d%02d-%04d%02d%02d" % ((parts[0] + [0,0,0])[0,3] + ((parts[1] || []) + [0,0,0])[0,3])
125
- end
126
-
127
- def <=>(other)
128
- return nil unless other.is_a?(Date)
129
- [year, sort_order] <=> [other.year, other.sort_order]
130
- end
131
- end
132
-
133
- end
@@ -1,38 +0,0 @@
1
- module CiteProc
2
-
3
- module Format
4
- def self.default; CiteProc::Format::Default.new; end
5
- end
6
-
7
- class Formatter
8
-
9
- def format(*args)
10
- @format ||= CiteProc.default_format
11
- args.empty? ? @format : apply(args[0], args[1])
12
- end
13
-
14
- def format=(format)
15
- @format = Format.const_get(format.to_s.split(/[\s_-]+/).map(&:capitalize).join).new
16
- rescue Exception => e
17
- CiteProc.log :warn, "failed to set format to #{ format.inspect }", e
18
- end
19
-
20
- def apply(input='', attributes={})
21
- return input if attributes.nil? || input.nil? || input.empty?
22
-
23
- format.input = input
24
-
25
- CSL::Nodes.formatting_attributes.each do |attribute|
26
- method_id = ['set', attribute.gsub(/-/, '_')].join('_')
27
-
28
- if !attributes[attribute].nil? && format.respond_to?(method_id)
29
- format.send(method_id, attributes[attribute])
30
- end
31
- end
32
-
33
- format.finalize
34
- end
35
-
36
- end
37
-
38
- end