mdlgocomponents

package module
v0.0.0-...-d2ad1d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2016 License: MIT Imports: 4 Imported by: 0

README

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

Documentation

Overview

Example (Main)

demonstrate use of mdl-go-components

package main

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 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.
}
Output:

Index

Examples

Constants

This section is empty.

Variables

View Source
var Tplpath = ""

Functions

func GuessGlob

func GuessGlob() string

func MustTemplate

func MustTemplate() *template.Template

func Template

func Template() (*template.Template, error)

Types

type ContextRenderer

type ContextRenderer interface {
	GetId() string
	RenderComponent(view ViewComponentRenderer, args ...interface{}) (string, error)
	SetDefaultTo(view ViewComponentContextSetter)
	AttachTo(view ViewComponentContextSetter)
}

type Ider

type Ider interface {
	SetId(s string)
	GetId() string
}

type RenderContext

type RenderContext struct {
	// contains filtered or unexported fields
}

func NewRenderContext

func NewRenderContext(t Templater, wr io.Writer) *RenderContext

func (*RenderContext) AttachTo

func (ctx *RenderContext) AttachTo(view ViewComponentContextSetter)

func (*RenderContext) GetId

func (ctx *RenderContext) GetId() string

func (*RenderContext) GetTemplate

func (ctx *RenderContext) GetTemplate() Templater

func (*RenderContext) GetWriter

func (ctx *RenderContext) GetWriter() io.Writer

func (*RenderContext) RenderComponent

func (ctx *RenderContext) RenderComponent(view ViewComponentRenderer, args ...interface{}) (string, error)

func (*RenderContext) SetDefaultTo

func (ctx *RenderContext) SetDefaultTo(view ViewComponentContextSetter)

func (*RenderContext) SetTemplate

func (ctx *RenderContext) SetTemplate(s Templater)

func (*RenderContext) SetWriter

func (ctx *RenderContext) SetWriter(s io.Writer)

type Templater

type Templater interface {
	ExecuteTemplate(wr io.Writer, name string, args interface{}) error
}

type ViewComponent

type ViewComponent struct {
	// contains filtered or unexported fields
}

func (*ViewComponent) GetBlock

func (view *ViewComponent) GetBlock() string

func (*ViewComponent) GetRenderContext

func (view *ViewComponent) GetRenderContext() ContextRenderer

func (*ViewComponent) SetBlock

func (view *ViewComponent) SetBlock(s string)

func (*ViewComponent) SetDefaultRenderContext

func (view *ViewComponent) SetDefaultRenderContext(ctx ContextRenderer)

func (*ViewComponent) SetRenderContext

func (view *ViewComponent) SetRenderContext(s ContextRenderer)

type ViewComponentContextSetter

type ViewComponentContextSetter interface {
	SetDefaultRenderContext(r ContextRenderer)
	SetRenderContext(r ContextRenderer)
}

type ViewComponentRenderer

type ViewComponentRenderer interface {
	SetDefaultRenderContext(r ContextRenderer)
	SetRenderContext(r ContextRenderer)
	GetRenderContext() ContextRenderer

	SetBlock(s string)
	GetBlock() string

	Render(args ...interface{}) (string, error)
}

type ViewData

type ViewData struct {
	Component interface{}
	Data      interface{}
}

func NewViewData

func NewViewData(datas ...interface{}) *ViewData

Directories

Path Synopsis
mdl

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL