Exemple #1
0
// render performs the needed work of collecting the giving markups and
// creating the complete html rendering.
func (rs *Resources) render(attachElems []*trees.Markup, rsx ...*ResourceDefinition) *trees.Markup {
	var head = trees.NewMarkup("head", false)
	var body = trees.NewMarkup("body", false)

	for _, rx := range rsx {

		for _, item := range rx.Links {
			item.Render().Apply(head)
		}

		for _, item := range rx.Renderables {
			markup := item.View.Render()

			if item.Targets != "" {
				for _, target := range trees.Query.QueryAll(body, item.Targets) {
					markup.Apply(target)
				}

				continue
			}

			markup.Apply(body)
		}

		// Render all deferred renderables into the body markup
		for _, item := range rx.DRenderables {
			markup := item.View.Render()

			if item.Targets != "" {
				for _, target := range trees.Query.QueryAll(body, item.Targets) {
					markup.Apply(target)
				}

				continue
			}

			markup.Apply(body)
		}

		for _, item := range rx.DeferLinks {
			item.Render().Apply(body)
		}
	}

	for _, item := range attachElems {
		item.Apply(body)
	}

	htmlMarkup := trees.NewMarkup("html", false)
	head.Apply(htmlMarkup)
	body.Apply(htmlMarkup)

	return htmlMarkup
}
Exemple #2
0
// Render returns the groups markup for the giving render group.
func (v *view) Render() *trees.Markup {
	defer v.rendered.Publish()

	v.renderedBefore = true

	if len(v.renders) == 0 {
		return trees.NewMarkup(v.tag, false)
	}

	var root *trees.Markup

	if len(v.renders) > 1 {
		root = trees.NewMarkup(v.tag, false)

		for _, view := range v.renders {
			view.Render().Apply(root)
		}

	} else {
		root = v.renders[0].Render()
	}

	if v.live != nil {
		live := v.live
		live.EachEvent(func(e *trees.Event, _ *trees.Markup) {
			if e.Handle != nil {
				e.Handle.End()
			}
		})

		v.live = nil
		root.Reconcile(live)

		// Clear out internal references with the current live markup.
		// TODO: Check if this will cause unknown side effects.
		if live != root {
			live.Empty()
		}
	}

	root.SwapUID(v.uuid)
	root = root.ApplyMorphers()

	v.live = root

	return root
}
Exemple #3
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 #4
0
// 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
}
Exemple #5
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...)
}