@condenast/ember-docs
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ | ||
"name": "@condenast/ember-docs", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Creates documentation from Ember apps / addons", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -5,5 +5,2 @@ const commonmark = require('commonmark'); | ||
const mdReader = new commonmark.Parser(); | ||
const mdWriter = new commonmark.HtmlRenderer(); | ||
function getPositionalParameters(ast, component) { | ||
@@ -39,4 +36,4 @@ let staticProperties = utils.getStaticProperties(ast, component) || []; | ||
if (component && mainComment) { | ||
let mainDoc = doctrine.parse(mainComment.value, { unwrap: true, recoverable: true }); | ||
docs.description = mdWriter.render(mdReader.parse(mainDoc.description)); | ||
let mainDoc = doctrine.parse(mainComment.value, { unwrap: false, recoverable: true }); | ||
docs.description = utils.markdown(mainDoc.description); | ||
@@ -52,4 +49,2 @@ if (docs.type == null) { | ||
} | ||
docs.examples = jsdoc[0].tags.filter(tag => tag.title === 'example') | ||
.map(example => mdWriter.render(mdReader.parse(example.description))); | ||
@@ -56,0 +51,0 @@ docs.dependencies = { |
@@ -228,3 +228,3 @@ const commonmark = require('commonmark'); | ||
if (helper && jsdoc && jsdoc[0]) { | ||
docs.description = mdWriter.render(mdReader.parse(jsdoc[0].description)); | ||
docs.description = utils.markdown(jsdoc[0].description); | ||
@@ -240,4 +240,2 @@ if (docs.type == null) { | ||
} | ||
docs.examples = jsdoc[0].tags.filter(tag => tag.title === 'example') | ||
.map(example => mdWriter.render(mdReader.parse(example.description))); | ||
@@ -244,0 +242,0 @@ docs.dependencies = { |
const commonmark = require('commonmark'); | ||
const mdReader = new commonmark.Parser(); | ||
const mdWriter = new commonmark.HtmlRenderer(); | ||
const utils = require('./utils'); | ||
@@ -16,3 +14,3 @@ const doctrine = require('doctrine'); | ||
let mainDoc = doctrine.parse(mainComment.value, { unwrap: true, recoverable: true }); | ||
docs.description = mdWriter.render(mdReader.parse(mainDoc.description)); | ||
docs.description = utils.markdown(mainDoc.description); | ||
@@ -28,4 +26,2 @@ if (docs.type == null) { | ||
} | ||
docs.examples = mainDoc.tags.filter(tag => tag.title === 'example') | ||
.map(example => mdWriter.render(mdReader.parse(example.description))); | ||
@@ -40,4 +36,4 @@ let properties = utils.getProperties(ast); | ||
if (comment) { | ||
let jsdoc = doctrine.parse(comment.value, { unwrap: true, recoverable: true }); | ||
jsdoc.description = mdWriter.render(mdReader.parse(jsdoc.description)); | ||
let jsdoc = doctrine.parse(comment.value, { unwrap: false, recoverable: true }); | ||
jsdoc.description = utils.markdown(jsdoc.description); | ||
return jsdoc; | ||
@@ -44,0 +40,0 @@ } |
const _ = require('lodash'); | ||
const commonmark = require('commonmark'); | ||
const mdReader = new commonmark.Parser({ smart: true }); | ||
const mdWriter = new commonmark.HtmlRenderer(); | ||
const utils = { | ||
@@ -24,2 +28,71 @@ getDefaultExport(ast) { | ||
unindent(text) { | ||
if (text == null) { | ||
return ''; | ||
} | ||
let indent = text.split('\n').reduce((indentation, line) => { | ||
if (line.length === 0) { | ||
return indentation; | ||
} | ||
let start = 0; | ||
while (line[start] === ' ' || | ||
line[start] === '*') { | ||
start++; | ||
} | ||
return Math.min(indentation, start); | ||
}, Infinity); | ||
return text.split('\n').map((line) => { | ||
return line.slice(indent); | ||
}).join('\n'); | ||
}, | ||
detectLanguage(code) { | ||
let hasHTML = /<[a-zA-Z-]+>/.test(code); | ||
let hasHandlebars = code.indexOf('{{') !== -1; | ||
if (hasHTML || hasHandlebars) { | ||
return 'htmlbars'; | ||
} | ||
return 'javascript'; | ||
}, | ||
markdown(text) { | ||
let start = 0; | ||
while (text[start] === '*') { | ||
start++; | ||
} | ||
let doc = mdReader.parse(utils.unindent(text.slice(start))); | ||
let walker = doc.walker(); | ||
let examples = []; | ||
let event; | ||
while ((event = walker.next())) { | ||
let node = event.node; | ||
if (event.entering && node.type === 'code_block') { | ||
examples.push(node.literal); | ||
node.literal = '\uFFFC'; | ||
} | ||
} | ||
let markdown = mdWriter.render(doc); | ||
let lines = markdown.replace(/<pre><code>\uFFFC<\/code><\/pre>/g, function (_, match) { | ||
return '\uFFFC'; | ||
}).split('\uFFFC'); | ||
let sections = []; | ||
lines.forEach(line => { | ||
sections.push(line); | ||
if (examples.length) { | ||
let source = examples.shift(); | ||
sections.push({ | ||
source, | ||
language: utils.detectLanguage(source) | ||
}); | ||
} | ||
}); | ||
return sections; | ||
}, | ||
getVariableFromReference(ast, reference) { | ||
@@ -26,0 +99,0 @@ let statements = ast.program.body; |
@@ -12,5 +12,6 @@ import Component from '@ember/component'; | ||
@example | ||
{{text-field value=name onchange=(action (mut name))}} | ||
<p>Hello, {{name}}</p> | ||
{{text-field value=name onchange=(action (mut name))}} | ||
<p>Hello, {{name}}</p> | ||
Test | ||
*/ | ||
@@ -17,0 +18,0 @@ export default Component.extend({ |
@@ -9,3 +9,9 @@ const parse = require('../../index'); | ||
expect(component.access).toBe('public'); | ||
expect(component.description).toBe('<p>Text fields are the building blocks of forms.\nWe have a custom component to use instead of Ember\'s\n<a href="https://emberjs.com/api/ember/release/classes/Ember.Templates.helpers/methods/input?anchor=input">{{input}}</a> so it follows a\nreactive programming model.</p>\n'); | ||
expect(component.description).toEqual([ | ||
'<p>Text fields are the building blocks of forms.\nWe have a custom component to use instead of Ember’s\n<a href="https://emberjs.com/api/ember/release/classes/Ember.Templates.helpers/methods/input?anchor=input">{{input}}</a> so it follows a\nreactive programming model.</p>\n', | ||
{ | ||
source: '{{text-field value=name onchange=(action (mut name))}}\n<p>Hello, {{name}}</p>\n', | ||
language: 'htmlbars' | ||
}, | ||
'\n<p>Test</p>\n']); | ||
}); | ||
@@ -18,5 +24,5 @@ | ||
expect(component.access).toBe('public'); | ||
expect(component.description).toBe('<p>Text fields are the building blocks of forms.\nWe have a custom component to use instead of Ember\'s\n<a href="https://emberjs.com/api/ember/release/classes/Ember.Templates.helpers/methods/input?anchor=input">{{input}}</a> so it follows a\nreactive programming model.</p>\n'); | ||
expect(component.description).toEqual(['<p>Text fields are the building blocks of forms.\nWe have a custom component to use instead of Ember’s\n<a href="https://emberjs.com/api/ember/release/classes/Ember.Templates.helpers/methods/input?anchor=input">{{input}}</a> so it follows a\nreactive programming model.</p>\n']); | ||
}); | ||
}); | ||
}); |
@@ -9,3 +9,3 @@ const parse = require('../../index'); | ||
expect(helper.access).toBe('private'); | ||
expect(helper.description).toBe('<p>This is a private helper.</p>\n'); | ||
expect(helper.description).toEqual(['<p>This is a private helper.</p>\n']); | ||
}); | ||
@@ -17,3 +17,3 @@ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>Default export description</p>\n'); | ||
expect(helper.description).toEqual(['<p>Default export description</p>\n']); | ||
expect(helper.parameters).toEqual({ | ||
@@ -37,3 +37,3 @@ positional: [ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>Named export description</p>\n'); | ||
expect(helper.description).toEqual(['<p>Named export description</p>\n']); | ||
expect(helper.parameters).toEqual({ | ||
@@ -57,3 +57,3 @@ positional: [ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>Default export description</p>\n'); | ||
expect(helper.description).toEqual(['<p>Default export description</p>\n']); | ||
expect(helper.dependencies.controllers).toEqual([]); | ||
@@ -83,3 +83,3 @@ expect(helper.dependencies.services).toEqual([ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>This helper has default values.</p>\n'); | ||
expect(helper.description).toEqual(['<p>This helper has default values.</p>\n']); | ||
@@ -102,3 +102,3 @@ expect(helper.parameters).toEqual({ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>This helper has optional named params.</p>\n'); | ||
expect(helper.description).toEqual(['<p>This helper has optional named params.</p>\n']); | ||
@@ -120,3 +120,3 @@ expect(helper.parameters).toEqual({ | ||
expect(helper.access).toBe('private'); | ||
expect(helper.description).toBe('<p>This is a private helper.</p>\n'); | ||
expect(helper.description).toEqual(['<p>This is a private helper.</p>\n']); | ||
}); | ||
@@ -128,3 +128,3 @@ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>Default export description</p>\n'); | ||
expect(helper.description).toEqual(['<p>Default export description</p>\n']); | ||
expect(helper.parameters).toEqual({ | ||
@@ -148,3 +148,3 @@ positional: [ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>Named export description</p>\n'); | ||
expect(helper.description).toEqual(['<p>Named export description</p>\n']); | ||
expect(helper.parameters).toEqual({ | ||
@@ -168,3 +168,3 @@ positional: [ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>Default export description</p>\n'); | ||
expect(helper.description).toEqual(['<p>Default export description</p>\n']); | ||
expect(helper.dependencies.controllers).toEqual([]); | ||
@@ -194,3 +194,3 @@ expect(helper.dependencies.services).toEqual([ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>This helper has default values.</p>\n'); | ||
expect(helper.description).toEqual(['<p>This helper has default values.</p>\n']); | ||
@@ -213,3 +213,3 @@ expect(helper.parameters).toEqual({ | ||
expect(helper.access).toBe('public'); | ||
expect(helper.description).toBe('<p>This helper has optional named params.</p>\n'); | ||
expect(helper.description).toEqual(['<p>This helper has optional named params.</p>\n']); | ||
@@ -216,0 +216,0 @@ expect(helper.parameters).toEqual({ |
@@ -9,5 +9,5 @@ const parse = require('../../index'); | ||
expect(service.access).toBe('public'); | ||
expect(service.description).toBe('<p>The Router service is the public API that provides component/view layer\naccess to the router.</p>\n'); | ||
expect(service.description).toEqual(['<p>The Router service is the public API that provides component/view layer\naccess to the router.</p>\n']); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49562
1356