1
1
import { html } from 'lit-element' ;
2
- import { unsafeHTML } from 'lit-html/directives/unsafe-html' ;
3
-
4
- import marked from 'marked' ;
5
2
6
3
// Templates
7
4
import expandedEndpointTemplate from '@/templates/expanded-endpoint-template' ;
8
5
import focusedEndpointTemplate from '@/templates/focused-endpoint-template' ;
6
+ import overviewTemplate from '@/templates/overview-template' ;
9
7
import endpointTemplate from '@/templates/endpoint-template' ;
10
8
import serverTemplate from '@/templates/server-template' ;
11
9
import securitySchemeTemplate from '@/templates/security-scheme-template' ;
12
- import componentsTemplate from '@/templates/components-template' ;
13
10
import headerTemplate from '@/templates/header-template' ;
14
11
import navbarTemplate from '@/templates/navbar-template' ;
15
12
import advancedSearchTemplate from '@/templates/advance-search-template' ;
16
13
17
14
import SetTheme from '@/utils/theme' ;
18
15
import { isValidHexColor } from '@/utils/color-utils' ;
19
16
20
- function infoDescriptionHeadingRenderer ( ) {
21
- const renderer = new marked . Renderer ( ) ;
22
- renderer . heading = ( ( text , level , raw , slugger ) => `<h${ level } class="observe-me" id="overview--${ slugger . slug ( raw ) } ">${ text } </h${ level } >` ) ;
23
- return renderer ;
24
- }
25
-
26
- /* eslint-disable indent */
27
-
28
- function overviewTemplate ( ) {
29
- return html `
30
- < div id ="overview " class ="observe-me ${ this . renderStyle === 'read' ? 'section-gap--read-mode' : ( this . renderStyle === 'focused' ? 'section-gap--read-mode' : 'section-gap' ) } ">
31
- < div id ="api-title " style ="font-size:32px ">
32
- ${ this . resolvedSpec . info . title }
33
- ${ ! this . resolvedSpec . info . version ? '' : html `
34
- < span style = 'font-size:var(--font-size-small);font-weight:bold '>
35
- ${ this . resolvedSpec . info . version }
36
- </ span > `
37
- }
38
- </ div >
39
- < div id ="api-info " style ="font-size:calc(var(--font-size-regular) - 1px); margin-top:8px; ">
40
- ${ this . resolvedSpec . info . contact ?. email
41
- ? html `< span > ${ this . resolvedSpec . info . contact . name || 'Email' } :
42
- < a href ="mailto: ${ this . resolvedSpec . info . contact . email } "> ${ this . resolvedSpec . info . contact . email } </ a >
43
- </ span > `
44
- : ''
45
- }
46
- ${ this . resolvedSpec . info . contact ?. url
47
- ? html `< span > URL: < a href ="${ this . resolvedSpec . info . contact . url } "> ${ this . resolvedSpec . info . contact . url } </ a > </ span > `
48
- : ''
49
- }
50
- ${ this . resolvedSpec . info . license
51
- ? html `< span > License:
52
- ${ this . resolvedSpec . info . license . url
53
- ? html `< a href ="${ this . resolvedSpec . info . license . url } "> ${ this . resolvedSpec . info . license . name } </ a > `
54
- : this . resolvedSpec . info . license . name
55
- } </ span > `
56
- : ''
57
- }
58
- ${ this . resolvedSpec . info . termsOfService
59
- ? html `< span > < a href ="${ this . resolvedSpec . info . termsOfService } "> Terms of Service</ a > </ span > `
60
- : ''
61
- }
62
- </ div >
63
- < div id ="api-description ">
64
- ${ this . resolvedSpec . info . description
65
- ? html `${ unsafeHTML ( `<div class="m-markdown regular-font">${ marked ( this . resolvedSpec . info . description , { renderer : infoDescriptionHeadingRenderer ( ) } ) } </div>` ) } `
66
- : ''
67
- }
68
- </ div >
69
- </ div >
70
- ` ;
71
- }
72
-
73
17
export default function mainBodyTemplate ( ) {
74
18
const newTheme = {
75
19
bg1 : isValidHexColor ( this . bgColor ) ? this . bgColor : '' ,
@@ -86,6 +30,7 @@ export default function mainBodyTemplate() {
86
30
navAccentColor : isValidHexColor ( this . navAccentColor ) ? this . navAccentColor : '' ,
87
31
} ;
88
32
33
+ /* eslint-disable indent */
89
34
return html `
90
35
${ this . theme === 'dark' ? SetTheme . call ( this , 'dark' , newTheme ) : SetTheme . call ( this , 'light' , newTheme ) }
91
36
@@ -107,48 +52,28 @@ export default function mainBodyTemplate() {
107
52
< main class ="main-content regular-font ">
108
53
< slot > </ slot >
109
54
< div class ="main-content-inner--${ this . renderStyle } -mode ">
110
- ${ this . loading === true ? html `< div class ="loader "> </ div > ` : '' }
111
- ${ this . loadFailed === true ? html `< div style ="text-align: center;margin: 16px; "> Unable to load the Spec</ div > ` : '' }
112
- ${ this . resolvedSpec
113
- ? html `
114
- ${ ( this . showInfo === 'false' || ! this . resolvedSpec . info )
115
- ? ''
116
- : this . renderStyle === 'focused'
117
- ? ( this . selectedContentId === 'overview' ? overviewTemplate . call ( this ) : '' )
118
- : overviewTemplate . call ( this )
119
- }
120
-
121
- ${ this . allowServerSelection === 'false'
122
- ? ''
123
- : this . renderStyle === 'focused'
124
- ? ( this . selectedContentId === 'api-servers' ? serverTemplate . call ( this ) : '' )
125
- : serverTemplate . call ( this )
126
- }
127
-
128
- ${ ( this . allowAuthentication === 'false' || ! this . resolvedSpec . securitySchemes )
129
- ? ''
130
- : this . renderStyle === 'focused'
131
- ? ( this . selectedContentId === 'authentication' ? securitySchemeTemplate . call ( this ) : '' )
132
- : securitySchemeTemplate . call ( this )
133
- }
134
- < div class ="operations-root " @click ="${ ( e ) => { this . handleHref ( e ) ; } } ">
135
- ${ this . resolvedSpec . tags
136
- ? this . renderStyle === 'read'
137
- ? expandedEndpointTemplate . call ( this )
138
- : this . renderStyle === 'focused'
139
- ? this . selectedContentId . startsWith ( 'cmp-' )
140
- ? componentsTemplate . call ( this )
141
- : focusedEndpointTemplate . call ( this )
142
- : endpointTemplate . call ( this )
143
- : ''
144
- }
145
- </ div >
146
-
147
- ${ this . showComponents === 'true' && this . renderStyle !== 'focused'
148
- ? componentsTemplate . call ( this )
149
- : '' }
150
- `
151
- : ''
55
+ ${ this . loading === true
56
+ ? html `< div class ="loader "> </ div > `
57
+ : html `
58
+ ${ this . loadFailed === true
59
+ ? html `< div style ="text-align: center;margin: 16px; "> Unable to load the Spec</ div > `
60
+ : html `
61
+ < div class ="operations-root " @click ="${ ( e ) => { this . handleHref ( e ) ; } } ">
62
+ ${ this . renderStyle === 'focused'
63
+ ? html `${ focusedEndpointTemplate . call ( this ) } `
64
+ : html `
65
+ ${ this . showInfo === 'true' ? overviewTemplate . call ( this ) : '' }
66
+ ${ this . allowServerSelection === 'true' ? serverTemplate . call ( this ) : '' }
67
+ ${ this . allowAuthentication === 'true' ? securitySchemeTemplate . call ( this ) : '' }
68
+ ${ this . renderStyle === 'read'
69
+ ? expandedEndpointTemplate . call ( this )
70
+ : endpointTemplate . call ( this )
71
+ }
72
+ `
73
+ }
74
+ </ div >
75
+ `
76
+ } `
152
77
}
153
78
</ div >
154
79
< slot name ="footer "> </ slot >
0 commit comments