Skip to content

Commit

Permalink
Fix issue #2
Browse files Browse the repository at this point in the history
  • Loading branch information
ericmorand committed Oct 6, 2017
1 parent b21c9be commit 8224994
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ class Depper extends Transform {
});

let processToken = function (token, template) {
if (token.type == 'logic') {
if (token.type === 'logic') {
token = token.token;

switch (token.type) {
case 'Twig.logic.type.include':
case 'Twig.logic.type.import': {
case 'Twig.logic.type.import':
case 'Twig.logic.type.extends':
case 'Twig.logic.type.embed':
case 'Twig.logic.type.use': {
token.stack.forEach(function (stackEntry) {
switch (stackEntry.type) {
case 'Twig.expression.type.string':
Expand Down
68 changes: 67 additions & 1 deletion test/depper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs');
const path = require('path');

tap.test('depper', function (test) {
test.plan(8);
test.plan(11);

test.test('should handle Twig.logic.type.include', function (test) {
let d = new Depper();
Expand Down Expand Up @@ -193,4 +193,70 @@ tap.test('depper', function (test) {

d.end(entry);
});

test.test('should handle Twig.logic.type.extends', function (test) {
let d = new Depper();
let entry = path.join(__dirname, '/fixtures/extends/entry.twig');

let rows = [];

d.on('data', function (row) {
rows.push(row);
});

d.on('finish', function () {
test.same(rows.sort(), [
path.join(__dirname, '/fixtures/extends/entry.twig'),
path.join(__dirname, '/fixtures/extends/import.twig')
].sort());

test.end();
});

d.end(entry);
});

test.test('should handle Twig.logic.type.embed', function (test) {
let d = new Depper();
let entry = path.join(__dirname, '/fixtures/embed/entry.twig');

let rows = [];

d.on('data', function (row) {
rows.push(row);
});

d.on('finish', function () {
test.same(rows.sort(), [
path.join(__dirname, '/fixtures/embed/entry.twig'),
path.join(__dirname, '/fixtures/embed/import.twig')
].sort());

test.end();
});

d.end(entry);
});

test.test('should handle Twig.logic.type.use', function (test) {
let d = new Depper();
let entry = path.join(__dirname, '/fixtures/use/entry.twig');

let rows = [];

d.on('data', function (row) {
rows.push(row);
});

d.on('finish', function () {
test.same(rows.sort(), [
path.join(__dirname, '/fixtures/use/entry.twig'),
path.join(__dirname, '/fixtures/use/import.twig')
].sort());

test.end();
});

d.end(entry);
});
});
2 changes: 2 additions & 0 deletions test/fixtures/embed/entry.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% embed "import.twig" %}
{% endembed %}
1 change: 1 addition & 0 deletions test/fixtures/embed/import.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
1 change: 1 addition & 0 deletions test/fixtures/extends/entry.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "import.twig" %}
1 change: 1 addition & 0 deletions test/fixtures/extends/import.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo
1 change: 1 addition & 0 deletions test/fixtures/use/entry.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% use "import.twig" %}
1 change: 1 addition & 0 deletions test/fixtures/use/import.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
foo

0 comments on commit 8224994

Please sign in to comment.