Skip to content

Commit

Permalink
Expose internal libxmljs
Browse files Browse the repository at this point in the history
  • Loading branch information
albanm committed Jan 21, 2015
1 parent a6748f4 commit 19b8e6f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
10 changes: 10 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"node": true,
"undef": true,
"unused": true,
"globals": {
"describe": false,
"it": false,
"before": false
}
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ Libxmljs integration

Node-libxslt depends on [libxmljs](https://github.com/polotek/libxmljs/issues/226) in the same way that [libxslt](http://xmlsoft.org/libxslt/) depends on [libxml](http://xmlsoft.org/). This dependancy makes possible to bundle and to load in memory libxml only once for users of both libraries.

The libxmljs module required by node-libxslt is exposed as ```require('libxslt').libxmljs```. This prevents depending on libxmljs twice which is not optimal and source of weird bugs.

It is possible to work with libxmljs documents instead of strings:

```js
var lixslt = require('libxslt');
var libxmljs = require('libxmljs');
var libxmljs = libxslt.libxmljs;

var stylesheetObj = libxmljs.parseXml(stylesheetString, { nocdata: true });
var stylesheet = libxslt.parse(stylesheetObj);
Expand Down
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ var binding = require('bindings')('node-libxslt');

binding.registerEXSLT();

/**
* The libxmljs module. Prevents the need for a user's code to require it a second time. Also prevent weird bugs.
*/
exports.libxmljs = libxmljs;

/**
* A compiled stylesheet. Do not call this constructor, instead use parse or parseFile.
*
Expand Down
8 changes: 5 additions & 3 deletions readme.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ Libxmljs integration
Node-libxslt depends on [libxmljs](https://github.com/polotek/libxmljs/issues/226) in the same way that [libxslt](http://xmlsoft.org/libxslt/) depends on [libxml](http://xmlsoft.org/). This dependancy makes possible to bundle and to load in memory libxml only once for users of both libraries.
The libxmljs module required by node-libxslt is exposed as ```require('libxslt').libxmljs```. This prevents depending on libxmljs twice which is not optimal and source of weird bugs.
It is possible to work with libxmljs documents instead of strings:
```js
var lixslt = require('libxslt');
var libxmljs = require('libxmljs');
var libxmljs = libxslt.libxmljs;
var stylesheetObj = libxmljs.parseXml(stylesheetString);
var stylesheetObj = libxmljs.parseXml(stylesheetString, { nocdata: true });
var stylesheet = libxslt.parse(stylesheetObj);
var document = libxmljs.parseXml(documentString);
stylesheet.apply(document, function(err, result){
// result is now a libxmljs document containing the result of the transformation
// result is now a libxmljs document containing the result of the transformation
});
```
Expand Down
21 changes: 10 additions & 11 deletions test/libxslt.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
var fs = require('fs');

var should = require('should');
var libxmljs = require("libxmljs");

var libxslt = require('../index');

Expand Down Expand Up @@ -40,8 +39,8 @@ describe('node-libxslt', function() {
var stylesheet;
var stylesheetInclude;
describe('synchronous parse function', function() {
it('should parse a stylesheet from a libxmljs xml document', function() {
var stylesheetDoc = libxmljs.parseXml(stylesheetSource);
it('should parse a stylesheet from a libxslt.libxmljs xml document', function() {
var stylesheetDoc = libxslt.libxmljs.parseXml(stylesheetSource);
stylesheet = libxslt.parse(stylesheetDoc);
stylesheet.should.be.type('object');
});
Expand All @@ -50,7 +49,7 @@ describe('node-libxslt', function() {
stylesheet.should.be.type('object');
});
it('should parse a stylesheet with a include from a xml string', function() {
var stylesheetDoc = libxmljs.parseXml(stylesheetIncludeSource);
var stylesheetDoc = libxslt.libxmljs.parseXml(stylesheetIncludeSource);
stylesheetInclude = libxslt.parse(stylesheetDoc);
stylesheetInclude.should.be.type('object');
});
Expand All @@ -71,8 +70,8 @@ describe('node-libxslt', function() {
});

describe('asynchronous parse function', function() {
it('should parse a stylesheet from a libxmljs xml document', function(callback) {
var stylesheetDoc = libxmljs.parseXml(stylesheetSource);
it('should parse a stylesheet from a libxslt.libxmljs xml document', function(callback) {
var stylesheetDoc = libxslt.libxmljs.parseXml(stylesheetSource);
libxslt.parse(stylesheetDoc, function(err, stylesheet) {
stylesheet.should.be.type('object');
callback(err);
Expand All @@ -85,7 +84,7 @@ describe('node-libxslt', function() {
});
});
it('should parse a stylesheet with a include from a xml string', function(callback) {
var stylesheetDoc = libxmljs.parseXml(stylesheetIncludeSource);
var stylesheetDoc = libxslt.libxmljs.parseXml(stylesheetIncludeSource);
libxslt.parse(stylesheetDoc, function(err, stylesheet) {
stylesheet.should.be.type('object');
callback(err);
Expand All @@ -100,8 +99,8 @@ describe('node-libxslt', function() {
});

describe('synchronous apply function', function() {
it('should apply a stylesheet to a libxmljs xml document', function() {
var doc = libxmljs.parseXml(docSource);
it('should apply a stylesheet to a libxslt.libxmljs xml document', function() {
var doc = libxslt.libxmljs.parseXml(docSource);
var result = stylesheet.apply(doc);
result.should.be.type('object');
result.toString().should.match(/<td>Bob Dylan<\/td>/);
Expand All @@ -128,8 +127,8 @@ describe('node-libxslt', function() {
});

describe('asynchronous apply function', function() {
it('should apply a stylesheet to a libxmljs xml document', function(callback) {
var doc = libxmljs.parseXml(docSource);
it('should apply a stylesheet to a libxslt.libxmljs xml document', function(callback) {
var doc = libxslt.libxmljs.parseXml(docSource);
stylesheet.apply(doc, function(err, result) {
result.should.be.type('object');
result.toString().should.match(/<td>Bob Dylan<\/td>/);
Expand Down

0 comments on commit 19b8e6f

Please sign in to comment.