forked from helpers/handlebars-helpers
/
code.js
37 lines (31 loc) · 1.4 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
'use strict';
require('mocha');
const assert = require('assert');
const hbs = require('handlebars').create();
const codeHelpers = require('../lib/code');
hbs.registerHelper(codeHelpers);
describe('code', function() {
describe('gist', function() {
it('should return a gist script tag', function() {
const 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() {
const source = '{{{jsfiddle id="UXbas"}}}';
const 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() {
const source = '{{{jsfiddle id="UXbas" tabs="html,css"}}}';
const 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>');
});
});
});