Use both "text/template" & "html/template" together under a common umbrella.
Shall be written another day :-)
Package template implements the interface common to the standard packages
"text/template" and "html/template" as type Template.
Thus, it exploits the fact, that
package `html/template` provides the same interface as package `text/template`
and should be used instead of `text/template` whenever the output is HTML
as it automatically secures HTML output against certain attacks.
as said in go doc text/template and go doc html/template.
All methods and all package level functions are forewarded.
Instead of a single New(name) this package unsurprisingly provides
two constructors:
-
template.Text(name)& -
template.HTML(name).
Note: The package level functions ParseFiles & ParseGlob became
-
ParseTextFiles/ParseHTMLfileresp. -
ParseTextGlob/ParseHTMLglob.
Thus, the exported type Template represents the template used,
be it html or text.
Also the type FuncMap is forwarded.
Note: Clients in need to access any other type
-
such as
ExecError(from"text/template") or -
data types such as
HTML,CSS,JSand friends -
as well as
ErrorandErrorCode(from"html/template")
are requested to use the respective standard package directly for access to the error and data types.
For example escape_test.go uses
import( data "html/template" )
and refers to
data.HTML, data.CSS, data.JS ...
later.
doc.gojust documents the package (as quoted above) forgo doc github.com/GoLangsam/templatetemplate.godefines the interface typeTemplate(and the convenient wrapperMustand the ubiquous typeFuncMap)forward.goforwards package level functions. It'is simply taken from"html/template"as noted inside.wrapTemplateText.goandwrapTemplateHTML.godefine respective (private) implementation types, foreward the methods (if need) and theParse...functions. Intentionally they are as similar possible.
All *_test.go files from both standard packages are used! (Except as noted below.)
Adjusted are just things such as:
- package declarations
template=>template_test- in order to avoid spurious bug: duplicate flag definition
debug
- imports
"text/template"resp."html/template"=>"github.com/GoLangsam/template"
- references to type
Template*Template=>Template
- constructors
New=>Textresp.HTML
- the global
Parse-functionstemplate.Parse...=>template.ParseText...resp.template.ParseHTML...
- data types from
"html/template"- imported as
data, and types used accordingly, e.g. template.HTML=>data.HTML
- imported as
- few portions are deactivated / commented, as they require internals of the underlying package
css_test.go,html_test.go,js_test.gourl_test.goand from"html/template"are entirely omitted for same reason
- misspellings: Cincinatti => Cincinnati
- in order to make Go Report Card more happy :-)
As of now, no additional tests are provided. The author could not think of anything reasonable yet.
Your suggestions, remarks, questions and/or contributions are welcome ;-)
Hey dude! Help me out for a couple of 🍻!