Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(27)

Issue 4808089: code review 4808089: exp/template/html: New package with a toy template tran... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
13 years, 7 months ago by MikeSamuel
Modified:
13 years, 7 months ago
Reviewers:
CC:
rsc, r, nigeltao, r2, golang-dev
Visibility:
Public.

Description

exp/template/html: New package with a toy template transformation. func Reverse(*Template) *Template returns a template that produces the reverse of the original for any input. Changes outside exp/template/html include: - Adding a getter for a template's FuncMap so that derived templates can inherit function definitions. - Exported one node factory function, newIdentifier. Deriving tempaltes requires constructing new nodes, but I didn't export all of them because I think shallow copy functions might be more useful for this kind of work. - Bugfix: Template's Name() method ignores the name field so template.New("foo") is a nil dereference instead of "foo". Caveats: Reverse is a toy. It is not UTF-8 safe, and does not preserve order of calls to funcs in FuncMap. For context, see http://groups.google.com/group/golang-nuts/browse_thread/thread/e8bc7c771aae3f20/b1ac41dc6f609b6e?lnk=gst

Patch Set 1 #

Patch Set 2 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 5 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Patch Set 6 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Patch Set 7 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Total comments: 25

Patch Set 8 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Total comments: 18

Patch Set 9 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Total comments: 2

Patch Set 10 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Total comments: 1

Patch Set 11 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Patch Set 12 : diff -r 48ec728c62b0 https://go.googlecode.com/hg/ #

