forked from helpers/handlebars-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
code.js
88 lines (80 loc) · 2.78 KB
/
code.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'use strict';
require('mocha');
var assert = require('assert');
var hbs = require('handlebars').create();
var helpers = require('..');
helpers.code({handlebars: hbs});
describe('code', function() {
describe('embed', function() {
it('should embed markdown:', function() {
assert.equal(hbs.compile('{{{embed "test/fixtures/simple.md"}}}')(), [
'```markdown',
'## Some Markdown\n',
' - one',
' - two',
' - three\n',
'[Click here](http://github.com)\n',
'```\n'
].join('\n'));
});
it('should determine the language from the file extension', function() {
assert.equal(hbs.compile('{{{embed "test/fixtures/embedded.md"}}}')(), [
'```markdown',
'## Markdown',
'',
'Code example',
'',
'```js',
'var urlresolve = function(base, href) {',
' return url.resolve(base, href);',
'};',
'```',
'',
'[Click here](http://assemble.io) for more documentation.',
'',
'```\n'
].join('\n'));
});
it('should use the language defined in the last argument', function() {
var template = hbs.compile('{{{embed "test/fixtures/index.html" "hbs"}}}');
assert.equal(template(), [
'```hbs',
'<!DOCTYPE html>',
' <html lang="en">',
' <head>',
' <meta charset="UTF-8">',
' <title>{{title}}</title>',
' </head>',
' <body>',
' {{> foo }}',
' </body>',
'</html>',
'',
'```\n'
].join('\n'));
});
});
describe('gist', function() {
it('should return a gist script tag', function() {
var fn = hbs.compile('{{{gist "abcdefg"}}}');
assert.equal(fn(), '<script src="https://gist.github.com/abcdefg.js"></script>');
});
});
describe('jsfiddle', function() {
it('should return a jsfiddle embed link, with default tabs assigned', function() {
var source = '{{{jsfiddle id="UXbas"}}}';
var fn = hbs.compile(source);
assert.equal(fn(), '<iframe width="100%" height="300" src="http://jsfiddle.net/UXbas/embedded/result,js,html,css/presentation/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>');
});
it('should throw an error if id is missing', function() {
assert.throws(function() {
hbs.compile('{{jsfiddle}}')();
});
});
it('should return a jsfiddle embed link, with custom tabs assigned', function() {
var source = '{{{jsfiddle id="UXbas" tabs="html,css"}}}';
var fn = hbs.compile(source);
assert.equal(fn(), '<iframe width="100%" height="300" src="http://jsfiddle.net/UXbas/embedded/html,css/presentation/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>');
});
});
});