-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
48 lines (40 loc) · 1.11 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
var app = require('koa')()
var router = require('koa-router')()
var handlebars = require("koa-handlebars")
router.get('/', function *(next) {
this.body = 'hello'
})
router.get('/api/v1/demo.html', function *(next) {
if (!this.query.components){
this.body = 'No Component Specified~'
return
}
this.query.components = this.query.components.split(',').map(parse)
this.query.filters = this.query.filters ? this.query.filters.split(',').map(parse) : []
this.query.script = this.query.script ? this.query.script.match(/export default \{([\s\S]*?)\}$/)[1]:''
yield this.render("code", {
title: "demo",
data: this.query
});
})
app.use(handlebars({
helpers: {
capitalizeFirstLetter: capitalizeFirstLetter
}
}))
app
.use(router.routes())
.use(router.allowedMethods())
app.listen(7001)
function capitalizeFirstLetter (string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
function toDash (str) {
return str.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();})
}
function parse(one){
return {
tag: toDash(capitalizeFirstLetter(one)).slice(1),
umd: 'vux'+one
}
}