Exemple #1
0
// DoStyle adds a element which generates a <style> tag.
func DoStyle(styles interface{}, bind interface{}, deferRender bool) {
	var rs *css.Rule

	switch so := styles.(type) {
	case string:
		rs = css.New(so)
	case *css.Rule:
		rs = so
	default:
		panic("Invalid Acceptable type for css: Only string or *css.Rule")
	}

	current := getResources().MustCurrentResource()

	var static gu.StaticView
	static.Morph = true
	static.Content = trees.CSSStylesheet(rs, bind)

	trees.NewAttr("resource-id", current.UUID()).Apply(static.Content)

	if deferRender {
		current.DeferLinks = append(current.DeferLinks, static)
		return
	}

	current.Links = append(current.Links, static)
}
Exemple #2
0
// DoHead adds the provided markup as part of the children to the head tag.
func DoHead(markup Viewable, deferRender bool) {
	var markupFn []*trees.Markup

	switch mo := markup.(type) {
	case func() []*trees.Markup:
		markupFn = mo()
	case []*trees.Markup:
		markupFn = mo
	case func() *trees.Markup:
		markupFn = []*trees.Markup{mo()}
	case *trees.Markup:
		markupFn = []*trees.Markup{mo}
	case string:
		markupFn = trees.ParseTree(mo)
	default:
		panic("Unknown markup processable type")
	}

	current := getResources().MustCurrentResource()

	for _, item := range markupFn {
		var static gu.StaticView
		static.Morph = true
		static.Content = item

		trees.NewAttr("resource-id", current.UUID()).Apply(static.Content)

		if deferRender {
			current.DeferLinks = append(current.DeferLinks, static)
			continue
		}

		current.Links = append(current.Links, static)
	}
}
Exemple #3
0
// DoMarkup returns a new instance of a provided value which either is a function
// which returns a needed trees.Markup or a trees.Markup or slice of trees.Markup
// itself.
func DoMarkup(markup Viewable, targets string, deferRender bool, targetAlreadyInDom bool) {
	var markupFn []*trees.Markup

	switch mo := markup.(type) {
	case func() []*trees.Markup:
		markupFn = mo()
	case []*trees.Markup:
		markupFn = mo
	case func() *trees.Markup:
		markupFn = []*trees.Markup{mo()}
	case *trees.Markup:
		markupFn = []*trees.Markup{mo}
	case string:
		markupFn = trees.ParseTree(mo)
	default:
		panic("Unknown markup processable type")
	}

	current := getResources().MustCurrentResource()

	for _, markup := range markupFn {
		static := gu.Static(markup)
		static.Morph = true

		trees.NewAttr("resource-id", current.UUID()).Apply(static.Content)

		if deferRender {
			current.DRenderables = append(current.DRenderables, targetRenderable{
				Targets: targets,
				View:    static,
			})

			continue
		}

		if !deferRender && targetAlreadyInDom {
			current.Renderables = append(current.Renderables, targetRenderable{
				Targets: targets,
				View:    static,
			})

			continue
		}

		if !deferRender && !targetAlreadyInDom && targets != "" {
			current.DRenderables = append(current.DRenderables, targetRenderable{
				View:    static,
				Targets: targets,
			})

			continue
		}

		current.Renderables = append(current.Renderables, targetRenderable{
			View:    static,
			Targets: targets,
		})

	}
}
Exemple #4
0
// RenderPathWithScript creates a complete markup definition using the giving set of Resource
// Definition by applying the giving dispatch.Path, and adding the script path as a script tag.
func (rs *Resources) RenderPathWithScript(path dispatch.Path, script string) *trees.Markup {
	result := rs.Resolve(path)

	if script != "" {
		src := trees.NewAttr("src", script)
		srctype := trees.NewAttr("gu-script-root", "true")
		scriptElem := trees.NewMarkup("script", false)

		src.Apply(scriptElem)
		srctype.Apply(scriptElem)

		return rs.render([]*trees.Markup{scriptElem}, result...)
	}

	return rs.render(nil, result...)
}
Exemple #5
0
func generateMarkup() *trees.Markup {
	body := trees.NewMarkup("body", false)
	trees.NewCSSStyle("width", "auto").Apply(body)
	trees.NewAttr("id", "main-wrapper").Apply(body)

	root := trees.NewMarkup("div", false)
	trees.NewAttr("id", "root-div").Apply(root)
	trees.NewAttr("class", "roots").Apply(root)
	trees.NewCSSStyle("width", "100px").Apply(root)
	trees.NewMarkup("section", false).Apply(root)
	root.Apply(body)

	root2 := trees.NewMarkup("div", false)
	trees.NewAttr("id", "root-div-2").Apply(root2)
	trees.NewAttr("class", "roots").Apply(root2)
	root2.Apply(body)

	label := trees.NewMarkup("label", false)
	trees.NewCSSStyle("width", "200px").Apply(label)
	label.Apply(root2)

	return body
}
Exemple #6
0
// DoMeta adds a element which generates a <style> tag.
func DoMeta(props map[string]string) {
	ml := mLink("meta", false)
	for name, val := range props {
		trees.NewAttr(name, val).Apply(ml.Content)
	}
}
Exemple #7
0
// DoScript adds a element which generates a <style> tag.
func DoScript(src string, mtype string, defered bool) {
	ml := mLink("script", defered)
	trees.NewAttr("src", src).Apply(ml.Content)
	trees.NewAttr("type", mtype).Apply(ml.Content)
}
Exemple #8
0
// DoCSS adds a element which generates a <style> tag.
func DoCSS(src string, defered bool) {
	ml := mLink("link", defered)
	trees.NewAttr("href", src).Apply(ml.Content)
	trees.NewAttr("rel", "stylesheet").Apply(ml.Content)
	trees.NewAttr("type", "text/css").Apply(ml.Content)
}
Exemple #9
0
// DoLink adds a element which generates a <link> tag.
func DoLink(url string, mtype string, defered bool) {
	ml := mLink("link", defered)
	trees.NewAttr("href", url).Apply(ml.Content)
	trees.NewAttr("rel", mtype).Apply(ml.Content)
}