Class: CiteProc::JS::Engine
- Inherits:
-
Engine
- Object
- Engine
- CiteProc::JS::Engine
- Defined in:
- lib/citeproc/js/engine.rb
Class Attribute Summary collapse
-
.path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .parser ⇒ Object
-
.reload ⇒ Object
Forces a reload citeproc-js JavaScript code.
-
.source ⇒ Object
Returns the citeproc-js JavaScript code.
Instance Method Summary collapse
- #append(citation) ⇒ Object
- #bibliography(selector = Selector.new) ⇒ Object
- #citation_registry ⇒ Object
-
#items ⇒ Object
The processor’s items converted to citeproc-js format.
-
#locales ⇒ Object
The locale put into a hash to make citeproc-js happy.
-
#namespace=(namespace) ⇒ Object
Sets the abbreviation’s namespace, both in Ruby and JS land.
- #registry ⇒ Object
Class Attribute Details
.path ⇒ Object (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
.parser ⇒ Object
18 19 20 |
# File 'lib/citeproc/js/engine.rb', line 18 def parser ExecJS.runtime.name =~ /rhino|spidermonkey/i ? 'xmle4x.js' : 'xmldom.js' end |
.reload ⇒ Object
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 |
.source ⇒ Object
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_registry ⇒ Object
89 90 91 |
# File 'lib/citeproc/js/engine.rb', line 89 def citation_registry @citation_registry ||= Hash.new { |h,k| registry["citationreg.#{k}"] } end |
#items ⇒ Object
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 |
#locales ⇒ Object
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 |
#registry ⇒ Object
85 86 87 |
# File 'lib/citeproc/js/engine.rb', line 85 def registry @registry ||= Hash.new { |h,k| delegate "citeproc.registry.#{k}" } end |