summaryrefslogtreecommitdiffstats
path: root/test/template.js
blob: f338a848e4b167f50690b6b24221af8580688976 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
var mock = require('./mock');
var pkg = require('../package.json');

describe('Template', function() {
    var book;

    before(function() {
        return mock.setupDefaultBook({
            'test.md': 'World'
        })
        .then(function(_book) {
            book = _book;
            return book.parse();
        });
    });

    describe('.renderString', function() {
        it('should render a simple string', function() {
            return book.template.renderString('Hello World')
                .should.be.fulfilledWith('Hello World');
        });

        it('should render with variable', function() {
            return book.template.renderString('Version is {{ gitbook.version }}')
                .should.be.fulfilledWith('Version is '+pkg.version);
        });
    });

    describe('Conrefs Loader', function() {
        it('should include a local file', function() {
            return book.template.renderString('Hello {% include "./test.md" %}')
                .should.be.fulfilledWith('Hello World');
        });

        it('should include a git url', function() {
            return book.template.renderString('Hello {% include "./test.md" %}')
                .should.be.fulfilledWith('Hello World');
        });

        it('should reject file out of scope', function() {
            return book.template.renderString('Hello {% include "../test.md" %}')
                .should.be.rejected();
        });

        describe('Git Urls', function() {
            it('should include a file from a git repo', function() {
                return book.template.renderString('{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test.md" %}')
                    .should.be.fulfilledWith('Hello from git');
            });

            it('should handle deep inclusion (1)', function() {
                return book.template.renderString('{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test2.md" %}')
                    .should.be.fulfilledWith('First Hello. Hello from git');
            });

            it('should handle deep inclusion (2)', function() {
                return book.template.renderString('{% include "git+https://gist.github.com/69ea4542e4c8967d2fa7.git/test3.md" %}')
                    .should.be.fulfilledWith('First Hello. Hello from git');
            });
        });
    });

});