Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Commit 34b0dea

Browse files
committed
Proof of concept
1 parent 78038a3 commit 34b0dea

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

.jshintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
"white": false,
2929
"eqnull": true,
3030
"esnext": true,
31-
"unused": true
31+
"unused": "vars"
3232
}

index.js

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,57 @@
11
/* jshint node: true */
22
'use strict';
33

4+
var Filter = require('broccoli-filter');
5+
var marked = require('marked');
6+
marked.setOptions({
7+
gfm: true,
8+
sanitize: true
9+
});
10+
11+
function TemplateCompiler(inputNode, options) {
12+
if (!(this instanceof TemplateCompiler)) {
13+
return new TemplateCompiler(inputNode, options);
14+
}
15+
16+
options = options || {};
17+
Filter.call(this, inputNode, options);
18+
this.compile = marked;
19+
}
20+
21+
TemplateCompiler.prototype = Object.create(Filter.prototype);
22+
TemplateCompiler.prototype.constructor = TemplateCompiler;
23+
TemplateCompiler.prototype.extensions = ['md'];
24+
TemplateCompiler.prototype.targetExtension = 'hbs';
25+
26+
TemplateCompiler.prototype.processString = function(string, relativePath) {
27+
return this.compile(string).replace(/{/g, '{');
28+
};
29+
430
module.exports = {
5-
name: 'ember-cli-markdown-compiler'
31+
name: 'ember-cli-markdown-compiler',
32+
33+
isDevelopingAddon: function() {
34+
return true;
35+
},
36+
37+
setupPreprocessorRegistry: function(type, registry) {
38+
registry.add('template', {
39+
name: 'ember-cli-markdown-compiler',
40+
ext: ['md'],
41+
toTree: function(tree) {
42+
return TemplateCompiler(tree);
43+
}
44+
});
45+
46+
if (type === 'parent') {
47+
this.parentRegistry = registry;
48+
}
49+
},
50+
51+
included: function(app) {
52+
this._super.included.apply(this, arguments);
53+
54+
this.setupPreprocessorRegistry('parent', app.registry);
55+
}
56+
657
};

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "ember-cli-markdown-compiler",
3-
"version": "0.0.0",
4-
"description": "The default blueprint for ember-cli addons.",
3+
"version": "1.0.0",
4+
"description": "Build-time Markdown compiler for template.md -> template.hbs",
55
"directories": {
66
"doc": "doc",
77
"test": "tests"
@@ -41,9 +41,15 @@
4141
"ember-addon"
4242
],
4343
"dependencies": {
44-
"ember-cli-babel": "^5.1.3"
44+
"broccoli-filter": "^1.2.2",
45+
"ember-cli-babel": "^5.1.3",
46+
"marked": "0.3.5"
4547
},
4648
"ember-addon": {
47-
"configPath": "tests/dummy/config"
49+
"configPath": "tests/dummy/config",
50+
"before": [
51+
"ember-cli-htmlbars"
52+
]
53+
4854
}
49-
}
55+
}

0 commit comments

Comments
 (0)