/mdl-go-components

MDL for go

Primary LanguageGoMIT LicenseMIT

mdl-go-components

GoDoc

Material Design Lite components intergration for Go.

This integration is particularly suitable with my fork of mdl.

Install

glide get github.com/mh-cbon/mdl-go-components

Build

To build a specific resources location,

go build -ldflags="-X github.com/mh-cbon/mdl-go-components.Tplpath=YOURPATH" your-main.go

Usage

package mdlgocomponents_test

import (
	mgc "github.com/mh-cbon/mdl-go-components"
	"github.com/mh-cbon/mdl-go-components/components"
	"html/template"
	"io"
	"os"
)

var out io.Writer = os.Stdout

// demonstrate use of mdl-go-components
func Example_main() {

	// create  new template to reference mdl components blocks
	t := mgc.MustTemplate()

	// create a new render context: (template + writer)
	ctx := mgc.NewRenderContext(t, out)

	// create your components, and configure them
	btn := components.NewButton()
	btn.SetLabel("label")
	btn.Classes.Add("the-class-name")

	// attach components to a render context
	ctx.AttachTo(btn)

	// Call the component Render method to get the content.
	if _, err := btn.Render(); err != nil {
		panic(err)
	}

  // when suitable, components can be nested with the type
  // mgc.ViewComponentRenderer see tabs, dup, form ect.
}

Performance

troubled by html/template performance ? me too! Check this out :D