Skip to content

Commit

Permalink
updated: [sitekit]use go:embed in template entry(main.html)
Browse files Browse the repository at this point in the history
  • Loading branch information
xc committed Aug 9, 2021
1 parent 315b947 commit aac0e2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
10 changes: 7 additions & 3 deletions sitekit/sitekit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package sitekit

import (
"context"
_ "embed"
"errors"
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"

Expand All @@ -21,6 +21,9 @@ import (
"github.com/gorilla/mux"
)

//go:embed templates/main.html
var mainTemplate []byte

var siteSettings = map[string]SiteSettings{}
var siteIdentifiers = []string{}

Expand Down Expand Up @@ -249,8 +252,9 @@ func Output(w io.Writer, variables map[string]interface{}, ctx context.Context)
if log.GetContextInfo(ctx).CanDebug() {
variables["debug"] = true
}
gopath := os.Getenv("GOPATH")
tpl := pongo2.Must(pongo2.FromCache(gopath + "/src/github.com/digimakergo/digimaker/sitekit/templates/main.html")) //todo: use configuration

tpl := pongo2.Must(pongo2.FromBytes(mainTemplate))
//todo: support import in template - hard in go embed?

info := RequestInfo{Context: ctx, Site: variables["site"].(string), SitePath: variables["sitepath"].(string)}

Expand Down
27 changes: 25 additions & 2 deletions sitekit/templates/main.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
{%import "micros.html" output_content,output_field,output%}

{% comment %}
Available varilables:

Expand All @@ -16,6 +14,31 @@
- parameter given in handler/controller
{% endcomment %}

{% macro output_content( content, viewmode) export%}
{%with dm.tpl_content(content, viewmode) as path%}
{% if path=="" %}
{OVERRIDE NOT FOUND, PLEASE OVERRIDE. {{content.ID}},{{content.Name}},{{viewmode}}}
{%else%}
{% if debug %}<!-- {{path}} -->{%endif%}
{%include path|dm_abs_path %}
{% endif %}
{%endwith%}
{% endmacro %}

{% macro output_field( field ) export%}
{%with "fieldtype/"|add:field.Type()|add:".html"|dm_abs_path:"github.com/digimakergo/digimaker/sitekit" as path%}
{%include path with field=field%}
{%endwith%}
{% endmacro %}

{#include path from override #}
{% macro output( path, match_data ) export%}
{#todo: match it#}
{%with "../default/"|add:path|add:".html" as template%}
{%include template%}
{%endwith%}
{% endmacro %}

{%if error != nil %}
{{error}} {%comment%} todo: use include {%endcomment%}
{%else%}
Expand Down
24 changes: 0 additions & 24 deletions sitekit/templates/micros.html

This file was deleted.

0 comments on commit aac0e2b

Please sign in to comment.