0.5.0 • Published 9 years ago
angular-jsdom-renderer v0.5.0
Angular JSDom Renderer
Helps render angular pages on the server-side.
Installation
npm install angular-jsdom-renderer
Usage
// render using an interval poll selector
var renderer = require('angular-jsdom-renderer');
renderer.render({
/* url to retrieve the html from */
url: 'http://localhost:7559/',
/* poll this selector until a match is found */
pollSelector: 'body[data-content-loaded=true]',
/* how often to poll the given selector. default 500 */
pollSelectorMs: 100,
/* how long to wait to give up polling selector. default 60000 */
timeoutMs: 60000,
/* complete callback. this = config */
done: function(errors, window) {
if (errors) {
console.log(errors);
return;
}
var document = window.document;
var compiledHtml = document.outerHTML;
// var angular = window.angular
console.log(compiledHtml);
// window will close after this callback
}
});
// render using a timeout only
var renderer = require('angular-jsdom-renderer');
renderer.render({
/* url to retrieve the html from */
url: 'http://localhost:7559/',
/* how long to wait until rendering the content. default 5000 */
timeoutMs: 5000,
/* complete callback. this = config */
done: function(errors, window) {
if (errors) {
console.log(errors);
return;
}
var document = window.document;
var compiledHtml = document.outerHTML;
// var angular = window.angular
console.log(compiledHtml);
// window will close after this callback
}
});
####Run the examples
API
/* renders the give url or file or html string */
render({
/* raw html. optional but must provide either url|file|html */
html: '',
/* raw file. optional but must provide either url|file|html */
file: config.file,
/* raw url. optional but must provide either url|file|html */
url: '',
/* injects script urls in to the html to be rendered */
scripts: [],
/* injects script statements in to the html to be rendered */
src: [],
/* see jsdom for more info - https://github.com/tmpvar/jsdom#how-it-works */
features: config.features,
/* see jsdom for more info - https://github.com/tmpvar/jsdom#doneerrors-window */
done: function(jsdomErrors, window){},
/* polls a selector until a match is found and then passes the rendered html to the config.done callback */
pollSelector: 'body[data-content-loaded=true]'. default '',
/* how often to poll the given selector. default 500 */
pollSelectorMs: 500,
/* how long to wait to give up polling selector. default 60000 */
timeoutMs: 60000,
});
Contributing
Feel free to submit ideas and issues.
License
Licensed under the incredibly permissive MIT License Copyright © 2014+ Stringz Solutions Ltd Copyright © 2014+ Peter Flannery