Total comments: 2
Unified diffs Side-by-side diffs Delta from patch set Stats (+200 lines, -5 lines) Patch
M src/pkg/Makefile View 1 1 chunk +1 line, -0 lines 0 comments Download
A src/pkg/exp/template/html/Makefile View 1 2 3 4 1 chunk +11 lines, -0 lines 0 comments Download
A src/pkg/exp/template/html/reverse.go View 1 2 3 4 5 6 7 8 9 10 11 1 chunk +134 lines, -0 lines 2 comments Download
A src/pkg/exp/template/html/reverse_test.go View 1 2 3 4 5 6 7 8 1 chunk +48 lines, -0 lines 0 comments Download
M src/pkg/exp/template/parse.go View 1 2 3 4 5 6 7 1 chunk +1 line, -1 line 0 comments Download
M src/pkg/exp/template/parse/node.go View 1 2 3 4 5 6 7 2 chunks +4 lines, -3 lines 0 comments Download
M src/pkg/exp/template/parse/parse.go View 1 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 18
MikeSamuel
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://go.googlecode.com/hg/
13 years, 7 months ago (2011-08-10 19:24:05 UTC) #1
rsc
Do you avoid the accessors if you just edit the template in place? That's what ...
13 years, 7 months ago (2011-08-10 21:01:18 UTC) #2
MikeSamuel
On 2011/08/10 21:01:18, rsc wrote: > Do you avoid the accessors if you just edit ...
13 years, 7 months ago (2011-08-10 23:13:52 UTC) #3
MikeSamuel
http://codereview.appspot.com/4808089/diff/8008/src/pkg/exp/template/html/reverse_template.go File src/pkg/exp/template/html/reverse_template.go (right): http://codereview.appspot.com/4808089/diff/8008/src/pkg/exp/template/html/reverse_template.go#newcode1 src/pkg/exp/template/html/reverse_template.go:1: // Copyright 2011 The Go Authors. All rights reserved. ...
13 years, 7 months ago (2011-08-10 23:13:58 UTC) #4
rsc
> I was worried that exp/template/parse.go might (or might in the future) > share common ...
13 years, 7 months ago (2011-08-11 01:31:58 UTC) #5
r
http://codereview.appspot.com/4808089/diff/11/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/11/src/pkg/exp/template/html/reverse.go#newcode7 src/pkg/exp/template/html/reverse.go:7: the package comment should be bound to the package ...
13 years, 7 months ago (2011-08-11 03:57:17 UTC) #6
MikeSamuel
Incremental diffs at snapshot 7 : http://codereview.appspot.com/4808089/diff2/11:21001/src/pkg/exp/template/html/reverse.go http://codereview.appspot.com/4808089/diff/11/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/11/src/pkg/exp/template/html/reverse.go#newcode7 src/pkg/exp/template/html/reverse.go:7: On 2011/08/11 ...
13 years, 7 months ago (2011-08-11 06:17:04 UTC) #7
r
%q prints a quoted string, or quotes the strings inside an object containing strings such ...
13 years, 7 months ago (2011-08-11 06:36:55 UTC) #8
r
this is pretty good. just a few idiomatic improvements. http://codereview.appspot.com/4808089/diff/21001/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/21001/src/pkg/exp/template/html/reverse.go#newcode45 src/pkg/exp/template/html/reverse.go:45: ...
13 years, 7 months ago (2011-08-11 06:48:50 UTC) #9
nigeltao
http://codereview.appspot.com/4808089/diff/21001/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/21001/src/pkg/exp/template/html/reverse.go#newcode141 src/pkg/exp/template/html/reverse.go:141: var i int Delete this line and use "i ...
13 years, 7 months ago (2011-08-11 08:55:14 UTC) #10
MikeSamuel
Incremental diffs at http://codereview.appspot.com/4808089/diff2/21001:24003/src/pkg/exp/template/html/reverse.go http://codereview.appspot.com/4808089/diff/21001/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/21001/src/pkg/exp/template/html/reverse.go#newcode45 src/pkg/exp/template/html/reverse.go:45: panic("handling for type " + ...
13 years, 7 months ago (2011-08-11 19:08:01 UTC) #11
r
very close http://codereview.appspot.com/4808089/diff/24003/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/24003/src/pkg/exp/template/html/reverse.go#newcode73 src/pkg/exp/template/html/reverse.go:73: reversedText := make([]byte, n) the simplest way ...
13 years, 7 months ago (2011-08-12 01:31:51 UTC) #12
MikeSamuel
http://codereview.appspot.com/4808089/diff/24003/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/24003/src/pkg/exp/template/html/reverse.go#newcode73 src/pkg/exp/template/html/reverse.go:73: reversedText := make([]byte, n) On 2011/08/12 01:31:52, r wrote: ...
13 years, 7 months ago (2011-08-12 03:42:49 UTC) #13
r
http://codereview.appspot.com/4808089/diff/29003/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/29003/src/pkg/exp/template/html/reverse.go#newcode73 src/pkg/exp/template/html/reverse.go:73: runes := make([]int, n) my fault, i misled you. ...
13 years, 7 months ago (2011-08-12 03:53:42 UTC) #14
MikeSamuel
If this looks good, should I rework it in the next CL to do non-contextual ...
13 years, 7 months ago (2011-08-12 04:18:25 UTC) #15
r
LGTM http://codereview.appspot.com/4808089/diff/37002/src/pkg/exp/template/html/reverse.go File src/pkg/exp/template/html/reverse.go (right): http://codereview.appspot.com/4808089/diff/37002/src/pkg/exp/template/html/reverse.go#newcode71 src/pkg/exp/template/html/reverse.go:71: node.Text = []byte(string(runes)) there we go
13 years, 7 months ago (2011-08-12 04:19:33 UTC) #16
r2
On Aug 12, 2011, at 2:18 PM, mikesamuel@gmail.com wrote: > If this looks good, should ...
13 years, 7 months ago (2011-08-12 04:31:01 UTC) #17
r
13 years, 7 months ago (2011-08-12 04:34:37 UTC) #18
*** Submitted as http://code.google.com/p/go/source/detail?r=0447bf6a684a ***

exp/template/html: New package with a toy template transformation.

func Reverse(*Template) *Template
returns a template that produces the reverse of the original
for any input.

Changes outside exp/template/html include:
- Adding a getter for a template's FuncMap so that derived templates
  can inherit function definitions.
- Exported one node factory function, newIdentifier.
  Deriving tempaltes requires constructing new nodes, but I didn't
  export all of them because I think shallow copy functions might
  be more useful for this kind of work.
- Bugfix: Template's Name() method ignores the name field so
  template.New("foo") is a nil dereference instead of "foo".

Caveats: Reverse is a toy.  It is not UTF-8 safe, and does not
preserve order of calls to funcs in FuncMap.

For context, see
http://groups.google.com/group/golang-nuts/browse_thread/thread/e8bc7c771aae3...

R=rsc, r, nigeltao, r
CC=golang-dev
http://codereview.appspot.com/4808089

Committer: Rob Pike <r@golang.org>
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b