Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
coverage.html
coverage
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.11"
- "0.10"
- "0.8"
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
"twig": "^0.7.2"
},
"devDependencies": {
"mocha": "*",
"should": "*",
"istanbul": "*"
},
"engines": {
"node": ">=0.10"
},
"scripts": {
"test": "istanbul cover _mocha -- -R spec && mocha"
}
}
1 change: 1 addition & 0 deletions test/example.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is a test, with some {{ variables }}
53 changes: 53 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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 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);

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'
});

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!');
});

});
});
4 changes: 3 additions & 1 deletion index.js → twigify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down