github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/appengine/login/gitkit/tpl_creation.go (about)

     1  package gitkit
     2  
     3  /*
     4  	This is a TWO step template creation process
     5  
     6  	Hugo template is 'executed' into hugo-frame with gitkit body.
     7  	Result is then again 'executed' to a template containing gitkit params.
     8  
     9  */
    10  
    11  import (
    12  	"bytes"
    13  	"fmt"
    14  	"html/template"
    15  	"net/http"
    16  
    17  	"github.com/pbberlin/tools/net/http/loghttp"
    18  	"github.com/pbberlin/tools/net/http/tplx"
    19  )
    20  
    21  // Templates file path.
    22  const (
    23  	Headers = "\t" + `<script type="text/javascript"            src="//www.gstatic.com/authtoolkit/js/gitkit.js"></script>
    24  	<link   type="text/css" rel="stylesheet" href="//www.gstatic.com/authtoolkit/css/gitkit.css">`
    25  )
    26  
    27  func getHomeTpl(w http.ResponseWriter, r *http.Request) *template.Template {
    28  
    29  	lg, _ := loghttp.BuffLoggerUniversal(w, r)
    30  
    31  	bstpl := tplx.TemplateFromHugoPage(w, r)
    32  
    33  	b := new(bytes.Buffer)
    34  
    35  	fmt.Fprintf(b, tplx.ExecTplHelper(bstpl, map[string]interface{}{
    36  		// "HtmlTitle":       "{{ .HtmlTitle }}", // this seems to cause problems sometimes.
    37  		"HtmlTitle":       "Member Area",
    38  		"HtmlDescription": "", // reminder
    39  		"HtmlHeaders":     template.HTML(Headers),
    40  		"HtmlContent":     template.HTML(home1 + "\n<br><br>\n" + home2),
    41  	}))
    42  
    43  	intHomeTemplate, err := template.New("home").Parse(b.String())
    44  	lg(err)
    45  
    46  	return intHomeTemplate
    47  
    48  }
    49  
    50  func getWidgetTpl(w http.ResponseWriter, r *http.Request) *template.Template {
    51  
    52  	lg, _ := loghttp.BuffLoggerUniversal(w, r)
    53  
    54  	bstpl := tplx.TemplateFromHugoPage(w, r) // the jQuery irritates
    55  	// bstpl := tplx.HugoTplNoScript
    56  
    57  	b := new(bytes.Buffer)
    58  
    59  	fmt.Fprintf(b, tplx.ExecTplHelper(bstpl, map[string]interface{}{
    60  		// "HtmlTitle":       "{{ .HtmlTitle }}",  // it DOES cause some eternal loop. But why only here?
    61  		"HtmlTitle":       "GitKitWidget",
    62  		"HtmlDescription": "", // reminder
    63  		"HtmlHeaders":     template.HTML(Headers),
    64  		"HtmlContent":     template.HTML(widget),
    65  	}))
    66  
    67  	intGitkitTemplate, err := template.New("home").Parse(b.String())
    68  	lg(err)
    69  
    70  	return intGitkitTemplate
    71  
    72  }