Skip to content

Commit

Permalink
Change casing of liveReload options
Browse files Browse the repository at this point in the history
  • Loading branch information
dvonlehman committed Feb 4, 2015
1 parent 0c85b92 commit 75f23da
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ High-performant HTML pre-processor designed to execute at runtime rather than as

## Example
Use in express route or middleware:

```js
var htmlprep = require('htmlprep');

Expand All @@ -30,6 +31,7 @@ Rewrite relative asset paths to point to an absolute CDN url. If the `cdnHost` o
<img src="/images/logo.gif">
```
becomes:

```html
<script src="//cdnhost.com/dir/js/app.js"></script>
<img src="//cdnhost.com/dir/images/logo.gif">
Expand All @@ -49,7 +51,9 @@ Omit HTML blocks or individual tags based on a custom build attribute. Useful fo
</div>
<script src="dist/app.min.js" data-build="release">
```
When called with `buildType:"debug"` becomes:
```html
<link rel="stylesheet" href="/css/layout.css">
<link rel="stylesheet" href="/css/nav.css">
Expand All @@ -61,13 +65,15 @@ When called with `buildType:"debug"` becomes:
```

And with `buildType:"release"`:

```html
<link rel="stylesheet" href="/dist/app.min.css">
<script src="dist/app.min.js">
```
### Block injection
Inject blocks of HTML at render time to the `<head>` or `<body>` tags or to a named block specified with the `data-placeholder` attribute.
```js
htmlprep({
inject: {
Expand All @@ -90,6 +96,7 @@ htmlprep({
</html>
```
becomes:
```html
<html>
<head>
Expand All @@ -111,6 +118,16 @@ Appends the livereload script at the end of the body.
<script src="//localhost:35729/livereload.js"></script>
```

## Options
All the possible attributes that can be specifed in the `options` parameter.

* `buildType` - All elements with
* `liveReload` - Specify if the localhost LiveReload script should be injected.
* `liveReloadPort` - The port number for livereload.js, defaults to 35729.
* `cdnify` - Specify that relative asset URLs be repointed to an absolute CDN path.
* `cdnHost` - The CDN host to point to if `cdnify` is true.
* `inject` - Object of HTML blocks to inject over placeholders. The keys `body` and `head` will append to those respective tag names rather than a corresponding placeholder.

## Roadmap
### User-Agent specific blocks
Exclude blocks of HTML where the request user-agent does not pass an expression test. Useful for including polyfill scripts conditionally or excluding content from mobile devices to lighten the HTML payload.
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ exports = module.exports = function(options) {
options = _.defaults(options, {
attrPrefix: null,
buildType: 'debug',
livereload: false, // Should livereload script be injected
livereloadPort: 35729, // Port that livereload to listen on
liveReload: false, // Should livereload script be injected
liveReloadPort: 35729, // Port that livereload to listen on
inject: {} // Blocks of HTML to be injected
});

Expand Down Expand Up @@ -46,7 +46,7 @@ exports = module.exports = function(options) {
inPlaceholder = true;
return;
}

// If in removeMode, don't write to the output stream.
if (tagMatchContext) {
if (name === tagMatchContext.name) {
Expand Down Expand Up @@ -127,8 +127,8 @@ exports = module.exports = function(options) {
if (name === 'body') {
if (options.inject.body)
self.push(options.inject.body);
if (options.livereload === true)
self.push('<script src="//localhost:' + options.livereloadPort + '/livereload.js"></script>');
if (options.liveReload === true)
self.push('<script src="//localhost:' + options.liveReloadPort + '/livereload.js"></script>');
}

self.push("</" + name + ">");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "htmlprep",
"version": "1.0.0",
"version": "1.0.1",
"description": "High-performance streaming HTML pre-processor designed to run in middleware.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion test/htmlprep.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ describe('htmlprep()', function() {
it('injects livereload script', function(done) {
var html = '<html><body><h1>title</h1></body></html>';

runProcessor(html, {livereload: true}, function(err, output) {
runProcessor(html, {liveReload: true}, function(err, output) {
if (err) return done(err);

assert.equal(output, '<html><body><h1>title</h1><script src="//localhost:35729/livereload.js"></script></body></html>');
Expand Down

0 comments on commit 75f23da

Please sign in to comment.