Skip to content

Commit

Permalink
move "docs" defaults to build.api.js
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 13, 2019
1 parent 126aff8 commit 7707ffc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 33 deletions.
33 changes: 3 additions & 30 deletions app/bin/quasar-docs
Original file line number Diff line number Diff line change
Expand Up @@ -52,40 +52,13 @@ function docs (api, supplier, openOptions) {
let route, page, apiAnchor, url

if (supplier === void 0) {
const quasarRoutes = {
component: 'vue-components',
directive: 'vue-directives',
plugin: 'quasar-plugins'
}

if (api.docs) {
page = api.docs.page
route = api.docs.route
apiAnchor = api.docs.apiAnchor
}

if (page === void 0) {
if (item.startsWith('Q')) {
page = item.slice(1)
}
else {
page = item
}
// kebab-case
page = page.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/[\s_]+/g, '-').toLowerCase()
}

if (route === void 0) {
route = quasarRoutes[api.type]
}
page = api.docs.page
route = api.docs.route
apiAnchor = api.docs.apiAnchor

url = quasarBaseUrl + route + '/' + page

if (argv.api) {
if (apiAnchor === void 0) {
apiAnchor = api.type === 'directive' ? 'API' : item + '-API'
}

if (apiAnchor === false) {
log(`${item} docs page does not contain a API anchor. Opening default page...`)
}
Expand Down
31 changes: 28 additions & 3 deletions ui/build/build.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,34 @@ function parseAPI (file, apiType) {
return api
}

function orderAPI (api, apiType) {
const routes = {
component: 'vue-components',
directive: 'vue-directives',
plugin: 'quasar-plugins'
}

function getPage (fileName) {
let page
if (fileName.startsWith('Q')) {
page = fileName.slice(1)
} else {
page = fileName
}
// kebab-case
return page.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/[\s_]+/g, '-').toLowerCase()
}

function orderAPI (api, apiType, fileName) {
let docs = api.docs || {}
docs.page = docs.page || getPage(fileName)
docs.route = docs.route || routes[apiType]
if (docs.apiAnchor === void 0) {
docs.apiAnchor = apiType === 'directive' ? 'API' : fileName + '-API'
}

const ordered = {
type: apiType
type: apiType,
docs
}

topSections[apiType].forEach(section => {
Expand All @@ -415,7 +440,7 @@ function fillAPI (apiType) {
name = path.basename(file),
filePath = path.join(dest, name)

const api = orderAPI(parseAPI(file, apiType), apiType)
const api = orderAPI(parseAPI(file, apiType), apiType, name.replace('.json', ''))

// copy API file to dest
writeFile(filePath, JSON.stringify(api, null, 2))
Expand Down

0 comments on commit 7707ffc

Please sign in to comment.