Skip to content

Commit

Permalink
Add deployments page
Browse files Browse the repository at this point in the history
  • Loading branch information
fbennett committed Mar 7, 2016
1 parent 559d095 commit 3a8da73
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions deployments.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
==================
Deployment example
==================

.. include:: substitutions.txt
|CCBYSA|_ `Frank Bennett <https://twitter.com/fgbjr>`_

|alert|

------------------------

-----------
Hello there
-----------

demo.js
for citeproc-js CSL citation formatter

Get the citations that we are supposed to render, in the CSL-json format

.. code-block:: javascript
var xhr = new XMLHttpRequest();
xhr.open('GET', 'citations.json', false);
xhr.send(null);
var citations = JSON.parse(xhr.responseText);;
Initialize a system object, which contains two methods needed by the
engine.

.. code-block:: javascript
citeprocSys = {
retrieveLocale: function (lang){
var xhr = new XMLHttpRequest();
xhr.open('GET', 'locales-' + lang + '.xml', false);
xhr.send(null);
return xhr.responseText;
},
retrieveItem: function(id){
return citations[id];
}
};
Given a language tag in RFC-4646 form, this method retrieves the
locale definition file. This method must return a valid *serialized*
CSL locale. (In other words, an blob of XML as an unparsed string. The
processor will fail on a native XML object or buffer).

Given an identifier, this retrieves one citation item. This method
must return a valid CSL-JSON object.


Given the identifier of a CSL style, this function instantiates a CSL.Engine
object that can render citations in that style.

.. code-block:: javascript
function getProcessor(styleID) {
// Get the CSL style as a serialized string of XML
var xhr = new XMLHttpRequest();
xhr.open('GET', styleID + '.csl', false);
xhr.send(null);
var styleAsText = xhr.responseText;
// Instantiate and return the engine
var citeproc = new CSL.Engine(citeprocSys, styleAsText);
return citeproc;
};
This runs at document ready, and renders the bibliography

.. code-block:: javascript
function renderBib() {
var bibDivs = document.getElementsByClassName('bib-div');
for (var i = 0, ilen = bibDivs.length; i < ilen; ++i) {
var bibDiv = bibDivs[i];
var citeproc = getProcessor(bibDiv.getAttribute('data-csl'));
var itemIDs = [];
for (var key in citations) {
itemIDs.push(key);
}
citeproc.updateItems(itemIDs);
var bibResult = citeproc.makeBibliography();
bibDiv.innerHTML = bibResult[1].join('\n');
}
}

0 comments on commit 3a8da73

Please sign in to comment.