]> Cypherpunks repositories - gostls13.git/commit
html/template: wraps package template instead of exposing func Escape
authorMike Samuel <mikesamuel@gmail.com>
Fri, 4 Nov 2011 17:09:21 +0000 (13:09 -0400)
committerMike Samuel <mikesamuel@gmail.com>
Fri, 4 Nov 2011 17:09:21 +0000 (13:09 -0400)
commita5291099d2a79c8cc85c331dfd08ad42e92ce063
tree1de02862fc2082905aa97ef16aae0532ecfb8c4d
parentb14ee23f9b85b6c838207ccc2d67287fb0e56bb4
html/template: wraps package template instead of exposing func Escape

This does escaping on first execution.

template.go defines the same interface elements as package template.
It requires rather more duplication of code than I'd like, but I'm
not clear how to avoid that.

Maybe instead of

    mySet.ParseGlob(...)
    template.ParseSetGlob(...)
    mySet.ParseFiles(...)
    mySet.ParseTemplateFiles(...)
    template.ParseTemplateFiles(...)

we combine these into a fileset abstraction that can be wrapped

    var fileset template.FileSet
    fileset.Glob(...)  // Load a few files by glob
    fileset.Files(...)  // Load a few {{define}}d files
    fileset.TemplateFiles(...)  // Load a few files as template bodies
    fileset.Funcs(...)  // Make the givens func available to templates
    // Do the parsing.
    set, err := fileset.ParseSet()
    // or set, err := fileset.ParseInto(set)

or provide an interface that can receive filenames and functions and
parse messages:

    type Bundle interface {
      TemplateFile(string)
      File(string)
      Funcs(FuncMap)
    }

and define template.Parse* to handle the file-system stuff and send
messages to a bundle:

    func ParseFiles(b Bundle, filenames ...string)

R=r, r
CC=golang-dev
https://golang.org/cl/5270042
src/pkg/html/template/Makefile
src/pkg/html/template/clone_test.go
src/pkg/html/template/content_test.go
src/pkg/html/template/doc.go
src/pkg/html/template/error.go
src/pkg/html/template/escape.go
src/pkg/html/template/escape_test.go
src/pkg/html/template/template.go [new file with mode: 0644]