~evanj/cms

ref: 8edd2c746f62d805e3176aebb05c281788e6c7c6 cms/internal/s/tmpl/tmpls_embed.go -rw-r--r-- 13.5 KiB
8edd2c74Evan M Jones Feat(css): Adding "mvp" css. 1 year, 9 months ago
                                                                                
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
// Code generated by "embed -pattern */* -id tmpls"; DO NOT EDIT.

package tmpl

var tmpls map[string]string

func init() {
	tmpls = make(map[string]string)

	tmpls["css/main.css"] = `body {
}

main { 
  max-width: 700px;
  margin: 0 auto;
}

input,
textarea { 
  display: block;
  box-sizing: border-box;
}

a,
input, 
button {
  cursor: pointer;
}

textarea { 
  width: 100%;
  resize: vertical;
  min-height: 250px;
}

.input-html,
.input-markdown { 
  display: block !important; /* tinymce hides this. */
  width: 0;
  height: 0;
  min-height: 0;
  resize: none;
  overflow: hidden;
  position: relative;
  left: 50%;
  top: 100px;
  margin: 0;
  padding: 0;
}

/* To match stylesheet. */

form > legend,
.tox.tox-tinymce { 
  margin-bottom: 16px;
}

details > form {
  margin-top: 16px;
  margin-bottom: 16px;
}

`

	tmpls["html/_footer.html"] = `<footer>
  <center>© 2015-2020 Evan Jones</center>
</footer>
`

	tmpls["html/_head.html"] = `<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="https://favicon.evanjon.es/255/0/0/32/favicon.ico" />
<link rel="stylesheet" href="https://andybrewer.github.io/mvp/mvp.css">
`

	tmpls["html/_header.html"] = `<header>
  <h1>CMS</h1>
  <p>An old-school CMS for most.</p>
</header>
`

	tmpls["html/content.html"] = `<!DOCTYPE html>
<html lang=en>

<head>
  {{ template "html/_head.html" }}
  <title>CMS | {{ .Space.Name }} | {{ .ContentType.Name }} | {{ (.Content.MustValueByName "name").Value }}</title>
</head>

<body>
  <style>{{ template "css/main.css" }}</style>

  <main>
    {{ template "html/_header.html" }}
    <hr/>
    <article>

      <h1>{{ .Space.Name }} > {{ .ContentType.Name }} > {{ (.Content.MustValueByName "name").Value }}</h1>

      <details>
        <summary>Update Content</summary>
        <form method=POST action='/content/update' enctype='multipart/form-data'>
          <input required type=hidden name=space value="{{ .Space.ID }}" />
          <input required type=hidden name=contenttype value="{{ .ContentType.ID }}" />
          <input required type=hidden name=content value="{{ .Content.ID }}" />

          {{ range .Content.Values }}

            <label>{{ .Name }}</label>

            {{ if eq .Type "StringSmall" }}
              <input value="{{ .Value }}" required type=text name="{{ .Type }}-{{ .ID }}" placeholder="{{ .Name }}" />
            {{ end }}

            {{ if eq .Type "StringBig" }}
              <textarea required type=text name="{{ .Type }}-{{ .ID }}" placeholder="{{ .Name }}">{{ .Value }}</textarea>
            {{ end }}

            {{ if eq .Type "InputHTML" }}
              <textarea class='input-html' value="{{ .Value }}" required type=text name="{{ .Type }}-{{ .ID }}" placeholder="{{ .Name }}">{{ .Value }}</textarea>
            {{ end }}

            {{ if eq .Type "InputMarkdown" }}
              <textarea class='input-markdown' value="{{ .Value }}" required type=text name="{{ .Type }}-{{ .ID }}" placeholder="{{ .Name }}">{{ .Value }}</textarea>
            {{ end }}

            {{ if eq .Type "File" }}
              <input value="{{ .Value }}" type=file name="{{ .Type }}-{{ .ID }}" multiple=false />
            {{ end }}

            {{ if eq .Type "Date" }}
              <input value="{{ .Value }}" required type=date name="{{ .Type }}-{{ .ID }}" placeholder="{{ .Name }}" />
            {{ end }}

          {{ end }}

          <input type=submit value=Update />
        </form>
      </details>

      <details>
        <summary>Delete Content</summary>
        <form method=POST action='/content/delete' enctype='multipart/form-data'>
          <input required type=hidden name=space value="{{ .Space.ID }}" />
          <input required type=hidden name=contenttype value="{{ .ContentType.ID }}" />
          <input required type=hidden name=content value="{{ .Content.ID }}" />
          <input type=submit value=Delete />
        </form>
      </details>

    </article>
    <hr/>
    {{ template "html/_footer.html" }}
  </main>
  <script src="//unpkg.com/tinymce@5.2.0/tinymce.min.js"></script>
  <script src="//unpkg.com/tinymce@5.2.0/plugins/textpattern/plugin.min.js"></script>
  <script>{{ template "js/content.js" }}</script>
</body>

</html>
`

	tmpls["html/contenttype.html"] = `<!DOCTYPE html>
<html lang=en>

<head>
  {{ template "html/_head.html" }}
  <title>CMS | {{ .Space.Name }} | {{ .ContentType.Name }}</title>
</head>

<body>
  <style>{{ template "css/main.css" }}</style>

  <main>
    {{ template "html/_header.html" }}
    <hr/>
    <article>

      <h1>{{ .Space.Name }} > {{ .ContentType.Name }}</h1>

      <details>
        <summary>Create a {{ .ContentType.Name }} Content</summary>
        <form method=POST action='/content/new' enctype='multipart/form-data'>
          <input required type=hidden name=space value="{{ .Space.ID }}" />
          <input required type=hidden name=contenttype value="{{ .ContentType.ID }}" />
          <br/>

          {{ range .ContentType.Fields }}

            <label>{{ .Name }}</label>

            {{ if eq .Type "StringSmall" }}
              <input required type=text name="{{ .Type }}-{{ .Name }}" placeholder="{{ .Name }}" />
            {{ end }}

            {{ if eq .Type "StringBig" }}
              <textarea required type=text name="{{ .Type }}-{{ .Name }}" placeholder="{{ .Name }}" ></textarea>
            {{ end }}

            {{ if eq .Type "InputHTML" }}
              <textarea class='input-html' required type=text name="{{ .Type }}-{{ .Name }}" placeholder="{{ .Name }}" ></textarea>
            {{ end }}

            {{ if eq .Type "InputMarkdown" }}
              <textarea class='input-markdown' required type=text name="{{ .Type }}-{{ .Name }}" placeholder="{{ .Name }}" ></textarea>
            {{ end }}

            {{ if eq .Type "File" }}
              <input required type=file name="{{ .Type }}-{{ .Name }}" multiple=false />
            {{ end }}

            {{ if eq .Type "Date" }}
              <input required type=date name="{{ .Type }}-{{ .Name }}" placeholder="{{ .Name }}" />
            {{ end }}

          {{ end }}

          <input type=submit value=Create />
        </form>
      </details>

      <h2>Browse {{ .ContentType.Name }} Content</h2>
      {{ if .ContentList }}
        <ul>
          {{ range .ContentList }}
            <li> 
              <a href='/content/{{ $.Space.ID }}/{{ $.ContentType.ID }}/{{ .ID }}'>
                {{ (.MustValueByName "name").Value }}
              </a>
            </li>
          {{ end }}
        </ul>
      {{ else }}
        <p>No content has been created with a content type of {{ .ContentType.Name }}</p>
      {{ end }}

    </article>
    <hr/>
    {{ template "html/_footer.html" }}
  </main>
  <script src="//unpkg.com/tinymce@5.2.0/tinymce.min.js"></script>
  <script src="//unpkg.com/tinymce@5.2.0/plugins/textpattern/plugin.min.js"></script>
  <script>{{ template "js/content.js" }}</script>
</body>

</html>
`

	tmpls["html/index.html"] = `<!DOCTYPE html>
<html lang=en>

<head>
  {{ template "html/_head.html" }}
  <title>CMS</title>
</head>

<body>
  <style>{{ template "css/main.css" }}</style>

  <main>
    {{ template "html/_header.html" }}
    <hr/>
    <article>

      <h1>Home</h1>

      {{ if .User }}

        <details>
          <summary>Create a New Space</summary>
          <form method=POST action='/space/new' enctype='multipart/form-data'>
            <input required type=text name=name placeholder=name />
            <input required type=text name=desc placeholder=description />
            <input type=submit value=Create />
          </form>
        </details>

        <details>
          <summary>Logout</summary>
          <form method=POST action='/user/logout' enctype='multipart/form-data'>
            <input type=submit value=Logout />
          </form>
        </details>

        <br/>

        <h2>Available Spaces</h2>
        {{ if .Spaces }}
          <ul>
            {{ range .Spaces }}
            <li><a href="/space/{{ .ID }}">{{ .Name }}</a></li>
            {{ end }}
          </ul>
        {{ else }}
          <p>You haven't created any spaces yet.</p>
        {{ end }}

      {{ else }}

        <details>
          <summary>Login</summary>
          <form method=POST action='/user/login' enctype='multipart/form-data'>
            <input autocomplete=on required type=text name=username placeholder=username autofocus />
            <input autocomplete=on required type=password name=password placeholder=password />
            <input type=submit value=Login />
          </form>
        </details>

        <details>
          <summary>Signup</summary>
          <form method=POST action='/user/signup' enctype='multipart/form-data'>
            <input autocomplete=on required type=text name=username placeholder=username autofocus />
            <input autocomplete=on required type=password name=password placeholder=password />
            <input autocomplete=on required type=password name=verify placeholder=verify />
            <input type=submit value=Signup />
          </form>
        </details>

      {{ end }}

    </article>
    <hr/>
    {{ template "html/_footer.html" }}
  </main>
</body>

</html>
`

	tmpls["html/space.html"] = `<!DOCTYPE html>
<html lang=en>

<head>
  {{ template "html/_head.html" }}
  <title>CMS | {{ .Space.Name }}</title>
</head>

<body>
  <style>{{ template "css/main.css" }}</style>

  <main>
    {{ template "html/_header.html" }}
    <hr/>
    <article>

      <h1>{{ .Space.Name }}</h1>

      <details>
        <summary>Create Content Type</summary>
        <form method=POST action='/contenttype/new' enctype='multipart/form-data'>
          <input required type=hidden name=space value="{{ .Space.ID }}" />
          <input required type=text name=name placeholder="content type name" />
          <legend>Fields</legend>
          <div id='first-fieldset'>
            <input readonly="readonly" required type=text name="field_name_1" value="name" />
            <select readonly="readonly" required name="field_type_1">
              <option disabled value>Field Type</option>
              <option selected value="StringSmall">String Small</option>
              <option disabled value="StringBig">String Big</option>
              <option disabled value="InputHTML">HTML</option>
              <option disabled value="InputMarkdown">Markdown</option>
              <option disabled value="File">File</option>
              <option disabled value="Date">Date</option>
            </select>
          </div>
          <button id='add-fieldbtn'>Add Another Field</button>
          <input type=submit value=Create />
        </form>
      </details>

      <h2>Browse Content By Type</h2>
      {{ if .ContentTypes }}
        <ul>
          {{ range .ContentTypes }}
            <li><a href='/contenttype/{{ $.Space.ID }}/{{ .ID }}'>{{ .Name }}</a></li>
          {{ end }}
        </ul>
      {{ else }}
        <p>You haven't created any content types yet.</p>
      {{ end }}

    </article>
    <hr/>
    {{ template "html/_footer.html" }}
  </main>
  <script>{{ template "js/space.js" }}</script>
</body>

</html>
`

	tmpls["js/content.js"] = `// Setup inputs for content create/update.
(function() { 

  // HTML
  tinymce.init({ 
    selector: 'textarea.input-html',
    // statusbar: false,
    setup: function(item) { 
      item.on('change', function() { 
        item.targetElm.value = item.getContent()
      })
    }
  })

  // MARKDOWN
  tinymce.init({
    selector: "textarea.input-markdown",
    plugin: 'textpattern',
    menubar: false,
    toolbar: 'undo redo',
    // statusbar: false,
    textpattern_patterns: [
      {start: '*', end: '*', format: 'italic'},
      {start: '**', end: '**', format: 'bold'},
      {start: '#', format: 'h1'},
      {start: '##', format: 'h2'},
      {start: '###', format: 'h3'},
      {start: '####', format: 'h4'},
      {start: '#####', format: 'h5'},
      {start: '######', format: 'h6'},
      {start: '1. ', cmd: 'InsertOrderedList'},
      {start: '* ', cmd: 'InsertUnorderedList'},
      {start: '- ', cmd: 'InsertUnorderedList'}
    ],
    setup: function(item) { 
      item.on('change', function() { 
        item.targetElm.value = item.getContent()
      })
    }
  });

})();
`

	tmpls["js/space.js"] = `// Add more fields to space create.
(function() { 
  var addFieldBtn = document.getElementById('add-fieldbtn')
  var i = 1
  addFieldBtn.addEventListener('click', function(e) { 
    i++
    e.preventDefault()
    e.stopPropagation()
    var el = document.createElement('div')
    el.innerHTML = ` + "`" + `
      <div>
        <input required type=text name="field_name_${i}" placeholder="field name" />
        <select required name="field_type_${i}">
          <option disabled selected value>Field Type</option>
          <option value="StringSmall">String Small</option>
          <option value="StringBig">String Big</option>
          <option value="InputHTML">HTML</option>
          <option value="InputMarkdown">Markdown</option>
          <option value="File">File</option>
          <option value="Date">Date</option>
        </select>
        <button id='remove-fieldbtn_${i}'>Remove Field</button>
      </div>
    ` + "`" + `
    addFieldBtn.parentNode.insertBefore(el, addFieldBtn)
    var removeFieldBtn = document.getElementById(` + "`" + `remove-fieldbtn_${i}` + "`" + `)
    removeFieldBtn.addEventListener('click', function(e) { 
      i--
      e.preventDefault()
      e.stopPropagation()
      el.parentNode.removeChild(el)
    })
  })
})();
`

}

func Get(name string) (string, bool) {
	val, ok := tmpls[name]
	return val, ok
}

func Must(name string) string {
	val, _ := tmpls[name]
	return val
}