Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
258a08ed
Commit
258a08ed
authored
Apr 22, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add {.tab}
fix a couple of comments TBR=rsc OCL=27716 CL=27716
parent
9d70646f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
template.go
src/lib/template/template.go
+8
-6
template_test.go
src/lib/template/template_test.go
+1
-0
No files found.
src/lib/template/template.go
View file @
258a08ed
...
...
@@ -73,10 +73,11 @@ type ParseError struct {
os
.
ErrorString
}
//
All
the literals are aces.
//
Most of
the literals are aces.
var
lbrace
=
[]
byte
{
'{'
}
var
rbrace
=
[]
byte
{
'}'
}
var
space
=
[]
byte
{
' '
}
var
tab
=
[]
byte
{
'\t'
}
// The various types of "tokens", which are plain text or (usually) brace-delimited descriptors
const
(
...
...
@@ -330,7 +331,7 @@ func (t *Template) analyze(item []byte) (tok int, w []string) {
return
;
}
switch
w
[
0
]
{
case
".meta-left"
,
".meta-right"
,
".space"
:
case
".meta-left"
,
".meta-right"
,
".space"
,
".tab"
:
tok
=
tokLiteral
;
return
;
case
".or"
:
...
...
@@ -413,6 +414,8 @@ func (t *Template) parseSimple(item []byte) (done bool, tok int, w []string) {
t
.
elems
.
Push
(
&
literalElement
{
t
.
rdelim
});
case
".space"
:
t
.
elems
.
Push
(
&
literalElement
{
space
});
case
".tab"
:
t
.
elems
.
Push
(
&
literalElement
{
tab
});
default
:
t
.
parseError
(
"internal error: unknown literal: %s"
,
w
[
0
]);
}
...
...
@@ -714,7 +717,7 @@ func validDelim(d []byte) bool {
return
true
;
}
// Public interface
//
--
Public interface
// Parse initializes a Template by parsing its definition. The string
// s contains the template text. If any errors occur, Parse returns
...
...
@@ -730,11 +733,10 @@ func (t *Template) Parse(s string) (err os.Error) {
t
.
parse
();
t
.
errorchan
<-
nil
;
// clean return;
}();
err
=
<-
t
.
errorchan
;
return
return
<-
t
.
errorchan
;
}
// Execute
executes a parsed template on
the specified data object,
// Execute
applies a parsed template to
the specified data object,
// generating output to wr.
func
(
t
*
Template
)
Execute
(
data
interface
{},
wr
io
.
Write
)
os
.
Error
{
// Extract the driver data.
...
...
src/lib/template/template_test.go
View file @
258a08ed
...
...
@@ -73,6 +73,7 @@ var tests = []*Test {
&
Test
{
" {.meta-left}
\n
"
,
"{"
},
&
Test
{
" {.meta-right}
\n
"
,
"}"
},
&
Test
{
" {.space}
\n
"
,
" "
},
&
Test
{
" {.tab}
\n
"
,
"
\t
"
},
&
Test
{
" {#comment}
\n
"
,
""
},
// Variables at top level
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment