Class: CiteProc::JS::Engine

Inherits:
Engine
  • Object
show all
Defined in:
lib/citeproc/js/engine.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.pathObject (readonly)

Returns the value of attribute path.



16
17
18
# File 'lib/citeproc/js/engine.rb', line 16

def path
  @path
end

Class Method Details

.parserObject



18
19
20
# File 'lib/citeproc/js/engine.rb', line 18

def parser
  ExecJS.runtime.name =~ /rhino|spidermonkey/i ? 'xmle4x.js' : 'xmldom.js'
end

.reloadObject

Forces a reload citeproc-js JavaScript code. Returns the source code.



29
30
31
32
33
# File 'lib/citeproc/js/engine.rb', line 29

def reload
  @source = [
    parser, 'citeproc.js', 'system.js'
  ].map { |s| File.open(File.join(path,s), 'r:UTF-8').read }.join.freeze        
end

.sourceObject

Returns the citeproc-js JavaScript code.



23
24
25
# File 'lib/citeproc/js/engine.rb', line 23

def source
  @source || reload
end

Instance Method Details

#append(citation) ⇒ Object



115
116
117
# File 'lib/citeproc/js/engine.rb', line 115

def append(citation)
  append_citation_cluster(citation.to_citeproc, false)
end

#bibliography(selector = Selector.new) ⇒ Object



111
112
113
# File 'lib/citeproc/js/engine.rb', line 111

def bibliography(selector = Selector.new)
  Bibliography(make_bibliography(selector.to_citeproc))
end

#citation_registryObject



89
90
91
# File 'lib/citeproc/js/engine.rb', line 89

def citation_registry
  @citation_registry ||= Hash.new { |h,k| registry["citationreg.#{k}"] }
end

#itemsObject

The processor’s items converted to citeproc-js format



94
95
96
97
98
# File 'lib/citeproc/js/engine.rb', line 94

def items
  Hash[*processor.items.map { |id, item|
    [id.to_s, item.respond_to?(:to_citeproc) ? item.to_citeproc : item.to_s]
  }.flatten]
end

#localesObject

The locale put into a hash to make citeproc-js happy



101
102
103
# File 'lib/citeproc/js/engine.rb', line 101

def locales
  { locale.name => locale.to_s }
end

#namespace=(namespace) ⇒ Object

Sets the abbreviation’s namespace, both in Ruby and JS land



106
107
108
109
# File 'lib/citeproc/js/engine.rb', line 106

def namespace=(namespace)
  delegate "citeproc.setAbbreviations(#{ namespace.to_s.inspect })"
  @namespace = namespace.to_sym
end

#registryObject



85
86
87
# File 'lib/citeproc/js/engine.rb', line 85

def registry
  @registry ||= Hash.new { |h,k| delegate "citeproc.registry.#{k}" }
end