aboutsummaryrefslogtreecommitdiff
path: root/filehtml.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2019-04-19 13:16:06 +0700
committerShulhan <ms@kilabit.info>2019-04-19 13:18:19 +0700
commit7912eac3d19b08c05220c9d65c0ad21b83c25fbe (patch)
tree26cd83238251ca689cd83a49481f5d584aad0373 /filehtml.go
downloadciigo-7912eac3d19b08c05220c9d65c0ad21b83c25fbe.tar.xz
ciigo: program to write static web server using asciidoc markup language
This first commit provide the following features, * automatically regenerate asciidoc files on development, * generate static and HTML files into Go source code, and * running binary with embedded contents
Diffstat (limited to 'filehtml.go')
-rw-r--r--filehtml.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/filehtml.go b/filehtml.go
new file mode 100644
index 0000000..766fbed
--- /dev/null
+++ b/filehtml.go
@@ -0,0 +1,51 @@
+// Copyright 2019, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package ciigo
+
+import (
+ "html/template"
+ "strings"
+)
+
+//
+// fileHTML represent an HTML metadata for header and its body.
+//
+type fileHTML struct {
+ Title string
+ Styles []string
+ Body template.HTML
+
+ path string
+ rawBody strings.Builder
+}
+
+//
+// reset all fields to its empty values.
+//
+func (fhtml *fileHTML) reset() {
+ fhtml.Title = ""
+ fhtml.Styles = fhtml.Styles[:0]
+ fhtml.Body = template.HTML("")
+
+ fhtml.path = ""
+ fhtml.rawBody.Reset()
+}
+
+//
+// unpackAdoc convert the asciidoc metadata to its HTML representation and
+// rawBody to template.HTML.
+//
+func (fhtml *fileHTML) unpackAdoc(fa *fileAdoc) {
+ for k, v := range fa.metadata {
+ switch k {
+ case "doctitle":
+ fhtml.Title = v.(string)
+ case "stylesheet":
+ fhtml.Styles = append(fhtml.Styles, v.(string))
+ }
+ }
+
+ fhtml.Body = template.HTML(fhtml.rawBody.String()) // nolint:gosec
+}