Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

finished merge from master

  • Loading branch information...
commit af45068a8c358ce1f0db0ec62b45babfd27c1ce7 2 parents d0f5027 + 2fb9615
Erik Unger authored
Showing with 246 additions and 227 deletions.
  1. +12 −12 gostart.go
  2. +3 −1 media/imageref.go
  3. +6 −6 media/view.go
  4. +6 −1 model/blob.go
  5. +5 −2 model/bool.go
  6. +10 −2 model/choice.go
  7. +8 −2 model/color.go
  8. +2 −0  model/config.go
  9. +1 −1  model/country.go
  10. +1 −1  model/date.go
  11. +1 −1  model/datetime.go
  12. +1 −1  model/email.go
  13. +1 −1  model/file.go
  14. +3 −7 model/float.go
  15. +1 −1  model/geolocation.go
  16. +2 −6 model/int.go
  17. +1 −1  model/language.go
  18. +37 −30 model/metadata.go
  19. +1 −1  model/multiplechoice.go
  20. +4 −4 model/password.go
  21. +1 −1  model/phone.go
  22. +3 −7 model/string.go
  23. +3 −21 model/text.go
  24. +1 −1  model/time.go
  25. +1 −1  model/url.go
  26. +1 −1  model/visitor.go
  27. +6 −6 modelext/name.go
  28. +5 −5 modelext/postaladdress.go
  29. +1 −1  mongo/functions.go
  30. +1 −1  mongo/ref.go
  31. +1 −1  user/auth.go
  32. +1 −1  user/emailidentity.go
  33. +6 −6 user/formmodels.go
  34. +3 −3 user/user.go
  35. +2 −2 user/views.go
  36. +1 −1  view/basicauth.go
  37. +8 −8 view/config.go
  38. +0 −2  view/constants.go
  39. +9 −9 view/contactform.go
  40. +2 −1  view/fileinput.go
  41. +20 −20 view/form.go
  42. +2 −2 view/functions.go
  43. +2 −4 view/indirectviewwithurl.go
  44. +1 −1  view/jquery.go
  45. +1 −1  view/link.go
  46. +3 −3 view/menu.go
  47. +7 −7 view/{modelview.go → modeliteratorview.go}
  48. +4 −4 view/page.go
  49. +2 −2 view/pagelink.go
  50. +1 −1  view/renderview.go
  51. +1 −1  view/request.go
  52. +5 −0 view/response.go
  53. +1 −1  view/shortcuts.go
  54. +16 −2 view/standardformfieldfactory.go
  55. +9 −9 view/standardformlayout.go
  56. +2 −2 view/stringlink.go
  57. +1 −1  view/template.go
  58. +1 −1  view/textpreview.go
  59. +2 −2 view/urllink.go
  60. +3 −3 view/viewpath.go
