コード例 #1
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)
	}
}
コード例 #2
0
ファイル: parser_test.go プロジェクト: influx6/gu
func TestParser(t *testing.T) {
	trees.SetMode(trees.Testing)
	defer trees.SetMode(trees.Normal)

	result := trees.ParseTree(`
		<!doctype html>
		<html>
			<head></head>
			<body>
				<div class="racket" id="racket-wrapper">
		      <a href="#" rel="bounce postive">Bounce +</a>
		    </div>

		    <!--thertorial words-->

				<div class="racket" id="racket-wrapper-2">
		      <a href="#" rel="bounce negative">Bounce -</a>
		    </div>
			</body>
		</html>
  `)

	var html []string
	for _, res := range result {
		html = append(html, res.HTML())
	}

	t.Logf("\t%s\t Parser should have produced markup for html: %q", success, strings.Join(html, ""))
}
コード例 #3
0
ファイル: design.go プロジェクト: influx6/gu
// 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,
		})

	}
}