bluekeyes / templatetree Goto Github PK
View Code? Open in Web Editor NEWSimple template inheritance with standard Go templates
License: MIT License
Simple template inheritance with standard Go templates
License: MIT License
The parse functions should options to configure things that are either not currently supported or are mandatory arguments:
nil
)partial
function that can render dynamically selected named templates defined in the same text.Template
Go 1.16 introduced the io/fs
package and the fs.FS
interface. I invented my own version of this in ca13449, but it would be nice to support the official thing now that it's available.
I think this is best implemented by removing the existing File
type and parse methods and replacing them with the new fs
types, then making a 0.3.0 release that requires Go 1.16 and breaks the API.
When executing a template via ExecuteTemplate
errors are reported as coming from the base cloned template. Perform the same error mangling that we do for parse errors on execution.
Coming back to this library to add io/fs
support left me with some ideas to change the API:
File
; either use fs.File
or take a map[string]string
Load*
functions; everything should be Parse*
On the last point, I'm thinking about defining:
type Template interface {
Name() string
Execute(io.Writer, interface{}) error
}
type Tree map[string]Template
The concrete types in a Tree
would be either text/template.Template
or html/template.Template
depending on parse options. Internally, I think most things would take a Template
and then type assert / cast to concrete types as needed.
The main problem I see is this implies clients could provide their own Template
implementations, which would break everything that assumes there are only two standard library implementations.
Because of that, it might make sense to expose something like the currently-internal template
interface that defines all necessary methods and use that. This requires an adapter for the standard types because many of the methods return their own type for chaining.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.