forked from adonisjs/legacy.adonisjs.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlight.js
More file actions
110 lines (95 loc) · 2.2 KB
/
highlight.js
File metadata and controls
110 lines (95 loc) · 2.2 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const higlight = require('./extensions/highlight')
const args = process.argv.splice(2)
function wrapPre (code) {
return `<pre><code>${code}</code></pre>`
}
if (args[0] === 'routes') {
console.log(wrapPre(higlight(`/**
* Inline Route Handler
*/
Route.get('/', async ({ view }) => {
return view.render('home')
})
/**
* Using Controller
*/
Route.get('posts', 'PostsController.index')
Route.post('posts', 'PostsController.store')`,
'language-ts'
)))
}
if (args[0] === 'controllers') {
console.log(wrapPre(higlight(`import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import Post from 'App/Models/Post'
export default class PostsController {
/**
* Return all posts
*/
public async index () {
return Post.all()
}
/**
* Create a new post
*/
public async store ({ request }: HttpContextContract) {
const data = request.only([ 'title', 'body' ])
const post = await Post.create(data)
return post
}
}`,
'language-ts'
)))
}
if (args[0] === 'models') {
console.log(wrapPre(higlight(`import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm'
export default class Post extends BaseModel {
@column({ isPrimary: true })
public id: number
@column()
public title: string
@column()
public body: string
}`,
'language-ts'
)))
}
if (args[0] === 'edge:conditionals') {
console.log(wrapPre(higlight(`<body>
@if(user)
<p> Hello {{ user.username }} </p>
@endif
</body>`,
'language-edge'
)))
}
if (args[0] === 'edge:mmustache') {
console.log(wrapPre(higlight(`<body>
{{
user.earnings.map((earning) => {
return earning * 100
}).join(',')
}}
</body>`,
'language-edge'
)))
// console.log(higlight(`user.earnings.map((earning) => {
// return earning * 100
// }).join(',')`, 'language-js'))
}
if (args[0] === 'edge:components') {
console.log(wrapPre(higlight(`<body>
@component('components/modal', { title: 'Are you sure?' })
// highlight-start
@slot('body')
<p> Select yes, will delete the blog post permanently </p>
@endslot
@slot('actions')
<a href=""> Cancel </a>
<a href=""> Yes, delete it </a>
@endslot
// highlight-end
@endcomponent
</body>`,
'language-edge'
)))
}