Exemplo n.º 1
0
// Generate a BaseHRef-relative link to this page
func (d *DataObjectBase) Link(args ...string) string {
	hier := orm.IsHierarchical(d.ClassName)
	if !hier {
		return ""
	}

	obj := interface{}(d)
	res := d.URLSegment

	// @todo data.Eval.(int) may fail for a map where the ParentID may have type of string
	for parentID := data.Eval(obj, "ParentID").(int); parentID > 0; {
		// @todo don't hardcode "SiteTree", derive the base class using metadata.
		q := orm.NewQuery("SiteTree").Where("\"SiteTree_Live\".\"ID\"=" + strconv.Itoa(parentID))
		ds, e := q.Run()
		if e != nil {
			return ""
		}
		items, _ := ds.(orm.DataList).Items()
		obj = items[0]
		res = data.Eval(obj, "URLSegment").(string) + "/" + res
	}

	for _, a := range args {
		res += "/" + a
	}

	if res == "home" {
		res = "/"
	}

	return res
}
Exemplo n.º 2
0
// helper function to get a variable or function reference from a context object. If context
// implements goss.Evaluater, then call Get directly on it. Otherwise use the default locator
// via data.Eval
func (exec *executer) evaluate(context interface{}, name string, args ...interface{}) interface{} {
	e, ok := context.(goss.Evaluater)
	if ok {
		return e.Get(name, args...)
	}
	return data.Eval(context, name, args...)
}
Exemplo n.º 3
0
func (c *ContentControllerStruct) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	className := data.Eval(c.GetObject(), "ClassName").(string)
	templates := []string{"Page", className}
	e := template.RenderWith(w, templates, c.context, nil, r)

	if e != nil {
		ErrorHandler(w, e)
		return
	}
}
Exemplo n.º 4
0
// LinkingMode returns one of 3 values:
// - "link" if none of this page or its children are current
// - "section" if a child of this page is open
// - "current" this page is open
func LinkingMode(r *http.Request, obj interface{}) string {
	// get relative path to obj
	// get relative path of request URL
	// if same -> current
	// if request path is a subset of obj path
	// otherwise link
	requestRel := r.URL.Path
	pageRel := data.Eval(obj, "Link").(string)
	// fmt.Printf("Linking mode: requestRel: '%s', pageRel: '%s'\n", requestRel, pageRel)
	if requestRel == pageRel {
		return "current"
	} else if len(requestRel) < len(pageRel) && requestRel == pageRel[0:len(requestRel)] {
		return "section"
	}
	return "link"
}
Exemplo n.º 5
0
// Given a page, find a controller that says it can handle it, and render the page with that.
func renderWithMatchedController(w http.ResponseWriter, r *http.Request, page interface{}) {
	// locate a controller%s\n", page)
	className := data.Eval(page, "ClassName").(string)
	c, e := getControllerInstance(className)

	if e != nil {
		ErrorHandler(w, e)
		return
	}

	c.Init(r)

	// if the controller is a ContentController then set the object.
	if cc, ok := c.(ContentController); ok {
		cc.SetObject(page)
		cc.SetContext(c)
	}

	//	fmt.Printf("after init c is %s\n", c)
	c.ServeHTTP(w, r)
}