Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyoung committed Sep 20, 2013
0 parents commit 05e78fc
Show file tree
Hide file tree
Showing 10 changed files with 435 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
11 changes: 11 additions & 0 deletions Cakefile
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
19 changes: 19 additions & 0 deletions LICENSE
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.
112 changes: 112 additions & 0 deletions README.md
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
```
37 changes: 37 additions & 0 deletions bin/jade-inheritance
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));
22 changes: 22 additions & 0 deletions lib/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

108 changes: 108 additions & 0 deletions lib/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions package.json
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"
}
}
10 changes: 10 additions & 0 deletions src/index.coffee
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
Loading

0 comments on commit 05e78fc

Please sign in to comment.