From d8814a08c6a5026f0988030f775ff46e7d8064ca Mon Sep 17 00:00:00 2001 From: Scott Warren Date: Sat, 17 Jan 2015 21:52:20 +1000 Subject: [PATCH 1/6] Adds tests, updates package.json, Adds base readme and travisCI config --- .travis.yml | 5 +++++ README.md | 10 ++++++++++ package.json | 3 +++ test/tests.js | 30 ++++++++++++++++++++++++++++++ index.js => twigify.js | 4 +++- 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 .travis.yml create mode 100644 README.md create mode 100644 test/tests.js rename index.js => twigify.js (95%) diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..4a83e22 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - "0.11" + - "0.10" + - "0.8" diff --git a/README.md b/README.md new file mode 100644 index 0000000..3fddb66 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +Twigify +===== + +Twigify converts a .html.twig file to a compiled state using twig.js + +The idea is to precompile and package frontend templates for use. + +Tests +===== +Run them use `npm test` after making sure you run `npm install` first diff --git a/package.json b/package.json index 7bea5a5..07c3fbd 100755 --- a/package.json +++ b/package.json @@ -27,10 +27,13 @@ "twig": "^0.7.2" }, "devDependencies": { + "mocha": "*", + "should": "*" }, "engines": { "node": ">=0.10" }, "scripts": { + "test": "mocha" } } diff --git a/test/tests.js b/test/tests.js new file mode 100644 index 0000000..0da0129 --- /dev/null +++ b/test/tests.js @@ -0,0 +1,30 @@ +var should = require('should'), + twigify = require('../twigify'); + +describe('Twigify', function() { + describe('#twigify()', function() { + it('should describe what the function does', function() { + }); + }); + + describe('#process()', function() { + it('should describe what the function does', function() { + }); + }); + + describe('#twigify().push()', function() { + it('should describe what the function does', function() { + }); + }); + + describe('#twigify().end()', function() { + it('should describe what the function does', function() { + }); + }); + + describe('#compile()', function() { + it('should return a minified version of the input', function() { + + }); + }); +}); diff --git a/index.js b/twigify.js similarity index 95% rename from index.js rename to twigify.js index 164580c..7053d1a 100755 --- a/index.js +++ b/twigify.js @@ -14,7 +14,9 @@ var minifyDefaults = { function compile(str) { var minified = minify(str, minifyDefaults); - var template = twig({ data: minified }); + var template = twig({ + data: minified + }); var tokens = JSON.stringify(template.tokens) From 3e471b2773a8354922f30eadbd52f257076fd88f Mon Sep 17 00:00:00 2001 From: Scott Warren Date: Sat, 17 Jan 2015 22:55:54 +1000 Subject: [PATCH 2/6] :lipstick: Updated gitignore to exclude coverage output --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3c3629e..4faa9b3 100755 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules +coverage.html +coverage From 1a516c5d4cbd921753e4f4c60e428f96b8760c58 Mon Sep 17 00:00:00 2001 From: Scott Warren Date: Sat, 17 Jan 2015 22:57:30 +1000 Subject: [PATCH 3/6] added LOC coverage tests --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 07c3fbd..70e67be 100755 --- a/package.json +++ b/package.json @@ -28,12 +28,13 @@ }, "devDependencies": { "mocha": "*", - "should": "*" + "should": "*", + "istanbul": "*" }, "engines": { "node": ">=0.10" }, "scripts": { - "test": "mocha" + "test": "istanbul cover _mocha -- -R spec && mocha" } } From c0940313b0553621e723b81f43b31cd38ea66905 Mon Sep 17 00:00:00 2001 From: Scott Warren Date: Sat, 17 Jan 2015 22:57:39 +1000 Subject: [PATCH 4/6] Updates to tests --- test/tests.js | 37 ++++++++++++++++++++++++++++++------- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/test/tests.js b/test/tests.js index 0da0129..0a4acb5 100644 --- a/test/tests.js +++ b/test/tests.js @@ -1,9 +1,29 @@ -var should = require('should'), - twigify = require('../twigify'); +var should = require('should'), + twigify = require('../twigify'), + twig = require('twig').twig; + +/** + * use this in the tests to render the returned string from Twigify into a Twig + * rendered string, with optionally your Object containing the variables that your + * Twig template requires + * @param {String} twigifyRender String that Twigify returns, that you need + * to render still + * @param {Object} twigVars (Optional) Any variables within an Object that your + * template requires + * @return {String} rendered Twig template as a string + */ +var render = function(twigifyRender, twigVars) { + // Create an empty object if we're passed no twigVars + twigVars = twigVars || {}; + + // eval the Twigify string and then use Twig to render it + return eval(twigifyRender).render(twigVars); +}; describe('Twigify', function() { describe('#twigify()', function() { it('should describe what the function does', function() { + twigify(); }); }); @@ -12,14 +32,17 @@ describe('Twigify', function() { }); }); - describe('#twigify().push()', function() { - it('should describe what the function does', function() { + describe('#twigify()', function() { + it ('should be a function', function() { + twigify.should.be.an.instanceOf(Function); }); - }); + it('should render templates minified', function() { + var testMe = twigify.compile('a bc'); + testMe = render(testMe); - describe('#twigify().end()', function() { - it('should describe what the function does', function() { + testMe.should.equal('a bc'); }); + }); describe('#compile()', function() { From 43a062c776ad41ae18e5a90e5b579f16cb908ca8 Mon Sep 17 00:00:00 2001 From: Scott Warren Date: Sat, 17 Jan 2015 23:19:19 +1000 Subject: [PATCH 5/6] adding example file, trying to test loading files --- test/example.html.twig | 1 + test/tests.js | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 test/example.html.twig diff --git a/test/example.html.twig b/test/example.html.twig new file mode 100644 index 0000000..aa7f636 --- /dev/null +++ b/test/example.html.twig @@ -0,0 +1 @@ +this is a test, with some {{ variables }} diff --git a/test/tests.js b/test/tests.js index 0a4acb5..1f68f86 100644 --- a/test/tests.js +++ b/test/tests.js @@ -36,6 +36,7 @@ describe('Twigify', function() { it ('should be a function', function() { twigify.should.be.an.instanceOf(Function); }); + it('should render templates minified', function() { var testMe = twigify.compile('a bc'); testMe = render(testMe); @@ -43,11 +44,21 @@ describe('Twigify', function() { testMe.should.equal('a bc'); }); - }); + it('should render variables within the Twig template', function() { + var testMe = twigify.compile('hey {{ name }}'); + testMe = render(testMe, { + name: 'Scott' + }); - describe('#compile()', function() { - it('should return a minified version of the input', function() { + testMe.should.equal('hey Scott'); + }); + it('should load and render a test file', function() { + var testMe = twigify('test/example.html.twig'); + console.log(testMe); + + testMe.should.equal('this is a test, with some variable PLACEHOLDER!'); }); + }); }); From 6415268c8132eccfa95e7f4e33858e907ecb779d Mon Sep 17 00:00:00 2001 From: Scott Warren Date: Sat, 17 Jan 2015 23:25:01 +1000 Subject: [PATCH 6/6] :lipstick: :new_moon_with_face: removed empty tests --- test/tests.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/tests.js b/test/tests.js index 1f68f86..b8d5bbf 100644 --- a/test/tests.js +++ b/test/tests.js @@ -21,17 +21,6 @@ var render = function(twigifyRender, twigVars) { }; describe('Twigify', function() { - describe('#twigify()', function() { - it('should describe what the function does', function() { - twigify(); - }); - }); - - describe('#process()', function() { - it('should describe what the function does', function() { - }); - }); - describe('#twigify()', function() { it ('should be a function', function() { twigify.should.be.an.instanceOf(Function);