Skip to content

Commit 4fb27d0

Browse files
author
Ian Egner
committed
Re-factor ajax calls in docs
1 parent 205cdec commit 4fb27d0

File tree

4 files changed

+17
-37
lines changed

4 files changed

+17
-37
lines changed

docs/js/docs.js

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
var pug = require('pug')
22

3-
/**
4-
* On page load fetch the parameters via ajax
5-
* and save them to window object. Set up mixins object
6-
*/
7-
$(document).ready(function () {
8-
$.get('docs/pug/_parameters.pug', function (response) {
9-
window.codeMixins = response
10-
})
11-
12-
window.mixins = {}
13-
})
14-
153
/**
164
* Show code blocks when a show code button is clicked
175
* No JS Fallback: ✅ // Don't show code buttons if js is disabled
@@ -48,13 +36,9 @@ function openCode (component) {
4836
$component.find('.result').first().appendTo($html)
4937
}
5038

51-
$.get(schema.mixinPath || 'pug/components/_' + component + '.pug', function (mixin) {
52-
window.mixins[component] = mixin
53-
54-
updateMixin(component, $component)
39+
updateMixin(component, $component)
5540

56-
$component.removeClass('loading')
57-
})
41+
$component.removeClass('loading')
5842
}
5943

6044
/**
@@ -136,7 +120,7 @@ function camelToTitle (camelCase) {
136120
*/
137121
function renderEnum (params) {
138122
return pug.render(
139-
window.codeMixins + '\n' +
123+
window.components._parameters + '\n' +
140124
'+docs_select(name, title, id, description, options, selected)',
141125
params
142126
)
@@ -149,7 +133,7 @@ function renderEnum (params) {
149133
*/
150134
function renderBoolean (params) {
151135
return pug.render(
152-
window.codeMixins + '\n' +
136+
window.components._parameters + '\n' +
153137
'+docs_radio(name, title, id, description, options, selected)',
154138
params
155139
)
@@ -162,7 +146,7 @@ function renderBoolean (params) {
162146
*/
163147
function renderString (params) {
164148
return pug.render(
165-
window.codeMixins + '\n' +
149+
window.components._parameters + '\n' +
166150
'+docs_text(name, title, id, description, value)',
167151
params
168152
)
@@ -175,7 +159,7 @@ function renderString (params) {
175159
*/
176160
function renderNumber (params) {
177161
return pug.render(
178-
window.codeMixins + '\n' +
162+
window.components._parameters + '\n' +
179163
'+docs_number(name, title, id, description, value, null, null, 1)',
180164
params
181165
)
@@ -188,7 +172,7 @@ function renderNumber (params) {
188172
*/
189173
function renderJSON (params) {
190174
return pug.render(
191-
window.codeMixins + '\n' +
175+
window.components._parameters + '\n' +
192176
'+docs_json(name, title, id, description)' + '\n' +
193177
' |' + JSON.stringify(params.value),
194178
params
@@ -320,7 +304,7 @@ function writeMixinCall (component, $component) {
320304
*/
321305
function renderMixin (component, mixinCall) {
322306
return pug.render(
323-
window.mixins[component] + '\n' + mixinCall,
307+
window.components[component].mixin + '\n' + mixinCall,
324308
{ pretty: ' ' }
325309
)
326310
}

gulpfile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ gulp.task('pug', function () {
149149
data.menuLinks = buildMenu(data.menu, data.components)
150150
}
151151

152+
data.components._parameters = fs.readFileSync('./docs/pug/_parameters.pug', 'utf-8')
153+
152154
var pkg = JSON.parse(fs.readFileSync('./package.json'))
153155
data.version = pkg.version
154156

@@ -240,6 +242,7 @@ function extractComponent (component) {
240242
if (schema.params || schema.mixinPath) {
241243
try {
242244
mixin = fs.readFileSync(schema.mixinPath || './pug/components/_' + component + '.pug') + '\n'
245+
schema.mixin = mixin
243246
} catch (e) {
244247
console.log(e)
245248
}

index.html

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
"gulp-sass-lint": "^1.3.2",
1717
"gulp-standard": "^9.0.0",
1818
"gulp-webserver": "^0.9.1",
19-
2019
"husky": "^0.13.2",
21-
2220
"pug-lint": "^2.3.0",
2321
"sass-lint": "^1.10.2",
2422
"standard": "^9.0.2"
@@ -40,15 +38,10 @@
4038
"scripts": {
4139
"build": "gulp build",
4240
"lint": "gulp lint",
43-
44-
45-
4641
"precommit": "npm test && gulp dist && git add dist && git add docs && git add index.html",
4742
"prepush": "npm test",
4843
"postmerge": "npm install && npm run build",
49-
50-
"test": "npm run lint",
51-
44+
"test": "npm run lint && npm run build",
5245
"start": "gulp"
5346
},
5447
"standard": {

0 commit comments

Comments
 (0)