Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit b1c1dd5eed5557c63dc8ea4e6221da6e22002dca @tj committed Aug 7, 2012
Showing with 97 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +4 −0 .npmignore
  3. +5 −0 History.md
  4. +7 −0 Makefile
  5. +29 −0 Readme.md
  6. +16 −0 index.js
  7. +13 −0 package.json
  8. +19 −0 test/index.js
  9. +3 −0 test/tip.html
@@ -0,0 +1 @@
+node_modules
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
@@ -0,0 +1,5 @@
+
+0.0.1 / 2010-01-03
+==================
+
+ * Initial release
@@ -0,0 +1,7 @@
+
+test:
+ @./node_modules/.bin/mocha \
+ --require should \
+ --reporter spec
+
+.PHONY: test
@@ -0,0 +1,29 @@
+
+# html-to-js
+
+ Make HTML require()-able
+
+## License
+
+(The MIT License)
+
+Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
+
+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.
@@ -0,0 +1,16 @@
+
+/**
+ * Convert `str` of html to a string of js.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api public
+ */
+
+module.exports = function(str){
+ return "module.exports = '"
+ + str
+ .replace(/'/g, "\\'")
+ .replace(/\r\n|\r|\n/g, "\\n")
+ + "'";
+};
@@ -0,0 +1,13 @@
+{
+ "name": "html-to-js",
+ "version": "0.0.1",
+ "description": "Make HTML require()-able",
+ "keywords": [],
+ "author": "TJ Holowaychuk <tj@vision-media.ca>",
+ "dependencies": {},
+ "devDependencies": {
+ "mocha": "*",
+ "should": "*"
+ },
+ "main": "index"
+}
@@ -0,0 +1,19 @@
+
+/**
+ * Module dependencies.
+ */
+
+var fs = require('fs')
+ , html2js = require('..')
+ , read = fs.readFileSync
+ , vm = require('vm')
+
+describe('html2js(str)', function(){
+ it('should return js', function(){
+ var html = read('test/tip.html', 'utf8');
+ var js = html2js(html);
+ var mod = { exports: {} };
+ vm.runInNewContext(js, { module: mod });
+ mod.exports.should.equal(html);
+ })
+})
@@ -0,0 +1,3 @@
+<div class="tip">
+ <div class="tip-message">'Message here'</div>
+</div>

0 comments on commit b1c1dd5

Please sign in to comment.