Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

generate View IDs only on demand

  • Loading branch information...
commit 6e86600e6f85461ef22ce0fff43b328f3fdae2f0 1 parent e1a3081
@ungerik authored
View
4 view/button.go
@@ -18,7 +18,9 @@ func (self *Button) IterateChildren(callback IterateChildrenCallback) {
}
func (self *Button) Render(response *Response) (err error) {
- response.XML.OpenTag("button").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("button")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("type", "button")
response.XML.AttribIfNotDefault("name", self.Name)
if self.Disabled {
View
4 view/canvas.go
@@ -8,7 +8,9 @@ type Canvas struct {
}
func (self *Canvas) Render(response *Response) (err error) {
- response.XML.OpenTag("label").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("label")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("width", self.Width).Attrib("height", self.Height)
response.XML.ForceCloseTag()
return err
View
6 view/checkbox.go
@@ -14,7 +14,9 @@ type Checkbox struct {
}
func (self *Checkbox) Render(response *Response) (err error) {
- response.XML.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("input")
+ response.XML.Attrib(self.ID(), self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("type", "checkbox")
response.XML.Attrib("name", self.Name)
response.XML.Attrib("value", "true")
@@ -27,7 +29,7 @@ func (self *Checkbox) Render(response *Response) (err error) {
response.XML.CloseTag()
if self.Label != "" {
- response.XML.OpenTag("label").Attrib("for", self.id).Content(self.Label).CloseTag()
+ response.XML.OpenTag("label").Attrib("for", self.ID()).Content(self.Label).CloseTag()
}
return nil
}
View
4 view/div.go
@@ -18,7 +18,9 @@ func (self *Div) IterateChildren(callback IterateChildrenCallback) {
}
func (self *Div) Render(response *Response) (err error) {
- response.XML.OpenTag("div").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("div")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.AttribIfNotDefault("style", self.Style)
if self.Content != nil {
err = self.Content.Render(response)
View
4 view/dummyimage.go
@@ -44,7 +44,9 @@ func (self *DummyImage) Render(response *Response) (err error) {
src += "&text=" + url.QueryEscape(self.Text)
}
- response.XML.OpenTag("img").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("img")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("src", src)
response.XML.AttribIfNotDefault("width", self.Width)
response.XML.AttribIfNotDefault("height", self.Height)
View
4 view/fileinput.go
@@ -10,7 +10,9 @@ type FileInput struct {
}
func (self *FileInput) Render(response *Response) (err error) {
- response.XML.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("input")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("type", "file").Attrib("name", self.Name)
if self.Disabled {
response.XML.Attrib("disabled", "disabled")
View
4 view/form.go
@@ -511,7 +511,9 @@ func (self *Form) Render(response *Response) (err error) {
action = utils.AddUrlParam(action, FormIDName, self.FormID)
}
- response.XML.OpenTag("form").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("form")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("method", method)
response.XML.Attrib("action", action)
response.XML.AttribIfNotDefault("enctype", self.Enctype)
View
3  view/functions.go
@@ -8,7 +8,6 @@ import (
"github.com/ungerik/go-start/errs"
"github.com/ungerik/go-start/templatesystem"
"github.com/ungerik/go-start/utils"
- // "github.com/ungerik/goconfig"
"github.com/ungerik/web.go"
// "github.com/ungerik/go-start/debug"
@@ -20,9 +19,9 @@ var viewIdCounter int64
func init() {
go func() {
for {
+ viewIdCounter++
// Use base32 encoding for ids to make them shorter
viewIdChan <- strconv.FormatInt(viewIdCounter, 32)
- viewIdCounter++
}
}()
}
View
3  view/hiddeninput.go
@@ -10,7 +10,8 @@ type HiddenInput struct {
}
func (self *HiddenInput) Render(response *Response) (err error) {
- response.XML.OpenTag("input").Attrib("id", self.id)
+ response.XML.OpenTag("input")
+ response.XML.AttribIfNotDefault("id", self.id)
response.XML.Attrib("type", "hidden")
response.XML.Attrib("name", self.Name)
response.XML.Attrib("value", self.Value)
View
4 view/iframe.go
@@ -17,7 +17,9 @@ type Iframe struct {
}
func (self *Iframe) Render(response *Response) (err error) {
- response.XML.OpenTag("iframe").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("iframe")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("width", self.Width).Attrib("height", self.Height)
response.XML.Attrib("frameborder", self.Border)
response.XML.Attrib("marginwidth", self.MarginWidth).Attrib("marginheight", self.MarginHeight)
View
4 view/image.go
@@ -14,7 +14,9 @@ type Image struct {
}
func (self *Image) Render(response *Response) (err error) {
- response.XML.OpenTag("img").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("img")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
src := self.Src
if self.URL != nil {
src = self.URL.URL(response)
View
4 view/label.go
@@ -15,7 +15,9 @@ func (self *Label) Render(response *Response) (err error) {
if self.For != nil {
forID = self.For.ID()
}
- response.XML.OpenTag("label").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("label")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.AttribIfNotDefault("for", forID)
if self.Content != nil {
err = self.Content.Render(response)
View
3  view/link.go
@@ -13,7 +13,8 @@ type Link struct {
}
func (self *Link) Render(response *Response) (err error) {
- response.XML.OpenTag("a").AttribIfNotDefault("id", self.id)
+ response.XML.OpenTag("a")
+ response.XML.AttribIfNotDefault("id", self.id)
response.XML.AttribIfNotDefault("class", self.Class)
if self.NewWindow {
response.XML.Attrib("target", "_blank")
View
11 view/list.go
@@ -14,16 +14,21 @@ type List struct {
func (self *List) Render(response *Response) (err error) {
if self.Ordered {
- response.XML.OpenTag("ol").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("ol")
response.XML.Attrib("start", self.OrderOffset+1)
} else {
- response.XML.OpenTag("ul").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("ul")
}
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
if self.Model != nil {
numItems := self.Model.NumItems()
for i := 0; i < numItems; i++ {
- response.XML.OpenTag("li").Attrib("id", self.id, "_", i)
+ response.XML.OpenTag("li")
+ if self.id != "" {
+ response.XML.Attrib("id", self.id, "_", i)
+ }
view, err := self.Model.ItemView(i, response)
if view != nil && err == nil {
view.Init(view)
View
10 view/menu.go
@@ -19,7 +19,9 @@ type Menu struct {
}
func (self *Menu) Render(response *Response) (err error) {
- response.XML.OpenTag("ul").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("ul")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
requestURL := response.Request.URLString()
@@ -63,7 +65,11 @@ func (self *Menu) Render(response *Response) (err error) {
itemClass += " " + self.ActiveItemClass
}
- response.XML.OpenTag("li").Attrib("id", self.id, "_", index).AttribIfNotDefault("class", itemClass)
+ response.XML.OpenTag("li")
+ if self.id != "" {
+ response.XML.Attrib("id", self.id, "_", index)
+ }
+ response.XML.AttribIfNotDefault("class", itemClass)
if i > 0 && self.BetweenItems != "" {
response.XML.Content(self.BetweenItems)
View
4 view/paragraph.go
@@ -16,7 +16,9 @@ func (self *Paragraph) IterateChildren(callback IterateChildrenCallback) {
}
func (self *Paragraph) Render(response *Response) (err error) {
- response.XML.OpenTag("p").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("p")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
if self.Content != nil {
err = self.Content.Render(response)
}
View
4 view/select.go
@@ -17,7 +17,9 @@ func (self *Select) IterateChildren(callback IterateChildrenCallback) {
}
func (self *Select) Render(response *Response) (err error) {
- response.XML.OpenTag("select").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("select")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("name", self.Name)
if self.Disabled {
response.XML.Attrib("disabled", "disabled")
View
4 view/span.go
@@ -17,7 +17,9 @@ func (self *Span) IterateChildren(callback IterateChildrenCallback) {
}
func (self *Span) Render(response *Response) (err error) {
- response.XML.OpenTag("span").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("span")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
if self.Content != nil {
err = self.Content.Render(response)
}
View
4 view/submitbutton.go
@@ -12,7 +12,9 @@ type SubmitButton struct {
}
func (self *SubmitButton) Render(response *Response) (err error) {
- response.XML.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("input")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("type", "submit")
response.XML.AttribIfNotDefault("name", self.Name)
response.XML.AttribIfNotDefault("value", self.Value)
View
4 view/table.go
@@ -12,7 +12,9 @@ type Table struct {
}
func (self *Table) Render(response *Response) (err error) {
- response.XML.OpenTag("table").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("table")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
if self.Caption != "" {
response.XML.OpenTag("caption").EscapeContent(self.Caption).CloseTag()
View
4 view/tag.go
@@ -20,7 +20,9 @@ func (self *Tag) IterateChildren(callback IterateChildrenCallback) {
}
func (self *Tag) Render(response *Response) (err error) {
- response.XML.OpenTag(self.Tag).Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag(self.Tag)
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
for key, value := range self.Attribs {
response.XML.Attrib(key, value)
}
View
4 view/textarea.go
@@ -22,7 +22,9 @@ type TextArea struct {
}
func (self *TextArea) Render(response *Response) (err error) {
- response.XML.OpenTag("textarea").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("textarea")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
cols := self.Cols
if cols == 0 {
View
4 view/textfield.go
@@ -26,7 +26,9 @@ type TextField struct {
}
func (self *TextField) Render(response *Response) (err error) {
- response.XML.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("input")
+ response.XML.AttribIfNotDefault("id", self.id)
+ response.XML.AttribIfNotDefault("class", self.Class)
response.XML.Attrib("name", self.Name)
response.XML.AttribIfNotDefault("tabindex", self.TabIndex)
View
4 view/video.go
@@ -32,7 +32,9 @@ func (self *Video) Render(response *Response) (err error) {
}
if youtubeId != "" {
- response.XML.OpenTag("iframe").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
+ response.XML.OpenTag("iframe")
+ response.XML.Attrib("id", self.ID())
+ response.XML.AttribIfNotDefault("class", self.Class)
width := self.Width
if width == 0 {
width = 640
View
4 view/viewbasewithid.go
@@ -14,9 +14,11 @@ func (self *ViewBaseWithId) Init(thisView View) {
return // already initialized
}
self.ViewBase.Init(thisView)
- self.id = NewViewID(thisView)
}
func (self *ViewBaseWithId) ID() string {
+ if self.id == "" {
+ self.id = NewViewID(self.thisView)
+ }
return self.id
}
Please sign in to comment.
Something went wrong with that request. Please try again.