zotero / citeproc-js-server

Web service to generate citations and bibliographies using citeproc-js
Other
60 stars 39 forks source link

What is the best way to load this as a library? #16

Closed yinso closed 9 years ago

yinso commented 9 years ago

Looking for something like...

var citeproc = require('citeproc');
citeproc.init({config...});
citeproc.generate({data....});
....

Also, looks like this is not published to NPM. Would be nice to be able to do

npm install citeproc
fcheslack commented 9 years ago

There's not really one, unfortunately. Most of the pieces are there, but citeproc-node itself is not supposed to be a library. All the pieces to use citeproc.js in node/iojs are there in /lib (in module form) but there's not a convenient api for using them together. That's still something I should do at some point, but it doesn't exist yet.

rmzelle commented 9 years ago

There is some related discussion at https://bitbucket.org/fbennett/citeproc-js/issue/120/create-npm-package-for-nodejs (I guess)

michaelmcmillan commented 9 years ago

I'm going to yank out the core of this repo to create a working npm package. I really appreciate the effort the authors has put in to bring citeproc to node, but I don't understand why this is so tightly coupled to an HTTP server. It just seems so ... unnecessary :unamused:

michaelmcmillan commented 9 years ago

It's done. @yinso check out https://github.com/michaelmcmillan/citeproc-node-iojs Check out test/test.js to see how it works.

yinso commented 9 years ago

@michaelmcmillan - awesome - I will check it out once I have some available time, thanks!

fcheslack commented 9 years ago

citeproc-node is tied very closely to the server because that's what it's for. Citeproc-js is already a utility, which could be loaded into node with only very minimal changes (which I included in the copy citeproc-node uses). To get acceptable performance in practice, citeproc-node itself had to do a number of things that are not suited to using citeproc-js as a general purpose library (at least how I would use it).

For a library I don't want to require styles and locales to be on the file system, force async loading, or provide limited functionality based on the subset of citeproc-js functions we use for the Zotero API. With that in mind I created a separate package that takes out some of the long running server optimization things, and just exported everything https://github.com/fcheslack/citeproc-js-node. The readme on there gets you as far as loading an engine with items, locale, and style so you can use it according to Frank's manual http://gsl-nagoya-u.net/http/pub/citeproc-doc.html

It does very little beyond loading a straight bundled citeproc-js file: it includes CSL_JSON and Json_Walker; and the simpleSys object from the readme automatically handles using either pre-converted json or normal xml locales and styles.

michaelmcmillan commented 9 years ago

I appreciate that you to took the time to explain Faolan, but I'm still not any wiser as to why you choose to couple it to an http server. "citeproc-node is tied very closely to the server because that's what it's for" does not really answer the question (-: Even though you can't think of any way to use citeproc-js as a "general purpose library" I'm sure others do. The citeproc-js processing should really be spawned into as a child process mastered by a parent that provides the original API. I'm not claiming it is your responsibility to do so, but in the spirit of open source it sure would be helpful to uncouple it from the http server.

On Tue, Jun 23, 2015 at 7:46 PM, Faolan C-P notifications@github.com wrote:

citeproc-node is tied very closely to the server because that's what it's for. Citeproc-js is already a utility, which could be loaded into node with only very minimal changes (which I included in the copy citeproc-node uses). To get acceptable performance in practice, citeproc-node itself had to do a number of things that are not suited to using citeproc-js as a general purpose library (at least how I would use it).

For a library I don't want to require styles and locales to be on the file system, force async loading, or provide limited functionality based on the subset of citeproc-js functions we use for the Zotero API. With that in mind I created a separate package that takes out some of the long running server optimization things, and just exported everything https://github.com/fcheslack/citeproc-js-node. The readme on there gets you as far as loading an engine with items, locale, and style so you can use it according to Frank's manual http://gsl-nagoya-u.net/http/pub/citeproc-doc.html

It does very little beyond loading a straight bundled citeproc-js file: it includes CSL_JSON and Json_Walker; and the simpleSys object from the readme automatically handles using either pre-converted json or normal xml locales and styles.

— Reply to this email directly or view it on GitHub https://github.com/zotero/citeproc-node/issues/16#issuecomment-114586733 .

fcheslack commented 9 years ago

citeproc-js (https://bitbucket.org/fbennett/citeproc-js/wiki/Home) is a library.

citeproc-node (this repository) is an application. The reason this application exists is to tie the citeproc-js library very closely to an http server. That is not how I think most people should use citeproc-js as a javascript library, which is why I never made citeproc-node trivially usable as a library.