Skip to content

Commit

Permalink
added nunjucks for template rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Rembold committed Feb 14, 2016
1 parent 953e3cc commit 5b3d84f
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea
node_modules
node_modules
test/pages
25 changes: 20 additions & 5 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
var spawn = require('child_process').spawn,
gulp = require('gulp'),
gutil = require('gulp-util');
var spawn = require('child_process').spawn;
var gulp = require('gulp');
var gutil = require('gulp-util');
var nunjucksRender = require('gulp-nunjucks-render');

gulp.task('test', function () {
var tests = ['test/'];

gulp.task('test', ['nunjucks'], function () {

var tests = ['test/casper/tests/'];
var casperChild = spawn('casperjs', ['test'].concat(tests));

casperChild.stdout.on('data', function (data) {
Expand All @@ -18,4 +21,16 @@ gulp.task('test', function () {
process.exit(1);
}
});

});

gulp.task('nunjucks', function() {

// Gets .html and .nunjucks files in pages
return gulp.src('test/nunjucks/*.nunjucks')
.pipe(nunjucksRender({
path: ['test/nunjucks/partials/', 'test/nunjucks/layouts/']
}))
.pipe(gulp.dest('test/pages/'))

});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"devDependencies": {
"casperjs": "^1.1.0-beta5",
"gulp": "^3.9.1",
"gulp-nunjucks-render": "^2.0.0",
"gulp-util": "^3.0.7"
}
}
9 changes: 9 additions & 0 deletions test/casper/include/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
sayHi: function() {
console.log('Hello from module.exports');
}
};

casper.sayHiAgain = function() {
this.echo('Hello from casper function');
};
7 changes: 6 additions & 1 deletion test/test1.js → test/casper/tests/test1.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
var includeTest = require('../include/test');

casper.test.begin('testing.html contains stuff', 3, function (test) {

casper.start('./test/test1.html', function () {
casper.start('./test/pages/test1.html', function () {
test.assertTitle('Test Page');
test.assertSelectorHasText('h1', 'Test!');
});

casper.then(function () {
this.click('button');
test.assertSelectorHasText('h1', 'New title');

includeTest.sayHi();
casper.sayHiAgain();
});

casper.run(function() {
Expand Down
18 changes: 18 additions & 0 deletions test/nunjucks/layouts/master.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<!doctype html>
<html lang="en">
<head>
<title>Test Page</title>
<meta charset="utf-8">
{% block styles %}{% endblock %}
</head>
<body>

{% block content %}{% endblock %}

{% block includes %}{% endblock %}
<script>
{% block scripts %}{% endblock %}
</script>

</body>
</html>
1 change: 1 addition & 0 deletions test/nunjucks/partials/accordion.default.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button>Change title</button>
17 changes: 17 additions & 0 deletions test/nunjucks/test1.nunjucks
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{% extends "master.html" %}

{% block content %}

<h1>Test!</h1>
{% include "accordion.default.nunjucks" %}

{% endblock %}


{% block scripts %}

document.querySelector('button').addEventListener('click', function () {
document.querySelector('h1').innerHTML = 'New title';
});

{% endblock %}
18 changes: 0 additions & 18 deletions test/test1.html

This file was deleted.

0 comments on commit 5b3d84f

Please sign in to comment.