To install: fork or download this code and the "require" to the directory. Or you can npm install snip (this project is also my testing ground for NPM modules).
To use:
- After installing, add "require('snip')"
- Create a root level directory called "snips".
- Place HTML in "snips" you want to include into other pages.
- Place comments in the HTML you want to have the snips included in like this:
<!-- snip:html/header.html -->
While keeping the spacing the same as above, this comment would bring "header.html" from the "html" directory in "snips" to the page. - In where you are routing HTML, "snip" incoming data. Like so:
<P> fs.readFile('views/index.html', 'utf8', function(err, data){<BR /> res.writeHead(200, {'Content-Type':'text/html'}); <BR /> res.write(snip.snip(data)); <BR /> res.end();<BR /> });<BR /> </P> </LI>
That's it. Catch me on twitter @joshbirk if you have any questions.
Todo:
- Make the "snips" directory controlled by environment variables.
- Make snips multi-level.