示例#1
0
func (self *FormFieldFactory) CanCreateInput(metaData *model.MetaData, form *view.Form) bool {
	debug.Nop()
	if metaData.Value.CanAddr() {
		if _, ok := metaData.Value.Addr().Interface().(*ImageRef); ok {
			return true
		}
	}
	return self.FormFieldFactoryWrapper.Wrapped.CanCreateInput(metaData, form)
}
示例#2
0
func Load(configFile string, packages ...Package) {
	debug.Nop()
	data, err := ioutil.ReadFile(configFile)
	if err != nil {
		log.Panicf("Error while reading config file %s: %s", configFile, err)
	}
	Packages = packages
	switch path.Ext(configFile) {
	case ".json":
		// Compact JSON to make it easier to extract JSON per package
		var buf bytes.Buffer
		err = json.Compact(&buf, data)
		if err != nil {
			log.Panicf("Error in JSON config file %s: %s", configFile, err)
		}
		data = buf.Bytes()

		// Unmarshal and init packages in given order
		for _, pkg := range packages {
			// Extract JSON only for this package
			key := []byte(`"` + pkg.Name() + `":{`)
			begin := bytes.Index(data, key)
			if begin == -1 {
				continue
			}
			begin += len(key) - 1
			end := 0
			braceCounter := 0
			for i := begin; i < len(data); i++ {
				switch data[i] {
				case '{':
					braceCounter++
				case '}':
					braceCounter--
				}
				if braceCounter == 0 {
					end = i + 1
					break
				}
			}

			err = json.Unmarshal(data[begin:end], pkg)
			if err != nil {
				log.Panicf("Error while unmarshalling JSON from config file %s: %s", configFile, err)
			}
			err := pkg.Init()
			if err != nil {
				log.Panicf("Error while initializing package %s: %s", pkg.Name(), err)
			}
		}

	default:
		panic("Unsupported config file: " + configFile)
	}
}
示例#3
0
func main() {
	debug.Nop()

	///////////////////////////////////////////////////////////////////////////
	// Load configuration

	defer config.Close() // Close all packages on exit

	config.Load("config.json",
		&EmailConfig{&email.Config},
		&mongo.Config,
		&user.Config,
		&view.Config,
		&media.Config,
		&mongomedia.Config,
	)

	///////////////////////////////////////////////////////////////////////////
	// Ensure that an admin user exists

	var admin models.User
	_, err := user.EnsureExists("admin", "*****@*****.**", "test", true, &admin)
	errs.PanicOnError(err)
	admin.Admin = true
	err = admin.Save()
	errs.PanicOnError(err)

	///////////////////////////////////////////////////////////////////////////
	// Config view

	view.Config.NamedAuthenticators["admin"] = views.Admin_Auth
	view.Config.Debug.Mode = true
	// view.Config.Debug.LogPaths = true
	// view.Config.Debug.LogRedirects = true
	// view.Config.DisableCachedViews = true
	// view.Config.GlobalAuth = view.NewBasicAuth("statuplive.in", "gostart", "gostart")

	///////////////////////////////////////////////////////////////////////////
	// Run server

	view.RunServer(views.Paths())
}
示例#4
0
func FormModel(model interface{}) GetFormModelFunc {
	debug.Nop()
	return func(form *Form, ctx *Context) (interface{}, error) {
		return model, nil
	}
}
示例#5
0
func Visit(model interface{}, visitor Visitor) error {
	debug.Nop()
	return reflection.VisitStruct(model, &structVisitorWrapper{visitor: visitor})
}
示例#6
0
func init() {
	debug.Nop()
}
示例#7
0
文件: image.go 项目: strogo/go-start
// VersionSourceRect searches and returns an existing matching version,
// or a new one will be created and saved.
func (self *Image) VersionSourceRect(sourceRect image.Rectangle, width, height int, grayscale bool, outsideColor color.Color) (im *ImageVersion, err error) {
	debug.Nop()
	// debug.Printf(
	// 	"VersionSourceRect: from %dx%d image take rectangle [%d,%d,%d,%d] (%dx%d) and scale it to %dx%d",
	// 	self.Width(),
	// 	self.Height(),
	// 	sourceRect.Min.X,
	// 	sourceRect.Min.Y,
	// 	sourceRect.Max.X,
	// 	sourceRect.Max.Y,
	// 	sourceRect.Dx(),
	// 	sourceRect.Dy(),
	// 	width,
	// 	height,
	// )

	if self.Grayscale() {
		grayscale = true // Ignore color requests when original image is grayscale
	}

	// Search for exact match
	for i := range self.Versions {
		v := &self.Versions[i]
		match := v.SourceRect.Rectangle() == sourceRect &&
			v.Width.GetInt() == width &&
			v.Height.GetInt() == height &&
			v.OutsideColor.EqualsColor(outsideColor) &&
			v.Grayscale.Get() == grayscale
		if match {
			return v, nil
		}
	}

	// No exact match, create version
	origImage, err := self.Versions[0].LoadImage()
	if err != nil {
		return nil, err
	}

	var versionImage image.Image
	if grayscale {
		versionImage = image.NewGray(image.Rect(0, 0, width, height))
	} else {
		versionImage = image.NewRGBA(image.Rect(0, 0, width, height))
	}
	if sourceRect.In(self.Rectangle()) {
		// debug.Print("VersionSourceRect: rectangle is within image")

		// versionImage = ResampleImage(origImage, sourceRect, width, height)
		subImage := SubImageWithoutOffset(origImage, sourceRect)
		err = graphics.Scale(versionImage.(draw.Image), subImage)
		if err != nil {
			return nil, err
		}
		if grayscale && !self.Grayscale() {
			var grayVersion image.Image = image.NewGray(versionImage.Bounds())
			draw.Draw(grayVersion.(draw.Image), versionImage.Bounds(), versionImage, image.ZP, draw.Src)
			versionImage = grayVersion
		}
	} else {
		// debug.Print("VersionSourceRect: rectangle is not completely within image, using outsideColor")

		// Fill version with outsideColor
		draw.Draw(versionImage.(draw.Image), versionImage.Bounds(), image.NewUniform(outsideColor), image.ZP, draw.Src)
		// Where to draw the source image into the version image
		var destRect image.Rectangle
		if !(sourceRect.Min.X < 0 || sourceRect.Min.Y < 0) {
			panic("touching from outside means that sourceRect x or y must be negative")
		}
		sourceW := float64(sourceRect.Dx())
		sourceH := float64(sourceRect.Dy())
		destRect.Min.X = int(float64(-sourceRect.Min.X) / sourceW * float64(width))
		destRect.Min.Y = int(float64(-sourceRect.Min.Y) / sourceH * float64(height))
		destRect.Max.X = destRect.Min.X + int(float64(self.Width())/sourceW*float64(width))
		destRect.Max.Y = destRect.Min.Y + int(float64(self.Height())/sourceH*float64(height))

		// destImage := ResampleImage(origImage, origImage.Bounds(), destRect.Dx(), destRect.Dy())
		// draw.Draw(versionImage.(draw.Image), destRect, destImage, image.ZP, draw.Src)
		subImage := SubImageWithoutOffset(origImage, sourceRect)
		destImage := SubImageWithoutOffset(versionImage, destRect)
		err = graphics.Scale(destImage.(draw.Image), subImage)
		if err != nil {
			return nil, err
		}
	}

	// Save new image version
	version := self.addVersion(self.Filename(), self.ContentType(), sourceRect, width, height, grayscale)
	err = version.SaveImage(versionImage)
	if err != nil {
		return nil, err
	}
	err = self.Save()
	if err != nil {
		return nil, err
	}
	return version, nil
}