-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebdash-readme-preview.html
108 lines (90 loc) · 2.49 KB
/
webdash-readme-preview.html
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
<link rel="import" href="/bower_components/polymer/polymer-element.html">
<link rel="import" href="/bower_components/paper-spinner/paper-spinner.html">
<link rel="import" href="/bower_components/empty-state-webdash/empty-state-webdash.html">
<dom-module id="webdash-readme-preview">
<template>
<link rel="stylesheet" href="/bower_components/highlight-js/src/styles/solarized-dark.css">
<style>
:host {
display: block;
}
#preview {
padding: 0 20px;
}
#preview img {
max-width: 100%;
}
#preview pre,
#preview code {
max-width: 100%;
white-space: pre-wrap;
word-break: keep-all;
}
#preview pre {
background-color: #022B36;
padding: 20px;
border-radius: 5px;
}
#preview a {
color: var(--brand);
}
#preview a:hover {
color: var(--accent);
}
a {
color: inherit;
}
#spinner {
display: flex;
justify-content: center;
align-items: center;
}
#spinner paper-spinner[active] {
margin-top: 50px;
}
</style>
<template is="dom-if" if="{{emptyState}}">
<empty-state-webdash title="No README.md found">
Add a
<strong>README.md</strong> file at the root of your project to start using this plugin.
</empty-state-webdash>
</template>
<div id="preview">
</div>
<div id="spinner">
<paper-spinner active$="{{loading}}"></paper-spinner>
</div>
</template>
<script>
class WebdashReadmePreview extends Polymer.Element {
static get is() { return 'webdash-readme-preview'; }
constructor() {
super();
this.loading = true;
this.emptyState = false;
}
ready() {
super.ready();
this.backend = new Backend(WebdashReadmePreview.is);
this.getManifest();
}
getManifest() {
this.backend.get('readme-html').then(data => {
if (!data || !data.result || !data.result.html) {
this.emptyState = true;
return false;
}
const html = data.result.html;
this.$.preview.innerHTML = html;
})
.catch(error => {
console.log('there was an error', error);
})
.finally(() => {
this.loading = false;
});
}
}
window.customElements.define(WebdashReadmePreview.is, WebdashReadmePreview);
</script>
</dom-module>