-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 05e78fc
Showing
10 changed files
with
435 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{print} = require 'util' | ||
{spawn} = require 'child_process' | ||
|
||
task 'build', 'Build lib/ from src/', -> | ||
coffee = spawn 'coffee', ['-c', '-o', 'lib', 'src'] | ||
coffee.stderr.on 'data', (data) -> | ||
process.stderr.write data.toString() | ||
coffee.stdout.on 'data', (data) -> | ||
print data.toString() | ||
coffee.on 'exit', (code) -> | ||
callback?() if code is 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Copyright (c) 2013 Paul Young | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# jade-inheritance | ||
This tool can be used to reduce compilation time for Jade files. | ||
|
||
For example, without `jade-inheritance`, a `watch` task on a directory would recompile all template files when any change was made within that directory. With `jade-inheritance`, only the affected files can be recompiled. | ||
|
||
|
||
## Example | ||
```javascript | ||
var JadeInheritance = require('jade-inheritance'); | ||
var inheritance = JadeInheritance('foo.jade'); | ||
``` | ||
|
||
### Inheritance tree | ||
```javascript | ||
console.log(inheritance.tree); | ||
``` | ||
|
||
Output: | ||
```json | ||
{ | ||
"foo.jade": { | ||
"extendedBy": { | ||
"bar.jade": { | ||
"includedBy": { | ||
"baz.jade": {} | ||
} | ||
} | ||
}, | ||
"extendedBy": { | ||
"qux.jade": {} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
### Dependant files | ||
```javascript | ||
console.log(inheritance.files); | ||
``` | ||
|
||
Output: | ||
```json | ||
[ | ||
"foo.jade", | ||
"bar.jade", | ||
"baz.jade", | ||
"qux.jade" | ||
] | ||
``` | ||
|
||
### Integration with [grunt-contrib-jade](https://github.com/gruntjs/grunt-contrib-jade) | ||
```javascript | ||
// Gruntfile.js | ||
grunt.initConfig({ | ||
jade: { | ||
compile: { | ||
options: { | ||
basedir: 'app', | ||
pretty: true | ||
}, | ||
files: [{ | ||
expand: true, | ||
src: 'app/**/*.jade', | ||
dest: 'assets/', | ||
ext: '.html' | ||
}] | ||
} | ||
} | ||
}); | ||
|
||
|
||
var JadeInheritance = require('jade-inheritance'); | ||
var changedFiles = []; | ||
|
||
var onChange = grunt.util._.debounce(function() { | ||
var options = grunt.config('jade.compile.options'); | ||
var dependantFiles = []; | ||
|
||
files.forEach(function(filename) { | ||
var directory = options.basedir; | ||
var inheritance = new JadeInheritance(filename, directory, options); | ||
dependantFiles = dependantFiles.concat(inheritance.files); | ||
}); | ||
|
||
var config = grunt.config('jade.compile.files')[0]; | ||
config.src = dependantFiles; | ||
grunt.config('jade.compile.files', [config]); | ||
|
||
changedFiles = []; | ||
}, 200) | ||
|
||
grunt.event.on('watch', function(action, filepath) { | ||
changedFiles.push(filepath); | ||
onChange(); | ||
}); | ||
``` | ||
|
||
## Installation | ||
```sh | ||
$ npm install -g jade-inheritance | ||
``` | ||
|
||
## Command line usage | ||
```sh | ||
$ jade-inheritance --help | ||
``` | ||
|
||
## Development | ||
### Build | ||
```sh | ||
$ npm run-script build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
var colors = require('colors'); | ||
var JadeInheritance = require('../lib/index'); | ||
var pjson = require(__dirname + '/../package.json'); | ||
var program = require('commander'); | ||
|
||
|
||
program | ||
.version(pjson.version) | ||
.usage('<jade file> <directory>') | ||
.option('--basedir [string]', 'Required for includes and extends that use absolute paths.') | ||
.option('--files', 'Instead of the inheritance tree, print an array containing the files which would be affected by a change in the input file.') | ||
.parse(process.argv); | ||
|
||
|
||
var filename = program.args[0]; | ||
|
||
if (!filename) { | ||
console.log('jade-inheritance: no file provided'.red); | ||
process.exit(1); | ||
} | ||
|
||
|
||
var directory = program.args[1]; | ||
|
||
if (!directory) { | ||
directory = '.' | ||
} | ||
|
||
|
||
options = {}; | ||
options.basedir = program.basedir || directory; | ||
|
||
|
||
var inheritance = new JadeInheritance(filename, directory, options); | ||
var output = program.files ? inheritance.files : inheritance.tree; | ||
console.log(JSON.stringify(output, null, 2)); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"name": "jade-inheritance", | ||
"description": "Determine the inheritance of Jade templates.", | ||
"url": "https://github.com/paulyoung/jade-inheritance", | ||
"keywords": [ | ||
"jade" | ||
], | ||
"version": "0.0.1", | ||
"bin": { | ||
"jade-inheritance": "./bin/jade-inheritance" | ||
}, | ||
"main": "./lib/index", | ||
"engines": { | ||
"node": ">=0.8.x" | ||
}, | ||
"dependencies": { | ||
"colors": "0.6.2", | ||
"commander": "1.2.0", | ||
"glob": "3.2.6", | ||
"jade": "~0.34.1" | ||
}, | ||
"devDependencies": { | ||
"coffee-script": "1.6.3" | ||
}, | ||
"scripts": { | ||
"build": "./node_modules/.bin/cake build" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/paulyoung/jade-inheritance.git" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Parser = require './parser' | ||
|
||
class JadeInheritance | ||
constructor: (filename, directory, options) -> | ||
parser = new Parser filename, directory, options | ||
@tree = parser.tree | ||
@files = parser.files | ||
return this | ||
|
||
module.exports = JadeInheritance |
Oops, something went wrong.