コード例 #1
0
ファイル: design.go プロジェクト: influx6/gu
// 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)
}
コード例 #2
0
ファイル: design.go プロジェクト: influx6/gu
// 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)
	}
}
コード例 #3
0
ファイル: design.go プロジェクト: influx6/gu
// mLink adds tagName with the provided value into the header bar for the
// page content.
func mLink(tag string, deffer bool) gu.StaticView {
	var static gu.StaticView
	static.Morph = true
	static.Content = trees.NewMarkup(tag, false)

	current := getResources().MustCurrentResource()

	if deffer {
		current.DeferLinks = append(current.DeferLinks, static)
	} else {
		current.Links = append(current.Links, static)
	}

	return static
}