Permalink
Browse files

add example in docs

  • Loading branch information...
tj committed Aug 7, 2012
1 parent b1c1dd5 commit 334047bdbe9092f71d922c8cff470e8505626616
Showing with 39 additions and 2 deletions.
  1. +38 −1 Readme.md
  2. +1 −1 index.js
View
@@ -1,7 +1,44 @@
# html-to-js
- Make HTML require()-able
+ Make HTML require()-able.
+
+## Installation
+
+ $ npm install html-to-js
+
+## Example
+
+tip.html:
+
+```html
+<div class="tip">
+ <div class="tip-message"></div>
+</div>
+```
+
+js:
+
+```js
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+ , html2js = require('html-to-js')
+ , read = fs.readFileSync;
+
+var html = read('test/tip.html', 'utf8');
+var js = html2js(html);
+console.log(js);
+```
+
+output js string:
+
+```js
+module.exports = '<div class="tip">\n <div class="tip-message">\'Message here\'</div>\n</div>';
+```
## License
View
@@ -12,5 +12,5 @@ module.exports = function(str){
+ str
.replace(/'/g, "\\'")
.replace(/\r\n|\r|\n/g, "\\n")
- + "'";
+ + "';";
};

0 comments on commit 334047b

Please sign in to comment.