Permalink
Browse files

finished merge from master

  • Loading branch information...
2 parents d0f5027 + 2fb9615 commit af45068a8c358ce1f0db0ec62b45babfd27c1ce7 @ungerik committed Jul 30, 2012
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
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
}
}
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 {
View
@@ -2,28 +2,28 @@ 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
}
err = reader.Close()
if err != nil {
return err
}
- context.Header().Set("Content-Type", contentType)
+ response.Header().Set("Content-Type", contentType)
return nil
},
))
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 {
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 {
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
}
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 {
View
@@ -5,3 +5,5 @@ type Configuration struct {
}
var Config Configuration
+
+const StructTagKey = "model"
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 {
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")
}
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")
}
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")
}
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 {
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")
-}
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 {
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")
-}
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 {
Oops, something went wrong.

0 comments on commit af45068

Please sign in to comment.