Skip to content

Commit 0471cf0

Browse files
committed
Expose compileMarkdown as public API
- closes #318
1 parent a00a28e commit 0471cf0

File tree

20 files changed

+1481
-61
lines changed

20 files changed

+1481
-61
lines changed

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ module.exports = {
3636
'config/**/*.js',
3737
'lib/**/*.js',
3838
'tests/dummy/config/**/*.js',
39-
'tests-node/**/*.js'
39+
'tests-node/**/*.js',
40+
'addon-docs-shared/**/*.js'
4041
],
4142
excludedFiles: [
4243
'addon/**',
File renamed without changes.

addon-docs-shared/node_modules/.bin

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

addon-docs-shared/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "addon-docs-shared",
3+
"description": "Common code used at both build time and run time",
4+
"version": "1.0.0",
5+
"dependencies": {
6+
"marked": "*",
7+
"highlight.js": "*"
8+
}
9+
}

addon/utils/compile-markdown.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import compileMarkdown from 'addon-docs-shared/compile-markdown';
2+
3+
export default compileMarkdown;

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ const EmberApp = require('ember-cli/lib/broccoli/ember-app'); // eslint-disable-
99
const Plugin = require('broccoli-plugin');
1010
const walkSync = require('walk-sync');
1111
const buildTailwind = require('ember-cli-tailwind/lib/build-tailwind');
12+
// const foo = require('addon-docs-shared/foo');
13+
14+
// foo();
1215

1316
const LATEST_VERSION_NAME = '-latest';
1417

lib/broccoli/docs-compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const CachingWriter = require('broccoli-caching-writer');
77

88
const Serializer = require('../serializers/main');
99

10-
const compileMarkdown = require('../utils/compile-markdown');
10+
const compileMarkdown = require('addon-docs-shared//compile-markdown');
1111
const NavigationIndexGenerator = require('./docs-compiler/navigation-index-generator');
1212

1313
function compileDescriptions(objects) {

lib/preprocessors/markdown-template-compiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

33
const stew = require('broccoli-stew');
4-
const compileMarkdown = require('../utils/compile-markdown');
4+
const compileMarkdown = require('addon-docs-shared/compile-markdown');
55

66
module.exports = class MarkdownTemplateCompiler {
77
constructor() {

lib/utils/compile-doc-descriptions.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const compileMarkdown = require('./compile-markdown');
3+
const compileMarkdown = require('addon-docs-shared/compile-markdown');
44

55
module.exports = function compileDescriptions(docs) {
66
for (let doc of docs) {

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
},
2727
"dependencies": {
2828
"@glimmer/syntax": "^0.36.4",
29+
"addon-docs-shared": "./addon-docs-shared",
2930
"broccoli-bridge": "^1.0.0",
3031
"broccoli-caching-writer": "^3.0.3",
3132
"broccoli-debug": "^0.6.4",
@@ -36,6 +37,7 @@
3637
"broccoli-plugin": "^1.3.1",
3738
"broccoli-source": "^1.1.0",
3839
"broccoli-stew": "^2.0.0",
40+
"ember-auto-import": "^1.2.19",
3941
"ember-cli-autoprefixer": "^0.8.1",
4042
"ember-cli-babel": "^6.16.0",
4143
"ember-cli-clipboard": "^0.11.1",
@@ -116,7 +118,7 @@
116118
"eslint-plugin-node": "^7.0.1",
117119
"loader.js": "^4.7.0",
118120
"qunit": "^2.6.2",
119-
"qunit-dom": "^0.8.0"
121+
"qunit-dom": "^0.8.4"
120122
},
121123
"resolutions": {
122124
"**/tough-cookie": "~2.4.0",

scripts/link-them.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,22 @@ for package in "new-addon"; do
2020
ln -s ../../.. ./ember-cli-addon-docs
2121
popd > /dev/null
2222
done
23+
24+
##################################################
25+
#
26+
# addon-docs-shared setup
27+
#
28+
#
29+
# Link it, so its packages can be used in node & ember
30+
mkdir -p ./node_modules
31+
pushd ./node_modules > /dev/null
32+
rm -rf ./addon-docs-shared
33+
ln -s ../addon-docs-shared ./addon-docs-shared
34+
popd > /dev/null
35+
36+
# Give it a node_modules directory and a .bin link, so it can find its dependencies
37+
mkdir -p ./addon-docs-shared/node_modules
38+
rm -rf ./addon-docs-shared/node_modules/.bin
39+
ln -s ./node_modules/.bin ./addon-docs-shared/node_modules/.bin
40+
#
41+
##################################################

test-apps/new-addon/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"ember-try": "*",
4545
"eslint-plugin-ember": "*",
4646
"eslint-plugin-node": "*",
47-
"loader.js": "*"
47+
"loader.js": "*",
48+
"qunit-dom": "*"
4849
},
4950
"engines": {
5051
"node": "^4.5 || 6.* || >= 7.*"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { module, test } from 'qunit';
2+
import { visit, currentURL } from '@ember/test-helpers';
3+
import { setupApplicationTest } from 'ember-qunit';
4+
5+
module('Acceptance | sanity checks test', function(hooks) {
6+
setupApplicationTest(hooks);
7+
8+
test('the dummy app boots', async function(assert) {
9+
await visit('/');
10+
11+
assert.equal(currentURL(), '/');
12+
});
13+
14+
test('the --brand-primary css variable works', async function(assert) {
15+
await visit('/');
16+
17+
assert.dom(`.docs-bg-brand`).hasStyle({
18+
backgroundColor: 'rgb(0, 128, 0)'
19+
});
20+
});
21+
22+
test('the compileMarkdown function works', async function(assert) {
23+
await visit('/route-using-compile-markdown');
24+
25+
assert.dom(`.docs-md`).includesText('In the beginning');
26+
assert.dom(`pre`).hasStyle({
27+
backgroundColor: 'rgb(40, 44, 52)'
28+
});
29+
});
30+
});

test-apps/new-addon/tests/acceptance/smoke-test-test.js

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Controller from '@ember/controller';
2+
import { computed } from '@ember/object';
3+
import compileMarkdown from 'ember-cli-addon-docs/utils/compile-markdown';
4+
import { htmlSafe } from '@ember/string';
5+
6+
export default Controller.extend({
7+
8+
body: `In the beginning, we could only use
9+
10+
\`\`\`js
11+
function foo() {
12+
console.log('bar');
13+
}
14+
\`\`\`
15+
16+
Now, we can use
17+
18+
\`\`\`js
19+
const foo = () => {
20+
console.log('bar');
21+
});
22+
\`\`\`
23+
`,
24+
25+
htmlBody: computed('body', function() {
26+
return htmlSafe(compileMarkdown(this.body));
27+
})
28+
29+
});

test-apps/new-addon/tests/dummy/app/router.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const Router = AddonDocsRouter.extend({
77
});
88

99
Router.map(function() {
10+
this.route('route-using-compile-markdown');
11+
1012
docsRoute(this, function() {
1113

1214
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div style="max-width: 800px; margin: 3rem auto;">
2+
<h1>AddonDocs' markdown compiler</h1>
3+
4+
<p>Here's some markdown, compiled using AddonDocs' markdown compiler & syntax highlighting:</p>
5+
6+
{{htmlBody}}
7+
</div>

tests-node/unit/utils/compile-markdown-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const QUnit = require('qunit'), test = QUnit.test;
44
const stripIndent = require('common-tags').stripIndent;
5-
const compileMarkdown = require('../../../lib/utils/compile-markdown');
5+
const compileMarkdown = require('addon-docs-shared/compile-markdown');
66

77
QUnit.module('Unit | compile-markdown', function(hooks) {
88
test('compacting curly paragraphs', function(assert) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import Route from '@ember/routing/route';
2+
// import renderMarkdown from 'ember-cli-addon-docs/utils/render-markdown';
3+
// import foo from 'addon-docs-shared/foo';
4+
5+
export default Route.extend({
6+
7+
model() {
8+
// foo();
9+
// console.log('hi from route');
10+
// console.log(renderMarkdown);
11+
}
12+
13+
});

0 commit comments

Comments
 (0)