diff --git a/lib/markup.js b/lib/markup.js index 87151c0..8b8ab70 100644 --- a/lib/markup.js +++ b/lib/markup.js @@ -94,11 +94,16 @@ function highlight(description) { return $.html() } -function determineLanguage(lang) { +function determineLanguage(maybeFileName) { + const lang = maybeFileName.split('.').pop() switch (lang) { case 'js': case 'javascript': return 'javascript' + case 'ts': + return 'typescript' + case 'hbs': + return 'handlebars' default: return lang } diff --git a/package.json b/package.json index 65e93a3..1149057 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,9 @@ "server": "http-server -p 5050 --cors tmp", "serve": "yarn server", "start": "node index.js", - "test": "eslint lib/**/*.js index.js test/**.js && mocha -r esm test" + "test:mocha": "mocha -r esm test", + "lint": "eslint lib/**/*.js index.js test/**.js", + "test": "yarn lint && yarn test:mocha" }, "dependencies": { "cheerio": "^1.0.0-rc.2", diff --git a/test/markup-test.js b/test/markup-test.js new file mode 100644 index 0000000..675a485 --- /dev/null +++ b/test/markup-test.js @@ -0,0 +1,62 @@ +import markup from '../lib/markup' +import { assert } from 'chai' +import fs from 'fs' +import { join } from 'path' + +function desc(path) { + return { + id: Date.now(), + attributes: { + description: fs.readFileSync(join(__dirname, `./mocks/description/${path}.md`), 'utf-8'), + methods: [], + properties: [], + events: [] + } + } +} + +function mark(path) { + let data = [ + desc(path) + ] + let result = markup({data}) + let content = result.data[0].attributes.description + maybeWrite(content, path) + return content +} + +function maybeWrite(content, path) { + const fsPath = join(__dirname, `./mocks/description/${path}.html`) + if (fs.existsSync(fsPath)) { + return + } + fs.writeFileSync(fsPath, content, 'utf-8') +} + +function snapshot(path) { + const fsPath = join(__dirname, `./mocks/description/${path}.html`) + return fs.readFileSync(fsPath, 'utf8') +} + + +describe('markup', () => { + it('render correct syntax for handlebars with title', function() { + const caseName = 'handlebars-title' + assert.equal(mark(caseName), snapshot(caseName)) + }) + + it('render correct syntax for handlebars without title', function() { + const caseName = 'handlebars' + assert.equal(mark(caseName), snapshot(caseName)) + }) + + it('render correct syntax for javascript with title', function() { + const caseName = 'javascript-title' + assert.equal(mark(caseName), snapshot(caseName)) + }) + + it('render correct syntax for javascript without title', function() { + const caseName = 'javascript' + assert.equal(mark(caseName), snapshot(caseName)) + }) +}) diff --git a/test/mocks/description/handlebars-title.html b/test/mocks/description/handlebars-title.html new file mode 100644 index 0000000..00faa58 --- /dev/null +++ b/test/mocks/description/handlebars-title.html @@ -0,0 +1,65 @@ +
+
+
+ + + + + + + + + + + + +
profile.hbs
1
+2
+3
+
  <h1>{{person.title}}</h1>
+  {{! Executed in the component's context. }}
+  {{yield}} {{! block contents }}
+
+
+ +

If you want to customize the component, in order to + handle events or actions, you implement a subclass + of Ember.Component named after the name of the + component. + For example, you could implement the action + hello for the person-profile component:

+
+
+
+ + + + + + + + + + + + +
profile.js
1
+2
+3
+4
+5
+6
+7
+8
+
  import Ember from 'ember';
+  export default Ember.Component.extend({
+    actions: {
+      hello(name) {
+        console.log("Hello", name);
+      }
+    }
+  });
+
+
+ + \ No newline at end of file diff --git a/test/mocks/description/handlebars-title.md b/test/mocks/description/handlebars-title.md new file mode 100644 index 0000000..5e60961 --- /dev/null +++ b/test/mocks/description/handlebars-title.md @@ -0,0 +1,21 @@ +```app/components/person-profile.hbs +

{{person.title}}

+ {{! Executed in the component's context. }} + {{yield}} {{! block contents }} + ``` + If you want to customize the component, in order to + handle events or actions, you implement a subclass + of `Ember.Component` named after the name of the + component. + For example, you could implement the action + `hello` for the `person-profile` component: + ```app/components/person-profile.js + import Ember from 'ember'; + export default Ember.Component.extend({ + actions: { + hello(name) { + console.log("Hello", name); + } + } + }); +``` diff --git a/test/mocks/description/handlebars.html b/test/mocks/description/handlebars.html new file mode 100644 index 0000000..90e0f9f --- /dev/null +++ b/test/mocks/description/handlebars.html @@ -0,0 +1,60 @@ +
+
+
+ + + + + + + +
1
+2
+3
+
  <h1>{{person.title}}</h1>
+  {{! Executed in the component's context. }}
+  {{yield}} {{! block contents }}
+
+
+ +

If you want to customize the component, in order to + handle events or actions, you implement a subclass + of Ember.Component named after the name of the + component. + For example, you could implement the action + hello for the person-profile component:

+
+
+
+ + + + + + + + + + + + +
profile.js
1
+2
+3
+4
+5
+6
+7
+8
+
  import Ember from 'ember';
+  export default Ember.Component.extend({
+    actions: {
+      hello(name) {
+        console.log("Hello", name);
+      }
+    }
+  });
+
+
+ + \ No newline at end of file diff --git a/test/mocks/description/handlebars.md b/test/mocks/description/handlebars.md new file mode 100644 index 0000000..93c7b17 --- /dev/null +++ b/test/mocks/description/handlebars.md @@ -0,0 +1,21 @@ +```hbs +

{{person.title}}

+ {{! Executed in the component's context. }} + {{yield}} {{! block contents }} + ``` + If you want to customize the component, in order to + handle events or actions, you implement a subclass + of `Ember.Component` named after the name of the + component. + For example, you could implement the action + `hello` for the `person-profile` component: + ```app/components/person-profile.js + import Ember from 'ember'; + export default Ember.Component.extend({ + actions: { + hello(name) { + console.log("Hello", name); + } + } + }); +``` diff --git a/test/mocks/description/javascript-title.html b/test/mocks/description/javascript-title.html new file mode 100644 index 0000000..008aa90 --- /dev/null +++ b/test/mocks/description/javascript-title.html @@ -0,0 +1,35 @@ +
+
+
+ + + + + + + + + + + + +
app/routes/articles.js
1
+2
+3
+4
+5
+6
+7
+8
+
import Route from '@ember/routing/route';
+export default class ArticlesRoute extends Route {
+  resetController(controller, isExiting, transition) {
+    if (isExiting && transition.targetName !== 'error') {
+      controller.set('page', 1);
+    }
+  }
+}
+
+
+ + \ No newline at end of file diff --git a/test/mocks/description/javascript-title.md b/test/mocks/description/javascript-title.md new file mode 100644 index 0000000..6431841 --- /dev/null +++ b/test/mocks/description/javascript-title.md @@ -0,0 +1,10 @@ +```app/routes/articles.js +import Route from '@ember/routing/route'; +export default class ArticlesRoute extends Route { + resetController(controller, isExiting, transition) { + if (isExiting && transition.targetName !== 'error') { + controller.set('page', 1); + } + } +} +``` diff --git a/test/mocks/description/javascript.html b/test/mocks/description/javascript.html new file mode 100644 index 0000000..d4d9ff6 --- /dev/null +++ b/test/mocks/description/javascript.html @@ -0,0 +1,30 @@ +
+
+
+ + + + + + + +
1
+2
+3
+4
+5
+6
+7
+8
+
import Route from '@ember/routing/route';
+export default class ArticlesRoute extends Route {
+  resetController(controller, isExiting, transition) {
+    if (isExiting && transition.targetName !== 'error') {
+      controller.set('page', 1);
+    }
+  }
+}
+
+
+ + \ No newline at end of file diff --git a/test/mocks/description/javascript.md b/test/mocks/description/javascript.md new file mode 100644 index 0000000..46a9f57 --- /dev/null +++ b/test/mocks/description/javascript.md @@ -0,0 +1,10 @@ +```js +import Route from '@ember/routing/route'; +export default class ArticlesRoute extends Route { + resetController(controller, isExiting, transition) { + if (isExiting && transition.targetName !== 'error') { + controller.set('page', 1); + } + } +} +```