예제 #1
0
파일: new.go 프로젝트: rainycape/gondola
// LoadTemplates returns all the templates found in
// the given directory.
func LoadTemplates(dir string) ([]*Template, error) {
	dir, err := filepath.Abs(dir)
	if err != nil {
		return nil, err
	}
	files, err := ioutil.ReadDir(dir)
	if err != nil {
		return nil, err
	}
	var templates []*Template
	for _, v := range files {
		if s := v.Name()[0]; s == '.' || s == '_' {
			continue
		}
		if !v.IsDir() {
			continue
		}
		tmplDir := filepath.Join(dir, v.Name())
		var tmpl Template
		meta := filepath.Join(tmplDir, metaFile)
		if err := yaml.UnmarshalFile(meta, &tmpl); err != nil {
			return nil, err
		}
		tmpl.dir = tmplDir
		tmpl.Name = v.Name()
		templates = append(templates, &tmpl)
	}
	return templates, nil
}
예제 #2
0
func AppEngineAppId() string {
	var m map[string]interface{}
	if err := yaml.UnmarshalFile("app.yaml", &m); err == nil {
		// XXX: your-app-id is the default in app.yaml in GAE templates, found
		// in the gondolaweb repository. Keep these in sync.
		if id, ok := m["application"].(string); ok && id != "your-app-id" {
			return id
		}
	}
	return ""
}