-
Notifications
You must be signed in to change notification settings - Fork 6
/
0-intro.tpl.go
99 lines (80 loc) · 2.88 KB
/
0-intro.tpl.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//** This file was code generated by GoT. DO NOT EDIT. ***
package controls
import (
"context"
"io"
)
func (ctrl *IntroPanel) DrawTemplate(ctx context.Context, _w io.Writer) (err error) {
if _, err = io.WriteString(_w, `<h1>Introduction to GoRADD Controls</h1>
<p>
GoRADD controls are structs written in Go code that mirror html and javascript code sent to the browser.
The GoRADD framework takes care of the back and forth communication between the server and the client browser,
such that when the GoRADD control is changed on the server, the equivalent browser control is changed, and when the
user makes a change to the control in the browser, the change is reflected in the server. Also, if the user performs
an action that is being watched, the server code will be notified when the user does that action in the browser.
</p>
<p>
The idea is that for the most part, you create your web site using Go code and html templates, and the html controls you
use automatically send their data to the server so you do not need to figure out how to route the client data to the
server. They also automatically reflect their values so that you can just think about manipulating the controls
in Go code, vs. worrying about how to deal with Post, Get and other HTTP mechanics.
</p>
<p>
The simple example here will wait for you to type something into the text field, and will then display a message with
the content.
</p>
<label>Text Field</label>`); err != nil {
return
}
if _, err = io.WriteString(_w, `
`); err != nil {
return
}
if `` == "" {
if _, err = io.WriteString(_w, ` `); err != nil {
return
}
ctrl.Page().GetControl("textField").Draw(ctx, _w)
if _, err = io.WriteString(_w, `
`); err != nil {
return
}
} else {
if _, err = io.WriteString(_w, ` `); err != nil {
return
}
ctrl.Page().GetControl("textField").ProcessAttributeString(``).Draw(ctx, _w)
if _, err = io.WriteString(_w, `
`); err != nil {
return
}
}
if _, err = io.WriteString(_w, `<p>
Click on the Source Code button above to view the source code for this page. You will notice that in Go, the
control is created using this code in the <i>Init</i> function of the <i>0-intro.go</i> file:
<code>
textBox := NewTextbox(p, "textField")
textBox.On(event.Input().Delay(1000), action.Message(javascript.JsCode("event.target.value")))
</code>
Later parts of this tutorial will teach you about events and actions. The thing to notice is how easy it is
to declare an HTML control and tell it what to do.
</p>
<p>
The control is drawn in the template file with this code:
<code>
`); err != nil {
return
}
if _, err = io.WriteString(_w, `{{draw textField }}
`); err != nil {
return
}
if _, err = io.WriteString(_w, `</code>
Note that "textField" is the id of the control, which was assigned when the control was created. It is also the
HTML <var>id</var> of the control.
</p>
`); err != nil {
return
}
return
}