Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lordnox/sourcefile
automatic sourcefile compiler for jade, stylus and coffeescript for node.js
https://github.com/lordnox/sourcefile
Last synced: 26 days ago
JSON representation
automatic sourcefile compiler for jade, stylus and coffeescript for node.js
- Host: GitHub
- URL: https://github.com/lordnox/sourcefile
- Owner: lordnox
- Created: 2012-02-29T11:30:20.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-02-29T11:44:50.000Z (over 12 years ago)
- Last Synced: 2024-04-17T05:17:20.034Z (7 months ago)
- Language: CoffeeScript
- Homepage:
- Size: 918 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# source-file
source-file is a project to automatically recompile sourcefiles used during
development. It exposes each file as an eventemitter that tells you when the
file itself is loaded for the first time or if it is changed.## How to Install
npm install sourcefile
## How to use
First, require `sourcefile`:
```js
var Sourcefile = require('sourcefile');
```Next, attach it to a sourcefile. First we show a jade-template:
```js
// libs needed for the example
var fs = require('fs'),
jade = require('jade');// vars used
var Template = new Sourcefile('./index.jade'),
template = '';Template.on('loaded', function(path) {
fs.readFile(path, 'utf8', function(err, contents) {
template = jade.compile(contents, {filename: path});
});
});Template.on('modified', function(path) {
fs.readFile(path, 'utf8', function(err, contents) {
template = jade.compile(contents, {filename: path});
});
});// Template.on('error', function(error) {});
```## Sugar
There are subclasses defined that will emit an `compiled` event. This will be called
after these subclasses have done their job.```js
var template = '';
// This will identifiy the file as a jade file and use the callback accordingly
jadeTemplate = new Sourcefile.Jade('./index.jade');
jadeTemplate.on('compiled', function(data) {
template = data;
});
```Available are:
* jade - Sourcefile.jade
> compiled jade template function
* stylus - Sourcefile.stylus
> compiled stylus css as string
* coffee-script - Sourcefile.coffee
> compiled coffee-script javascript code as string
```js
var template = '';
// This will identifiy the file as a jade file and use the callback accordingly
Sourcefile.source('./index.jade', function(data) {
template = data;
});
```And for even more convenience or because its just stupid to sort everything again later
we can tell the `source`-function what to use```js
// This will identifiy the file as a jade file and use the callback accordingly
// Here we will write the private `style.styl` to the public `style.css`
Sourcefile.source('./private/style.styl', ['coffee', 'stylus'], function(data, path, name) {
fs.writeFile(name.replace('/private/', '/public/'), data, 'utf8');
});
```