github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/appengine/login/gitkit1/tpl_creation.go (about) 1 package gitkit1 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, title, body string) *template.Template { 28 29 if body == "" { 30 body = IDCardHTML + UserInfoHTML 31 } 32 33 lg, _ := loghttp.BuffLoggerUniversal(w, r) 34 35 bstpl := tplx.TemplateFromHugoPage(w, r) 36 37 b := new(bytes.Buffer) 38 39 fmt.Fprintf(b, tplx.ExecTplHelper(bstpl, map[string]interface{}{ 40 // "HtmlTitle": "{{ .HtmlTitle }}", // this seems to cause problems sometimes. 41 "HtmlTitle": title, 42 "HtmlDescription": "", // reminder 43 "HtmlHeaders": template.HTML(Headers), 44 "HtmlContent": template.HTML(body), 45 })) 46 47 intHomeTemplate, err := template.New("home").Parse(b.String()) 48 lg(err) 49 50 return intHomeTemplate 51 52 } 53 54 func GetIDCardTpl(w http.ResponseWriter, r *http.Request, u *User, 55 argSignoutURL string, argRedirectSuccess string) string { 56 57 b := new(bytes.Buffer) 58 59 if argRedirectSuccess != "" { 60 argRedirectSuccess = "?mode=select&user=wasNil&red=" + argRedirectSuccess 61 } 62 63 fmt.Fprintf(b, tplx.ExecTplHelper(IDCardHTML, map[string]interface{}{ 64 "WidgetURL": WidgetSigninAuthorizedRedirectURL + argRedirectSuccess, 65 "SignOutURL": argSignoutURL, 66 "User": u, 67 // "CookieDump": template.HTML(htmlfrag.CookieDump(r)), 68 })) 69 70 return b.String() 71 } 72 73 func GetWidgetTpl(w http.ResponseWriter, r *http.Request, title string) *template.Template { 74 75 lg, _ := loghttp.BuffLoggerUniversal(w, r) 76 77 bstpl := tplx.TemplateFromHugoPage(w, r) // the jQuery irritates 78 // bstpl := tplx.HugoTplNoScript 79 80 b := new(bytes.Buffer) 81 fmt.Fprintf(b, tplx.ExecTplHelper(bstpl, map[string]interface{}{ 82 // "HtmlTitle": "{{ .HtmlTitle }}", // it DOES cause some eternal loop. But why only here? 83 "HtmlTitle": title, 84 "HtmlDescription": "", // reminder 85 "HtmlHeaders": template.HTML(Headers), 86 "HtmlContent": template.HTML(widgetHTML), 87 })) 88 89 intGitkitTemplate, err := template.New("widg").Parse(b.String()) 90 lg(err) 91 92 return intGitkitTemplate 93 94 }