snip

0.5.1 • Public • Published

Snip

Snip is a ridiculously simple Node module to include client side files into other files (essentially the same as Server Side Includes with Apache). There might be, and probably are, other modules which include this functionality and a lot more - but I needed it for some demo code, was curious if I could get it to work in a couple hours as an experiment ... so here it is.

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:

  1. After installing, add "require('snip')"
  2. Create a root level directory called "snips".
  3. Place HTML in "snips" you want to include into other pages.
  4. 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.
  5. 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.

Readme

Keywords

none

Package Sidebar

Install

npm i snip

Weekly Downloads

2

Version

0.5.1

License

none

Last publish

Collaborators

  • joshbirk