24 gostart.go
View
@@ -93,14 +93,14 @@ Example of a dynamic view:
},
)
-Beside DynamicView there is also a ModelView. It takes a model.Iterator
+Beside DynamicView there is also a ModelIteratorView. It takes a model.Iterator
and creates a dynamic view for every iterated data item:
- view := &ModelView{
+ view := &ModelIteratorView{
GetModelIterator: func(response *Response) model.Iterator {
return models.Users.Sort("Name.First").Sort("Name.Last").Iterator()
},
- GetModelView: func(model interface{}, response *Response) (view View, err error) {
+ GetModelIteratorView: func(model interface{}, response *Response) (view View, err error) {
user := model.(*models.User)
return PrintfEscape("%s, ", user.Name), nil
},
@@ -165,9 +165,9 @@ Custom model wide validation is done by adding a Validate() method to the
struct type:
type SignupFormModel struct {
- Email model.Email `gostart:"required"`
- Password1 model.Password `gostart:"required|label=Password|minlen=6"`
- Password2 model.Password `gostart:"label=Repeat password"`
+ Email model.Email `model:"required"`
+ Password1 model.Password `view:"label=Password" model:"minlen=6"`
+ Password2 model.Password `view:"label=Repeat password"`
}
func (self *SignupFormModel) Validate(metaData *model.MetaData) []*model.ValidationError {
@@ -206,17 +206,17 @@ Example of a collection and document struct:
var ExampleDocs *mongo.Collection = mongo.NewCollection("exampledocs", (*ExampleDoc)(nil))
type ExampleDoc struct {
- mongo.DocumentBase `bson:",inline"` // Give it a Mongo ID
- Person mongo.Ref `gostart:"to=people"` // Mongo ID ref to a document in "people" collection
- LongerText model.Text `gostart:"rows=5|cols=80|maxlen=400"`
- Integer model.Int `gostart:"min=1|max=100"`
+ mongo.DocumentBase `bson:",inline"` // Give it a Mongo ID
+ Person mongo.Ref `model:"to=people"` // Mongo ID ref to a document in "people" collection
+ LongerText model.Text `model:"maxlen=400" view:"rows=5|cols=80"`
+ Integer model.Int `model:"min=1|max=100"`
Email model.Email // Normalization + special treament in forms
PhoneNumber model.Phone // Normalization + special treament in forms
Password model.Password // Hashed + special treament in forms
SubDoc struct {
Day model.Date
- Drinks []mongo.Choice `gostart:"options=Beer,Wine,Water"` // Mongo array of strings
- RealFloat model.Float `gostart:"valid" // Must be a real float value, not NaN or Inf
+ Drinks []mongo.Choice `model:"options=Beer,Wine,Water"` // Mongo array of strings
+ RealFloat model.Float `model:"valid" // Must be a real float value, not NaN or Inf
}
}
4 media/imageref.go
View
@@ -2,7 +2,9 @@ package media
import (
"errors"
+
"github.com/ungerik/go-start/model"
+ "github.com/ungerik/go-start/view"
)
type ImageRef string
@@ -21,7 +23,7 @@ func (self *ImageRef) IsEmpty() bool {
}
func (self *ImageRef) Required(metaData *model.MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(view.StructTagKey, "required")
}
func (self *ImageRef) Validate(metaData *model.MetaData) error {
12 media/view.go
View
@@ -2,20 +2,20 @@ package media
import (
"io"
+
"github.com/ungerik/go-start/view"
- "github.com/ungerik/go-start/utils"
)
var View view.ViewWithURL = view.NewViewURLWrapper(view.RenderView(
- func(context *view.Context, writer *utils.XMLWriter) error {
- reader, contentType, err := Config.Backend.ImageVersionReader(context.PathArgs[0])
+ func(response *view.Response) error {
+ reader, contentType, err := Config.Backend.ImageVersionReader(response.Request.URLArgs[0])
if err != nil {
if _, ok := err.(ErrInvalidImageID); ok {
- return view.NotFound(context.PathArgs[0] + "/" + context.PathArgs[1] + " not found")
+ return view.NotFound(response.Request.URLArgs[0] + "/" + response.Request.URLArgs[1] + " not found")
}
return err
}
- _, err = io.Copy(writer, reader)
+ _, err = io.Copy(response, reader)
if err != nil {
return err
}
@@ -23,7 +23,7 @@ var View view.ViewWithURL = view.NewViewURLWrapper(view.RenderView(
if err != nil {
return err
}
- context.Header().Set("Content-Type", contentType)
+ response.Header().Set("Content-Type", contentType)
return nil
},
))
7 model/blob.go
View
@@ -4,6 +4,11 @@ import (
// "io/ioutil"
)
+/*
+Blob is just a bunch of bytes.
+Struct tag attributes:
+ `model:"required"`
+*/
type Blob []byte
func (self *Blob) Get() []byte {
@@ -28,7 +33,7 @@ func (self *Blob) IsEmpty() bool {
}
func (self *Blob) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *Blob) Validate(metaData *MetaData) error {
7 model/bool.go
View
@@ -2,8 +2,11 @@ package model
import "strconv"
-// Attributes:
-// * label
+/*
+Bool model value.
+Struct tag attributes:
+ none
+*/
type Bool bool
func (self *Bool) Get() bool {
12 model/choice.go
View
@@ -7,7 +7,15 @@ import (
)
/*
-Separate options with ',' escape ',' in options with '\,'
+Choice can hold one of several string options.
+The options are defined by the struct tag attribute "options"
+delimited by colons ",".
+A colon in an option can be escaped with "\,"
+An empty string can be used as the first option.
+Choice is required, when the first option in not an empty string.
+Struct tag attributes:
+ `model:"options=Red,Green,Blue"`
+ `model:"options=,Second,Third"` // empty string is a valid value
*/
type Choice string
@@ -57,7 +65,7 @@ func (self *Choice) Validate(metaData *MetaData) error {
}
func (self *Choice) Options(metaData *MetaData) []string {
- options, ok := metaData.Attrib("options")
+ options, ok := metaData.Attrib(StructTagKey, "options")
if !ok {
return nil
}
10 model/color.go
View
@@ -7,7 +7,13 @@ import (
"encoding/hex"
)
-// Color holds a hex web-color with the # prefix.
+/*
+Color holds a hex web-color with the # prefix.
+The Set method accepts all valid web color syntaxes
+except for color names.
+Struct tag attributes:
+ `model:"required"`
+*/
type Color string
func (self *Color) Get() string {
@@ -64,7 +70,7 @@ func (self *Color) SetString(str string) error {
}
func (self *Color) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *Color) IsValid() bool {
2  model/config.go
View
@@ -5,3 +5,5 @@ type Configuration struct {
}
var Config Configuration
+
+const StructTagKey = "model"
2  model/country.go
View
@@ -54,7 +54,7 @@ func (self *Country) Validate(metaData *MetaData) error {
}
func (self *Country) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
type InvalidCountryCode struct {
2  model/date.go
View
@@ -87,5 +87,5 @@ func (self *Date) Validate(metaData *MetaData) error {
}
func (self *Date) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
2  model/datetime.go
View
@@ -93,5 +93,5 @@ func (self *DateTime) Validate(metaData *MetaData) error {
}
func (self *DateTime) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
2  model/email.go
View
@@ -46,5 +46,5 @@ func (self *Email) Validate(metaData *MetaData) error {
}
func (self *Email) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
2  model/file.go
View
@@ -19,7 +19,7 @@ func (self *File) IsEmpty() bool {
}
func (self *File) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *File) Validate(metaData *MetaData) error {
10 model/float.go
View
@@ -67,7 +67,7 @@ func (self *Float) Validate(metaData *MetaData) error {
}
func (self *Float) Min(metaData *MetaData) (min float64, ok bool, err error) {
- str, ok := metaData.Attrib("min")
+ str, ok := metaData.Attrib(StructTagKey, "min")
if !ok {
return 0, false, nil
}
@@ -76,7 +76,7 @@ func (self *Float) Min(metaData *MetaData) (min float64, ok bool, err error) {
}
func (self *Float) Max(metaData *MetaData) (max float64, ok bool, err error) {
- str, ok := metaData.Attrib("max")
+ str, ok := metaData.Attrib(StructTagKey, "max")
if !ok {
return 0, false, nil
}
@@ -85,7 +85,7 @@ func (self *Float) Max(metaData *MetaData) (max float64, ok bool, err error) {
}
func (self *Float) Valid(metaData *MetaData) bool {
- return metaData.BoolAttrib("valid")
+ return metaData.BoolAttrib(StructTagKey, "valid")
}
type FloatBelowMin struct {
@@ -113,7 +113,3 @@ type FloatNotReal struct {
func (self *FloatNotReal) Error() string {
return fmt.Sprintf("Float %v is not a real number", self.Value)
}
-
-func (self *Float) Hidden(metaData *MetaData) (hidden bool) {
- return metaData.BoolAttrib("hidden")
-}
2  model/geolocation.go
View
@@ -32,7 +32,7 @@ func (self *GeoLocation) IsEmpty() bool {
}
func (self *GeoLocation) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *GeoLocation) Validate(metaData *MetaData) error {
8 model/int.go
View
@@ -65,7 +65,7 @@ func (self *Int) Validate(metaData *MetaData) error {
}
func (self *Int) Min(metaData *MetaData) (min int64, ok bool, err error) {
- str, ok := metaData.Attrib("min")
+ str, ok := metaData.Attrib(StructTagKey, "min")
if !ok {
return 0, false, nil
}
@@ -74,7 +74,7 @@ func (self *Int) Min(metaData *MetaData) (min int64, ok bool, err error) {
}
func (self *Int) Max(metaData *MetaData) (max int64, ok bool, err error) {
- str, ok := metaData.Attrib("max")
+ str, ok := metaData.Attrib(StructTagKey, "max")
if !ok {
return 0, false, nil
}
@@ -99,7 +99,3 @@ type IntAboveMax struct {
func (self *IntAboveMax) Error() string {
return fmt.Sprintf("Int %d above maximum of %d", self.Value, self.Max)
}
-
-func (self *Int) Hidden(metaData *MetaData) (hidden bool) {
- return metaData.BoolAttrib("hidden")
-}
2  model/language.go
View
@@ -59,7 +59,7 @@ func (self *Language) Validate(metaData *MetaData) error {
}
func (self *Language) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
type InvalidLanguageCode struct {
67 model/metadata.go
View
@@ -51,14 +51,15 @@ func GetMetaDataKind(v reflect.Value) MetaDataKind {
// MetaData holds meta data about an model data item.
type MetaData struct {
- Kind MetaDataKind
- Value reflect.Value
- Depth int // number of steps up to the root parent
- Name string // empty for array and slice fields
- Index int // will also be set for struct fields
- Parent *MetaData
- tag string
- attribs map[string]string // cached tag attributes
+ Kind MetaDataKind
+ Value reflect.Value
+ Depth int // number of steps up to the root parent
+ Name string // empty for array and slice fields
+ Index int // will also be set for struct fields
+ Parent *MetaData
+ tag reflect.StructTag
+ // cached tag attributes, by package
+ attribs map[string]map[string]string
path []*MetaData
}
@@ -130,24 +131,42 @@ func (self *MetaData) Path() []*MetaData {
return self.path
}
+func ParseTagAttribs(tag string) map[string]string {
+ attribs := make(map[string]string)
+ for _, s := range strings.Split(tag, "|") {
+ pos := strings.Index(s, "=")
+ if pos == -1 {
+ attribs[s] = "true"
+ } else {
+ attribs[s[:pos]] = s[pos+1:]
+ }
+ }
+ return attribs
+}
+
/*
Attrib returns the value of a tag attribute if available.
Array and slice fields inherit the attributes of their named
parent fields.
The meaning of attributes is interpreted by the package that reads them.
-Attributes are defined in a struct tag named "gostart" and written
-as name=value. Multiple attributes are separated by '|'.
+Attributes are defined in a struct tag named "gostart", "model" or "view"
+and written as name=value. Multiple attributes are separated by '|'.
Example:
type Struct {
- X int `gostart:"min=0|max=10"`
- S []int `gostart:"maxlen=3|min=0|max=10"
+ X int `model:"min=0|max=10"`
+ S []int `model:"maxlen=3|min=0|max=10"
hidden int
Ignore int `gostart:"-"`
+ Z int `view:"lable=A longer label for display"`
}
*/
-func (self *MetaData) Attrib(name string) (value string, ok bool) {
+func (self *MetaData) Attrib(tagKey, name string) (value string, ok bool) {
if self.attribs == nil {
+ self.attribs = make(map[string]map[string]string)
+ }
+ keyAttribs, ok := self.attribs[tagKey]
+ if !ok {
structField := self
for !structField.IsStructField() {
structField = structField.Parent
@@ -155,16 +174,17 @@ func (self *MetaData) Attrib(name string) (value string, ok bool) {
return "", false
}
}
- self.attribs = ParseTagAttribs(structField.tag)
+ keyAttribs = ParseTagAttribs(structField.tag.Get(tagKey))
+ self.attribs[tagKey] = keyAttribs
}
- value, ok = self.attribs[name]
+ value, ok = keyAttribs[name]
return value, ok
}
// BoolAttrib uses Attrib() to check if the value of an attribute is "true".
// A non existing attribibute is considered to be false.
-func (self *MetaData) BoolAttrib(name string) bool {
- value, ok := self.Attrib(name)
+func (self *MetaData) BoolAttrib(tagKey, name string) bool {
+ value, ok := self.Attrib(tagKey, name)
return ok && value == "true"
}
@@ -202,16 +222,3 @@ func (self *MetaData) SelectorsMatch(list []string) bool {
func (self *MetaData) String() string {
return fmt.Sprintf("%s: %T", self.Selector(), self.Value.Interface())
}
-
-func ParseTagAttribs(tag string) map[string]string {
- attribs := make(map[string]string)
- for _, s := range strings.Split(tag, "|") {
- pos := strings.Index(s, "=")
- if pos == -1 {
- attribs[s] = "true"
- } else {
- attribs[s[:pos]] = s[pos+1:]
- }
- }
- return attribs
-}
2  model/multiplechoice.go
View
@@ -18,7 +18,7 @@ func (self *MultipleChoice) IsEmpty() bool {
}
func (self *MultipleChoice) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *MultipleChoice) Validate(metaData *MetaData) error {
8 model/password.go
View
@@ -49,7 +49,7 @@ func (self *Password) Required(metaData *MetaData) bool {
return true
}
}
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *Password) Validate(metaData *MetaData) error {
@@ -59,7 +59,7 @@ func (self *Password) Validate(metaData *MetaData) error {
if pos != -1 {
return errors.New("Line breaks not allowed")
}
-
+
if self.Required(metaData) && self.IsEmpty() {
return NewRequiredError(metaData)
}
@@ -85,7 +85,7 @@ func (self *Password) Validate(metaData *MetaData) error {
func (self *Password) Minlen(metaData *MetaData) (minlen int, ok bool, err error) {
var str string
- if str, ok = metaData.Attrib("minlen"); ok {
+ if str, ok = metaData.Attrib(StructTagKey, "minlen"); ok {
minlen, err = strconv.Atoi(str)
ok = err == nil
}
@@ -94,7 +94,7 @@ func (self *Password) Minlen(metaData *MetaData) (minlen int, ok bool, err error
func (self *Password) Maxlen(metaData *MetaData) (maxlen int, ok bool, err error) {
var str string
- if str, ok = metaData.Attrib("maxlen"); ok {
+ if str, ok = metaData.Attrib(StructTagKey, "maxlen"); ok {
maxlen, err = strconv.Atoi(str)
ok = err == nil
}
2  model/phone.go
View
@@ -31,7 +31,7 @@ func (self *Phone) FixValue(metaData *MetaData) {
}
func (self *Phone) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *Phone) Validate(metaData *MetaData) error {
10 model/string.go
View
@@ -48,7 +48,7 @@ func (self *String) Required(metaData *MetaData) bool {
return true
}
}
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *String) Validate(metaData *MetaData) error {
@@ -84,7 +84,7 @@ func (self *String) Validate(metaData *MetaData) error {
func (self *String) Minlen(metaData *MetaData) (minlen int, ok bool, err error) {
var str string
- if str, ok = metaData.Attrib("minlen"); ok {
+ if str, ok = metaData.Attrib(StructTagKey, "minlen"); ok {
minlen, err = strconv.Atoi(str)
ok = err == nil
}
@@ -93,17 +93,13 @@ func (self *String) Minlen(metaData *MetaData) (minlen int, ok bool, err error)
func (self *String) Maxlen(metaData *MetaData) (maxlen int, ok bool, err error) {
var str string
- if str, ok = metaData.Attrib("maxlen"); ok {
+ if str, ok = metaData.Attrib(StructTagKey, "maxlen"); ok {
maxlen, err = strconv.Atoi(str)
ok = err == nil
}
return maxlen, ok, err
}
-func (self *String) Hidden(metaData *MetaData) (hidden bool) {
- return metaData.BoolAttrib("hidden")
-}
-
type StringTooShort struct {
Str string
Minlen int
24 model/text.go
View
@@ -41,7 +41,7 @@ func (self *Text) Required(metaData *MetaData) bool {
return true
}
}
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *Text) Validate(metaData *MetaData) error {
@@ -72,7 +72,7 @@ func (self *Text) Validate(metaData *MetaData) error {
func (self *Text) Minlen(metaData *MetaData) (minlen int, ok bool, err error) {
var str string
- if str, ok = metaData.Attrib("minlen"); ok {
+ if str, ok = metaData.Attrib(StructTagKey, "minlen"); ok {
minlen, err = strconv.Atoi(str)
ok = err == nil
}
@@ -81,27 +81,9 @@ func (self *Text) Minlen(metaData *MetaData) (minlen int, ok bool, err error) {
func (self *Text) Maxlen(metaData *MetaData) (maxlen int, ok bool, err error) {
var str string
- if str, ok = metaData.Attrib("maxlen"); ok {
+ if str, ok = metaData.Attrib(StructTagKey, "maxlen"); ok {
maxlen, err = strconv.Atoi(str)
ok = err == nil
}
return maxlen, ok, err
}
-
-func (self *Text) Rows(metaData *MetaData) (rows int, ok bool, err error) {
- var str string
- if str, ok = metaData.Attrib("rows"); ok {
- rows, err = strconv.Atoi(str)
- ok = err == nil
- }
- return rows, ok, err
-}
-
-func (self *Text) Cols(metaData *MetaData) (cols int, ok bool, err error) {
- var str string
- if str, ok = metaData.Attrib("cols"); ok {
- cols, err = strconv.Atoi(str)
- ok = err == nil
- }
- return cols, ok, err
-}
2  model/time.go
View
@@ -25,7 +25,7 @@ func (self *Time) IsEmpty() bool {
}
func (self *Time) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
func (self *Time) Validate(metaData *MetaData) error {
2  model/url.go
View
@@ -56,5 +56,5 @@ func (self *Url) Validate(metaData *MetaData) error {
}
func (self *Url) Required(metaData *MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(StructTagKey, "required")
}
2  model/visitor.go
View
@@ -119,7 +119,7 @@ func (self *structVisitorWrapper) StructField(depth int, v reflect.Value, f refl
Depth: depth,
Name: f.Name,
Index: index,
- tag: f.Tag.Get("gostart"),
+ tag: f.Tag,
}
return self.visitor.StructField(self.metaData)
}
12 modelext/name.go
View
@@ -10,12 +10,12 @@ import (
// Name
type Name struct {
- Prefix model.String `gostart:"size=10"`
- First model.String `gostart:"size=20|label=Given"`
- Middle model.String `gostart:"size=20"`
- Last model.String `gostart:"size=20|label=Family"`
- Postfix model.String `gostart:"size=10"`
- Organization model.String `gostart:"size=40"`
+ Prefix model.String `view:"size=10"`
+ First model.String `view:"size=20|label=Given"`
+ Middle model.String `view:"size=20"`
+ Last model.String `view:"size=20|label=Family"`
+ Postfix model.String `view:"size=10"`
+ Organization model.String `view:"size=40"`
}
func (self *Name) SetForPerson(prefix, first, middle, last, postfix string) {
10 modelext/postaladdress.go
View
@@ -9,11 +9,11 @@ import (
// PostalAddress
type PostalAddress struct {
- FirstLine model.String `gostart:"size=40"`
- SecondLine model.String `gostart:"size=40"`
- ZIP model.String `gostart:"size=10"`
- City model.String `gostart:"size=20"`
- State model.String `gostart:"size=20"`
+ FirstLine model.String `view:"size=40"`
+ SecondLine model.String `view:"size=40"`
+ ZIP model.String `view:"size=10"`
+ City model.String `view:"size=20"`
+ State model.String `view:"size=20"`
Country model.Country
}
2  mongo/functions.go
View
@@ -154,7 +154,7 @@ func InitRefs(document interface{}) {
model.Visit(document, model.FieldOnlyVisitor(
func(data *model.MetaData) error {
if ref, ok := data.Value.Addr().Interface().(*Ref); ok && ref.CollectionName == "" {
- ref.CollectionName, ok = data.Attrib("to")
+ ref.CollectionName, ok = data.Attrib(model.StructTagKey, "to")
if !ok {
panic(data.Selector() + " is missing the 'to' meta-data tag")
}
2  mongo/ref.go
View
@@ -71,7 +71,7 @@ func (self *Ref) Validate(metaData *model.MetaData) error {
}
func (self *Ref) Required(metaData *model.MetaData) bool {
- return metaData.BoolAttrib("required")
+ return metaData.BoolAttrib(model.StructTagKey, "required")
}
// Dummy function to implement model.Reference
2  user/auth.go
View
@@ -17,7 +17,7 @@ func (self *Auth) Authenticate(response *view.Response) (ok bool, err error) {
ok, err = IsConfirmedUserID(id)
if !ok && err == nil && self.LoginURL != nil {
- err = view.Redirect(self.LoginURL.URL(context.PathArgs...))
+ err = view.Redirect(self.LoginURL.URL(response.Request.URLArgs...))
}
return ok, err
}
2  user/emailidentity.go
View
@@ -32,7 +32,7 @@ func (self *EmailIdentity) SendConfirmationEmail(response *view.Response, confir
}
subject := fmt.Sprintf(Config.ConfirmationEmailSubject, view.Config.SiteName)
- confirm := confirmationURL.URL(context.PathArgs...) + "?code=" + url.QueryEscape(confirmationCode)
+ confirm := confirmationURL.URL(response.Request.URLArgs...) + "?code=" + url.QueryEscape(confirmationCode)
message := fmt.Sprintf(Config.ConfirmationEmailMessage, view.Config.SiteName, confirm)
go func() {
12 user/formmodels.go
View
@@ -6,8 +6,8 @@ import (
)
type PasswordFormModel struct {
- Password1 model.Password `gostart:"label=Password|minlen=6|size=20"`
- Password2 model.Password `gostart:"label=Repeat password|size=20"`
+ Password1 model.Password `model:"minlen=6" view:"label=Password|size=20"`
+ Password2 model.Password `view:"label=Repeat password|size=20"`
}
func (self *PasswordFormModel) Validate(metaData *model.MetaData) error {
@@ -18,11 +18,11 @@ func (self *PasswordFormModel) Validate(metaData *model.MetaData) error {
}
type EmailPasswordFormModel struct {
- Email model.Email `gostart:"required|size=20"`
- PasswordFormModel `bson:",inline" gostart:"size=20"`
+ Email model.Email `model:"required" view:"size=20"`
+ PasswordFormModel `bson:",inline" view:"size=20"`
}
type LoginFormModel struct {
- Email model.Email `gostart:"required|size=20"`
- Password model.Password `gostart:"required|size=20"`
+ Email model.Email `model:"required" view:"size=20"`
+ Password model.Password `model:"required" view:"size=20"`
}
6 user/user.go
View
@@ -14,11 +14,11 @@ import (
type User struct {
mongo.DocumentBase `bson:",inline"`
Name modelext.Name
- Username model.String `gostart:"size=20"`
+ Username model.String `view:"size=20"`
Password model.Password
Blocked model.Bool
Admin model.Bool
- PostalAddress modelext.PostalAddress `gostart:"label=Postal Address"`
+ PostalAddress modelext.PostalAddress `view:"label=Postal Address"`
Phone []PhoneNumber
Web []Website
Email []EmailIdentity
@@ -225,7 +225,7 @@ type PhoneNumber struct {
// Implements view.LinkModel
type Website struct {
- Url model.Url `gostart:"label=URL"`
+ Url model.Url `view:"label=URL"`
Title model.String
Description model.String
}
4 user/views.go
View
@@ -81,7 +81,7 @@ func LogoutView(redirect view.URL) view.View {
func(response *view.Response) (err error) {
Logout(response.Session)
if redirect != nil {
- return view.Redirect(redirect.URL(context.PathArgs...))
+ return view.Redirect(redirect.URL(response.Request.URLArgs...))
}
return view.Redirect("/")
},
@@ -101,7 +101,7 @@ func NewSignupForm(buttonText, class, errorMessageClass, successMessageClass str
return &EmailPasswordFormModel{}, nil
},
Redirect: redirectURL,
- OnSubmit: func(form *view.Form, formModel interface{}, response *view.Response) string, view.URL, error {
+ OnSubmit: func(form *view.Form, formModel interface{}, response *view.Response) (string, view.URL, error) {
m := formModel.(*EmailPasswordFormModel)
email := m.Email.Get()
password := m.Password1.Get()
2  view/basicauth.go
View
@@ -39,7 +39,7 @@ func (self *BasicAuth) Authenticate(response *Response) (ok bool, err error) {
}
}
- response.SetHeader("WWW-Authenticate", "Basic realm=\""+self.Realm+"\"", false)
+ response.Header().Set("WWW-Authenticate", "Basic realm=\""+self.Realm+"\"")
response.AuthorizationRequired401()
return false, nil
}
16 view/config.go
View
@@ -11,14 +11,14 @@ import (
const StructTagKey = "view"
type PageConfiguration struct {
- Template string
- DefaultWriteHead Renderer // will be called after WriteTitle
- DefaultCSS string
- DefaultMetaViewport string
- DefaultWriteHeadScripts Renderer // write scripts as last element of the HTML head
- DefaultWriteScripts Renderer // will be called if Page.WriteScripts is nil
- PostWriteScripts Renderer // will always be called after Page.WriteScripts
- DefaultAuth Authenticator // Will be used for pages with Page.NeedsAuth == true
+ Template string
+ DefaultAdditionalHead Renderer // will be called after WriteTitle
+ DefaultCSS string
+ DefaultMetaViewport string
+ DefaultHeadScripts Renderer // write scripts as last element of the HTML head
+ DefaultScripts Renderer // will be called if Page.WriteScripts is nil
+ PostScripts Renderer // will always be called after Page.WriteScripts
+ DefaultAuth Authenticator // Will be used for pages with Page.NeedsAuth == true
}
type FormConfiguration struct {
2  view/constants.go
View
@@ -1,3 +1 @@
package view
-
-
18 view/contactform.go
View
@@ -8,20 +8,20 @@ import (
// ContactFormModel is a default form model for contact forms.
type ContactFormModel struct {
- Name model.String `gostart:"label=Your name|maxlen=40"`
- Email model.Email `gostart:"label=Your email address|required|maxlen=40"`
- Subject model.String `gostart:"label=Subject|maxlen=40"`
- Message model.Text `gostart:"label=Your message|required|cols=40|rows=10"`
+ Name model.String `view:"label=Your name" model:"maxlen=40"`
+ Email model.Email `view:"label=Your email address" model:"required|maxlen=40"`
+ Subject model.String `view:"label=Subject" model:"maxlen=40"`
+ Message model.Text `view:"label=Your message|cols=40|rows=10" model:"required"`
}
// NewContactForm creates a new contact form that sends submitted data to recipientEmail.
func NewContactForm(recipientEmail, subjectPrefix, formClass, buttonClass, formID string) *Form {
return &Form{
- Class: formClass,
- ButtonClass: buttonClass,
- ButtonText: "Send",
- SuccessMessage: "Message sent",
- FormID: formID,
+ Class: formClass,
+ SubmitButtonClass: buttonClass,
+ SubmitButtonText: "Send",
+ SuccessMessage: "Message sent",
+ FormID: formID,
GetModel: func(form *Form, response *Response) (interface{}, error) {
return &ContactFormModel{}, nil
},
3  view/fileinput.go
View
@@ -11,7 +11,8 @@ type FileInput struct {
Disabled bool
}
-func (self *FileInput) Render(response *Response, writer *utils.XMLWriter) (err error) {
+func (self *FileInput) Render(response *Response) (err error) {
+ writer := utils.NewXMLWriter(response)
writer.OpenTag("input").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
writer.Attrib("type", "file").Attrib("name", self.Name)
if self.Disabled {
40 view/form.go
View
@@ -265,7 +265,7 @@ func (self *Form) IsFieldExcluded(field *model.MetaData, response *Response) boo
auth, hasAuth = self.ModelFieldAuth[field.WildcardSelector()]
}
if hasAuth {
- ok, err := auth.Authenticate(context)
+ ok, err := auth.Authenticate(response.Request)
if err != nil {
fmt.Println("Error in view.Form.IsFieldExcluded(): " + err.Error())
}
@@ -281,7 +281,7 @@ func (self *Form) IsFieldExcluded(field *model.MetaData, response *Response) boo
// // Needs to pass all sub-Authenticators
// for _, name := range multi {
// if auth, ok := NamedAuthenticator(name); ok {
- // ok, err := auth.Authenticate(context)
+ // ok, err := auth.Authenticate(response)
// if err != nil {
// fmt.Println("Error in view.Form.IsFieldExcluded(): " + err.Error())
// }
@@ -292,7 +292,7 @@ func (self *Form) IsFieldExcluded(field *model.MetaData, response *Response) boo
// }
// } else {
if auth, ok := NamedAuthenticator(name); ok {
- ok, err := auth.Authenticate(context)
+ ok, err := auth.Authenticate(response.Request)
if ok {
// Only needs to pass one Authenticator
return false
@@ -316,7 +316,7 @@ func (self *Form) IsFieldExcluded(field *model.MetaData, response *Response) boo
// IsFieldExcluded and IsFieldHidden have different semantics.
func (self *Form) IsFieldVisible(field *model.MetaData, response *Response) bool {
return self.GetFieldFactory().CanCreateInput(field, self) &&
- !self.IsFieldExcluded(field, context) &&
+ !self.IsFieldExcluded(field, response) &&
!self.IsFieldHidden(field)
}
@@ -368,9 +368,8 @@ func (self *Form) DirectFieldLabel(metaData *model.MetaData) string {
return strings.Replace(metaData.NameOrIndex(), "_", " ", -1)
}
-func (self *Form) IsPost(response *Response) bool {
- return context.Request.Method == "POST" &&
- context.Request.FormValue(FormIDName) == self.FormID
+func (self *Form) IsPost(request *Request) bool {
+ return request.Method == "POST" && request.FormValue(FormIDName) == self.FormID
}
// FieldLabel returns a label for a form field generated from metaData.
@@ -401,7 +400,7 @@ func (self *Form) FieldInputClass(metaData *model.MetaData) string {
return class
}
-func (self *Form) Render(response *Response, writer *utils.XMLWriter) (err error) {
+func (self *Form) Render(response *Response) (err error) {
if self.OnSubmit == nil {
panic("view.Form.OnSubmit must not be nil")
}
@@ -417,13 +416,13 @@ func (self *Form) Render(response *Response, writer *utils.XMLWriter) (err error
var formModel interface{}
var hasErrors bool
content := Views{&HiddenInput{Name: FormIDName, Value: self.FormID}}
- isPost := self.IsPost(context)
+ isPost := self.IsPost(response.Request)
if self.GetModel == nil {
submitButton := self.GetFieldFactory().NewSubmitButton(self.GetSubmitButtonText(), self.SubmitButtonConfirm, self)
content = append(content, submitButton)
} else {
- formModel, err = self.GetModel(self, context)
+ formModel, err = self.GetModel(self, response)
if err != nil {
return err
}
@@ -435,7 +434,7 @@ func (self *Form) Render(response *Response, writer *utils.XMLWriter) (err error
setPostValues := &setPostValuesStructVisitor{
form: self,
formModel: formModel,
- context: context,
+ response: response,
}
err = model.Visit(formModel, setPostValues)
if err != nil {
@@ -447,7 +446,7 @@ func (self *Form) Render(response *Response, writer *utils.XMLWriter) (err error
formLayout: layout,
formModel: formModel,
formContent: &content,
- context: context,
+ response: response,
isPost: isPost,
}
err = model.Visit(formModel, validateAndFormLayout)
@@ -458,25 +457,25 @@ func (self *Form) Render(response *Response, writer *utils.XMLWriter) (err error
}
if isPost && !hasErrors {
- message, redirect, err := self.OnSubmit(self, formModel, context)
+ message, redirect, err := self.OnSubmit(self, formModel, response)
if err == nil {
if redirect == nil {
redirect = self.Redirect
}
if redirect != nil {
- return Redirect(redirect.URL(context.PathArgs...))
+ return Redirect(redirect.URL(response.Request.URLArgs...))
}
if message == "" {
message = self.SuccessMessage
}
if message != "" {
- self.GetLayout().SubmitSuccess(message, self, context, &content)
+ self.GetLayout().SubmitSuccess(message, self, response, &content)
}
} else {
if message == "" {
message = err.Error()
}
- self.GetLayout().SubmitError(message, self, context, &content)
+ self.GetLayout().SubmitError(message, self, response, &content)
}
}
@@ -488,24 +487,25 @@ func (self *Form) Render(response *Response, writer *utils.XMLWriter) (err error
action := self.Action
if action == "" {
action = "."
- if i := strings.Index(context.Request.RequestURI, "?"); i != -1 {
- action += context.Request.RequestURI[i:]
+ if i := strings.Index(response.Request.RequestURI, "?"); i != -1 {
+ action += response.Request.RequestURI[i:]
}
}
// Hack: Value of hidden input FormIDName is not available when
// enctype is multipart/form-data (bug?), so pass the form id as
// URL parameter
- if self.Enctype == MultipartFormData && context.Request.Method != "POST" {
+ if self.Enctype == MultipartFormData && response.Request.Method != "POST" {
action = utils.AddUrlParam(action, FormIDName, self.FormID)
}
+ writer := utils.NewXMLWriter(response)
writer.OpenTag("form").Attrib("id", self.id).AttribIfNotDefault("class", self.Class)
writer.Attrib("method", method)
writer.Attrib("action", action)
writer.AttribIfNotDefault("enctype", self.Enctype)
if len(content) > 0 {
content.Init(content)
- err = content.Render(context, writer)
+ err = content.Render(response)
if err != nil {
return err
}
4 view/functions.go
View
@@ -111,10 +111,10 @@ func RenderTemplate(filename string, out io.Writer, context interface{}) (err er
return templ.Render(out, context)
}
-func RenderChildViewsHTML(parent View, response *Response, writer *utils.XMLWriter) (err error) {
+func RenderChildViewsHTML(parent View, response *Response) (err error) {
parent.IterateChildren(func(parent View, child View) (next bool) {
if child != nil {
- err = child.Render(context, writer)
+ err = child.Render(response)
if err != nil {
return false
}
6 view/indirectviewwithurl.go
View
@@ -1,7 +1,5 @@
package view
-import "github.com/ungerik/go-start/utils"
-
func IndirectViewWithURL(viewWithURL *ViewWithURL) ViewWithURL {
return &indirectViewWithURL{viewWithURL}
}
@@ -22,8 +20,8 @@ func (self *indirectViewWithURL) IterateChildren(callback IterateChildrenCallbac
(*self.viewWithURL).IterateChildren(callback)
}
-func (self *indirectViewWithURL) Render(response *Response, writer *utils.XMLWriter) (err error) {
- return (*self.viewWithURL).Render(context, writer)
+func (self *indirectViewWithURL) Render(response *Response) (err error) {
+ return (*self.viewWithURL).Render(response)
}
func (self *indirectViewWithURL) URL(args ...string) string {
2  view/jquery.go
View
@@ -8,7 +8,7 @@ var (
func JQueryUIAutocompleteFromURL(domSelector string, dataURL URL, minLength int) View {
return RenderView(
func(response *Response) (err error) {
- url := dataURL.URL(response)
+ url := dataURL.URL(response.Request.URLArgs...)
response.Printf("<script>$('%s').autocomplete({source:'%s',minLength:%d});</script>", domSelector, url, minLength)
return nil
},
2  view/link.go
View
@@ -22,7 +22,7 @@ func (self *Link) Render(response *Response) (err error) {
writer.Attrib("target", "_blank")
}
if self.Model != nil {
- writer.Attrib("href", self.Model.URL(response.Request.PathArgs...))
+ writer.Attrib("href", self.Model.URL(response.Request.URLArgs...))
writer.AttribIfNotDefault("title", self.Model.LinkTitle(response))
writer.AttribIfNotDefault("rel", self.Model.LinkRel(response))
content := self.Model.LinkContent(response)
6 view/menu.go
View
@@ -31,7 +31,7 @@ func (self *Menu) Render(response *Response) (err error) {
if self.ActiveItemClass != "" {
// First try exact URL match
for i := range self.Items {
- url := self.Items[i].URL(response.Request.PathArgs...)
+ url := self.Items[i].URL(response.Request.URLArgs...)
if url == requestURL {
activeIndex = i
break
@@ -41,7 +41,7 @@ func (self *Menu) Render(response *Response) (err error) {
// If no exact URL match is found, search for sub pages
if activeIndex == -1 {
for i := range self.Items {
- url := self.Items[i].URL(response.Request.PathArgs...)
+ url := self.Items[i].URL(response.Request.URLArgs...)
if strings.HasPrefix(requestURL, url) {
activeIndex = i
// todo
@@ -58,7 +58,7 @@ func (self *Menu) Render(response *Response) (err error) {
}
itemClass := self.ItemClass
linkModel := self.Items[index]
- url := linkModel.URL(response.Request.Params...)
+ url := linkModel.URL(response.Request.URLArgs...)
// use i instead of index
if i == activeIndex {
14 view/modelview.go → view/modeliteratorview.go
View
@@ -6,10 +6,10 @@ import (
)
///////////////////////////////////////////////////////////////////////////////
-// ModelView
+// ModelIteratorView
type GetModelIteratorFunc func(response *Response) model.Iterator
-type GetModelViewFunc func(model interface{}, response *Response) (view View, err error)
+type GetModelIteratorViewFunc func(model interface{}, response *Response) (view View, err error)
func ModelIterator(iter model.Iterator) GetModelIteratorFunc {
return func(response *Response) model.Iterator {
@@ -17,18 +17,18 @@ func ModelIterator(iter model.Iterator) GetModelIteratorFunc {
}
}
-type ModelView struct {
+type ModelIteratorView struct {
ViewBase
- GetModelIterator GetModelIteratorFunc
- GetModelView GetModelViewFunc // nil Views will be ignored
+ GetModelIterator GetModelIteratorFunc
+ GetModelIteratorView GetModelIteratorViewFunc // nil Views will be ignored
}
-func (self *ModelView) Render(response *Response) (err error) {
+func (self *ModelIteratorView) Render(response *Response) (err error) {
var children Views
iter := self.GetModelIterator(response)
for model := iter.Next(); model != nil; model = iter.Next() {
- view, err := self.GetModelView(model, response)
+ view, err := self.GetModelIteratorView(model, response)
if err != nil {
return err
}
8 view/page.go
View
@@ -237,7 +237,7 @@ func (self *Page) Render(response *Response) (err error) {
templateContext.PreCSS = r.String()
}
if self.CSS != nil {
- templateContext.CSS = self.CSS.URL(response.Request.Params...)
+ templateContext.CSS = self.CSS.URL(response.Request.URLArgs...)
} else {
templateContext.CSS = Config.Page.DefaultCSS
}
@@ -289,9 +289,9 @@ func (self *Page) Render(response *Response) (err error) {
// Get dynamic style and scripts after self.Content.Render()
// because they are added in Render()
- templateContext.DynamicStyle = context.dynamicStyle.String()
- templateContext.DynamicHeadScripts = context.dynamicHeadScripts.String()
- templateContext.DynamicScripts = context.dynamicScripts.String()
+ templateContext.DynamicStyle = response.dynamicStyle.String()
+ templateContext.DynamicHeadScripts = response.dynamicHeadScripts.String()
+ templateContext.DynamicScripts = response.dynamicScripts.String()
self.Template.GetContext = TemplateContext(templateContext)
return self.Template.Render(response)
4 view/pagelink.go
View
@@ -17,14 +17,14 @@ func (self *PageLink) URL(args ...string) string {
func (self *PageLink) LinkContent(response *Response) View {
if self.Content == nil {
- return HTML(self.LinkTitle(context))
+ return HTML(self.LinkTitle(response))
}
return self.Content
}
func (self *PageLink) LinkTitle(response *Response) string {
if self.Title == "" {
- return self.Page.LinkTitle(context)
+ return self.Page.LinkTitle(response)
}
return self.Title
}
2  view/renderview.go
View
@@ -6,7 +6,7 @@ RenderView implements all View methods for a View.Render compatible function.
Example:
renderView := RenderView(
- func(response *Response, writer *utils.XMLWriter) error {
+ func(response *Response) error {
writer.Write([]byte("<html><body>Any Content</body></html>"))
return nil
},
2  view/request.go
View
@@ -28,7 +28,7 @@ type Request struct {
// URL returns the complete URL of the request including protocol and host.
func (self *Request) URLString() string {
url := self.RequestURI
- if !utils.StringStartsWith(url, "http") {
+ if !strings.HasPrefix(url, "http") {
url = "http://" + self.webContext.Request.Host + url
}
return url
5 view/response.go
View
@@ -5,6 +5,7 @@ import (
"container/heap"
"fmt"
"hash/crc32"
+ "net/http"
"github.com/ungerik/web.go"
)
@@ -105,6 +106,10 @@ func (self *Response) AuthorizationRequired401() {
self.Abort(401, "Authorization Required")
}
+func (self *Response) Header() http.Header {
+ return self.webContext.Header()
+}
+
func (self *Response) SetHeader(header string, value string, unique bool) {
self.webContext.SetHeader(header, value, unique)
}
2  view/shortcuts.go
View
@@ -63,7 +63,7 @@ func ScriptLink(url string) HTML {
func RSSLink(title string, url URL) View {
return RenderView(
func(response *Response) error {
- href := url.URL(response)
+ href := url.URL(response.Request.URLArgs...)
response.Printf("<link rel='alternate' type='application/rss+xml' title='%s' href='%s'>", title, href)
return nil
},
18 view/standardformfieldfactory.go
View
@@ -2,6 +2,8 @@ package view
import (
"fmt"
+ "strconv"
+
// "github.com/ungerik/go-start/debug"
"github.com/ungerik/go-start/model"
)
@@ -180,8 +182,20 @@ func (self *StandardFormFieldFactory) NewInput(withLabel bool, metaData *model.M
input = textField
case *model.Text:
- cols, _, _ := s.Cols(metaData) // will be zero if not available, which is OK
- rows, _, _ := s.Rows(metaData) // will be zero if not available, which is OK
+ var cols int // will be zero if not available, which is OK
+ if str, ok := metaData.Attrib(StructTagKey, "cols"); ok {
+ cols, err = strconv.Atoi(str)
+ if err != nil {
+ panic("Error in StandardFormFieldFactory.NewInput(): " + err.Error())
+ }
+ }
+ var rows int // will be zero if not available, which is OK
+ if str, ok := metaData.Attrib(StructTagKey, "rows"); ok {
+ rows, err = strconv.Atoi(str)
+ if err != nil {
+ panic("Error in StandardFormFieldFactory.NewInput(): " + err.Error())
+ }
+ }
input = &TextArea{
Class: form.FieldInputClass(metaData),
Name: metaData.Selector(),
18 view/standardformlayout.go
View
@@ -85,16 +85,16 @@ func (self *StandardFormLayout) BeginStruct(strct *model.MetaData, form *Form, r
func (self *StandardFormLayout) StructField(field *model.MetaData, validationErr error, form *Form, response *Response, formContent *Views) error {
fieldFactory := form.GetFieldFactory()
- if !fieldFactory.CanCreateInput(field, form) || form.IsFieldExcluded(field) {
+ if !fieldFactory.CanCreateInput(field, form) || form.IsFieldExcluded(field, response) {
return nil
}
grandParent := field.Parent.Parent
if grandParent != nil && (grandParent.Kind == model.ArrayKind || grandParent.Kind == model.SliceKind) {
- if form.IsFieldExcluded(grandParent) {
+ if form.IsFieldExcluded(grandParent, response) {
return nil
}
- return self.structFieldInArrayOrSlice(grandParent, field, validationErr, form, context, formContent)
+ return self.structFieldInArrayOrSlice(grandParent, field, validationErr, form, response, formContent)
}
if form.IsFieldHidden(field) {
@@ -126,8 +126,8 @@ func (self *StandardFormLayout) BeginArray(array *model.MetaData, form *Form, re
}
func (self *StandardFormLayout) ArrayField(field *model.MetaData, validationErr error, form *Form, response *Response, formContent *Views) error {
- if field.Kind == model.ValueKind && !form.IsFieldExcluded(field.Parent) && form.GetFieldFactory().CanCreateInput(field, form) {
- return self.arrayOrSliceFieldValue(field, validationErr, form, context, formContent)
+ if field.Kind == model.ValueKind && !form.IsFieldExcluded(field.Parent, response) && form.GetFieldFactory().CanCreateInput(field, form) {
+ return self.arrayOrSliceFieldValue(field, validationErr, form, response, formContent)
}
return nil
}
@@ -141,8 +141,8 @@ func (self *StandardFormLayout) BeginSlice(slice *model.MetaData, form *Form, re
}
func (self *StandardFormLayout) SliceField(field *model.MetaData, validationErr error, form *Form, response *Response, formContent *Views) error {
- if field.Kind == model.ValueKind && !form.IsFieldExcluded(field.Parent) && form.GetFieldFactory().CanCreateInput(field, form) {
- return self.arrayOrSliceFieldValue(field, validationErr, form, context, formContent)
+ if field.Kind == model.ValueKind && !form.IsFieldExcluded(field.Parent, response) && form.GetFieldFactory().CanCreateInput(field, form) {
+ return self.arrayOrSliceFieldValue(field, validationErr, form, response, formContent)
}
return nil
}
@@ -171,7 +171,7 @@ func (self *StandardFormLayout) structFieldInArrayOrSlice(arrayOrSlice, field *m
table.Init(table) // get an ID now
*formContent = append(*formContent, table)
// Add script for manipulating table rows
- context.AddScript(EditFormSliceTableScript, 0)
+ response.AddScript(EditFormSliceTableScript, 0)
}
tableModel := table.Model.(ViewsTableModel)
if field.Parent.Index == 0 {
@@ -227,7 +227,7 @@ func (self *StandardFormLayout) arrayOrSliceFieldValue(field *model.MetaData, va
table.Init(table) // get an ID now
*formContent = append(*formContent, table)
// Add script for manipulating table rows
- context.AddScript(EditFormSliceTableScript, 0)
+ response.AddScript(EditFormSliceTableScript, 0)
}
td, err := fieldFactory.NewInput(false, field, form)
if err != nil {
4 view/stringlink.go
View
@@ -15,14 +15,14 @@ func (self *StringLink) URL(args ...string) string {
func (self *StringLink) LinkContent(response *Response) View {
if self.Content == nil {
- return HTML(self.LinkTitle(context))
+ return HTML(self.LinkTitle(response))
}
return self.Content
}
func (self *StringLink) LinkTitle(response *Response) string {
if self.Title == "" {
- return self.URL(context.PathArgs...)
+ return self.URL(response.Request.URLArgs...)
}
return self.Title
}
2  view/template.go
View
@@ -98,7 +98,7 @@ func (self *Template) Render(response *Response) (err error) {
}
// todo: how to add config data to context if it's not a slice?
- // map[string][]string{"args": context.PathArgs}
+ // map[string][]string{"args": response.Request.URLArgs}
// Config, context.Web
return self.template.Render(response, context)
}
2  view/textpreview.go
View
@@ -40,7 +40,7 @@ func (self *TextPreview) Render(response *Response) (err error) {
writer.Content("... ")
if self.MoreLink != nil {
writer.OpenTag("a")
- writer.Attrib("href", self.MoreLink.URL(response))
+ writer.Attrib("href", self.MoreLink.URL(response.Request.URLArgs...))
writer.AttribIfNotDefault("title", self.MoreLink.LinkTitle(response))
content := self.MoreLink.LinkContent(response)
if content != nil {
4 view/urllink.go
View
@@ -15,14 +15,14 @@ func (self *URLLink) URL(args ...string) string {
func (self *URLLink) LinkContent(response *Response) View {
if self.Content == nil {
- return HTML(self.LinkTitle(context))
+ return HTML(self.LinkTitle(response))
}
return self.Content
}
func (self *URLLink) LinkTitle(response *Response) string {
if self.Title == "" {
- return self.Url.URL(context.PathArgs...)
+ return self.Url.URL(response.Request.URLArgs...)
}
return self.Title
}
6 view/viewpath.go
View
@@ -162,7 +162,7 @@ func (self *ViewPath) initAndRegisterViewsRecursive(parentPath string) {
return handleErr(err)
case self.NoAuth != nil:
from := url.QueryEscape(response.Request.RequestURI)
- to := self.NoAuth.URL(response.Request.Params...) + "?from=" + from
+ to := self.NoAuth.URL(response.Request.URLArgs...) + "?from=" + from
return handleErr(Redirect(to))
}
return handleErr(Forbidden("403 Forbidden: authentication required"))
@@ -175,7 +175,7 @@ func (self *ViewPath) initAndRegisterViewsRecursive(parentPath string) {
}
if Config.GlobalAuth != nil {
- if ok, err := Config.GlobalAuth.Authenticate(response); !ok {
+ if ok, err := Config.GlobalAuth.Authenticate(response.Request); !ok {
return handleNoAuth(err)
}
}
@@ -184,7 +184,7 @@ func (self *ViewPath) initAndRegisterViewsRecursive(parentPath string) {
self.Auth = Config.FallbackAuth
}
if self.Auth != nil {
- if ok, err := self.Auth.Authenticate(response); !ok {
+ if ok, err := self.Auth.Authenticate(response.Request); !ok {
return handleNoAuth(err)
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.