-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcode.js
64 lines (57 loc) · 1.87 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
/*!
* template-helpers <https://github.com/jonschlinkert/template-helpers>
*
* Copyright (c) 2015, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var helpers = require('..')('code');
var assert = require('assert');
var template = require('lodash.template');
var imports = {imports: helpers};
describe('code', function() {
var orig = process.cwd();
before(function() {
process.chdir(__dirname + '/fixtures');
});
after(function() {
process.chdir(orig);
});
describe('jsfiddle', function() {
it('should return an empty string with no args.', function() {
assert.equal(template('<%= jsfiddle() %>', imports)(), '');
});
it('should return create a jsfiddle link.', function() {
assert.equal(template('<%= jsfiddle({id: "c0th6weq", tabs: true}) %>', imports)(), '<iframe width="100%" height="300" src="http://jsfiddle.net/c0th6weq/embedded/true/presentation/" allowfullscreen="allowfullscreen" frameborder="0"></iframe>');
});
});
describe('embed', function() {
it('should return create a code example from the given file.', function() {
assert.equal(template('<%= embed("a.js") %>', imports)({}), [
'```js',
'function foo(a, b, c) {',
' return a + b + c;',
'}',
'```\n'
].join('\n'));
});
it('should use the extension specified as a second argument.', function() {
assert.equal(template('<%= embed("a.js", "javascript") %>', imports)(), [
'```javascript',
'function foo(a, b, c) {',
' return a + b + c;',
'}',
'```\n'
].join('\n'));
});
it('should escape backticks in markdown.', function() {
assert.equal(template('<%= embed("a.md", "md") %>', imports)(), [
'```md',
'```',
'foo',
'```',
'```\n'
].join('\n'));
});
});
});