gu

package module
v2.0.3+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2017 License: MIT Imports: 9 Imported by: 0

README

Gu

Go Report Card Build Status

A component rendering library for Go. It efficiently renders standard HTML both on the frontend and backend.

Install

go get -u github.com/gu-io/gu/...

Example

Greeter Example Components Example

CLI

Gu provides an cli tooling which is installed when go get is done for this package, the tooling provides easier means of generating a project and components using the gu project, among other features.

It is provided to both improve the workflow of the user, as well as to provide quick setup of your project. Provided below are examples of workflows which are generally done when developing with Gu.

  • Creating a Gu project
> ➜ gu app box
- Creating package directory: "box"
- Creating package directory: "box/public"
- Creating package directory: "box/public/less"
- Add file to package directory: "box/public/less/box.less"
- Add file to package directory: "box/settings.toml"
- Add file to package directory: "box/settings_bundle.go"
- Add file to package directory: "box/public_bundle.go"
- Add file to package directory: "box/public/box_bundle.go"
- Add file to package directory: "box/box.go"

➜ cd box
➜ gu driver js
- Creating package directory: "driver/js"
- Add file to package directory: "driver/js/main.go"
- Add file to package directory: "public/index.html"

  • Add a component with initial boilerplate

➜ gu component sugarbar
- Creating package directory: "/home/ewe/devlabs/src/github.com/gu-io/box/sugarbar"
- Add file to package directory: "sugarbar/sugarbar.go"
- Add file to package directory: "sugarbar/sugarbar_bundle.go"
- Add file to package directory: "sugarbar/generate.go"

The generated package can be found here https://github.com/gu-io/box.

Goals

  • Dead Simple API.
  • Embeddable Resources.
  • Simplicity and Flexibility as core philosophies.
  • Able to render on both front and back end.
  • Quickly craft your UI without touching HTML.
  • Share code between backend and frontend.
  • Efficient and extendable asset bundling for all possible file types.

Advantages

  • Complex component libraries can be built up and shared as Golang packages.
  • Components are hierarchical allowing further reuse.
  • Event handling is simple and strongly typed.
  • Compile time safety
  • Bundles all assets (with less files natively converted)
  • Minify all css outputs.

Examples

The github repo Components contains gu style components that showcases how to build components with gu.

Concepts

Gu is fundamentally a library built to provide rendering capabilities with simple principles in building components that make up your application. There exists certain concepts which should be grasped due to the architecture and these do make it easier to reason and thinking when using the library. To fully grasp these concept, there is set below a series of short explanations about the different core pieces that make up the libray and I hope these will help in the use of this libray and it's examples.

How to Contribute

Please read the contribution guidelines Contribution Guidelines

Limitations

Gu by it's very design and architecture is "Simple". It lacks the bells and whistles of similar frameworks and libraries. It's geared to solve your rendering needs and due to this, certain limitations exists with it.

  • Gu provides no react like flux structure.

  • Gu only focuses on providing you sets of structures able to work on the client and server for HTML/HTML5 rendering markup rendering with diffing support.

  • Gu component are simply Go types that implements Gu's set of interfaces and nothing else.

Once these limitations are not a problem, I believe using the library should help in achieving the end product and design you wish to build.

Last Note

Please feel free to make issues on suggestions, questions, changes, bugs or improvements for the library. They all will be gladly received with much fan-fare.

God bless.

Documentation

Overview

Package gu provides a UI framework for Go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewKey

func NewKey() string

NewKey returns a new string key which is path of the incremental key which once initializes constantly increases.

Types

type AppJSON

type AppJSON struct {
	AppID         string             `json:"AppId"`
	Name          string             `json:"Name"`
	Title         string             `json:"Title"`
	Head          []ViewJSON         `json:"Head"`
	Body          []ViewJSON         `json:"Body"`
	HeadResources []trees.MarkupJSON `json:"HeadResources"`
	BodyResources []trees.MarkupJSON `json:"BodyResources"`
}

AppJSON defines a struct which holds the giving sets of tree changes to be rendered.

type AppUpdate

type AppUpdate struct {
	App *NApp
}

AppUpdate defines a struct which is used to notify the need to update a App. @notification:event

type AppUpdateHandler

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

AppUpdateHandler defines a structure type which implements the AppUpdateSubscriber interface and the EventDistributor interface.

func NewAppUpdateHandler

func NewAppUpdateHandler(fn func(AppUpdate)) *AppUpdateHandler

NewAppUpdateHandler returns a new instance of a AppUpdateHandler.

func (*AppUpdateHandler) Handle

func (sn *AppUpdateHandler) Handle(receive interface{})

Handle takes the giving value and asserts the expected value to match the AppUpdate type then passes it to the Receive method.

func (*AppUpdateHandler) Receive

func (sn *AppUpdateHandler) Receive(elem AppUpdate)

Receive takes the giving value and execute it against the underline handler.

type AppUpdateNotification

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

AppUpdateNotification defines a structure type which must be used to receive AppUpdate type has a event.

func NewAppUpdateNotification

func NewAppUpdateNotification() *AppUpdateNotification

NewAppUpdateNotification returns a new instance of NewAppUpdateNotification.

func NewAppUpdateNotificationWith

func NewAppUpdateNotificationWith(validation func(AppUpdate) bool) *AppUpdateNotification

NewAppUpdateNotificationWith returns a new instance of AppUpdateNotification.

func (*AppUpdateNotification) Handle

func (sn *AppUpdateNotification) Handle(elem interface{})

Handle takes the giving value and asserts the expected value to be of the type and pass on to it's underline subscribers else ignoring the event.

func (*AppUpdateNotification) Notify

Notify adds the given subscriber into the notification list and will await an update of a new event of the given AppUpdate type.

func (*AppUpdateNotification) UnNotify

func (sn *AppUpdateNotification) UnNotify(sub AppUpdateSubscriber)

UnNotify removes the given subscriber from the notification's list if found from future events.

type AppUpdateSubscriber

type AppUpdateSubscriber interface {
	Receive(AppUpdate)
}

AppUpdateSubscriber defines a interface that which is used to subscribe specifically for events AppUpdate type.

type ApplyView

type ApplyView struct {
	Morph    bool
	Mounted  Subscriptions
	Rendered Subscriptions
	Content  trees.Appliable
	// contains filtered or unexported fields
}

ApplyView defines a MarkupRenderer implementing structure which returns its Content has its markup.

func ApplyStatic

func ApplyStatic(tree trees.Appliable) *ApplyView

ApplyStatic defines a toplevel function which returns a new instance of a StaticView using the provided markup as its content.

func (*ApplyView) Render

func (a *ApplyView) Render() *trees.Markup

Render returns the markup for the static view.

func (*ApplyView) RenderHTML

func (a *ApplyView) RenderHTML() template.HTML

RenderHTML returns the html template version of the StaticView content.

func (*ApplyView) UUID

func (a *ApplyView) UUID() string

UUID returns the RenderGroup UUID for identification.

type Component

type Component struct {
	Reactive

	Target string

	Rendering Renderable
	Router    router.Resolver
	// contains filtered or unexported fields
}

Component defines a struct which

func (*Component) Render

func (c *Component) Render() *trees.Markup

Render returns the markup corresponding to the internal Renderable.

func (Component) UUID

func (c Component) UUID() string

UUID returns the identification for the giving component.

type Identity

type Identity interface {
	UUID() string
}

Identity defines an interface which expoese the identity of a giving object.

type Location

type Location interface {
	// Current Location of the driver path.
	Location() router.PushEvent

	// Navigate the Driver to the provided path.
	Navigate(router.PushDirectiveEvent)
}

Location defines an interface which exposes a type which allows the retrieval and setting of the location of a given display.

type MarkupRenderer

type MarkupRenderer interface {
	Renderable
	RenderHTML() template.HTML
}

MarkupRenderer provides a interface for a types capable of rendering dom markup.

type NApp

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

NApp defines a struct which encapsulates all the core view management functions for views.

func App

func App(title string, router *router.Router) *NApp

App creates a new app structure to rendering gu components.

func (*NApp) ActivateRoute

func (app *NApp) ActivateRoute(es interface{})

ActivateRoute actives the views which are to be rendered.

func (*NApp) Active

func (app *NApp) Active() bool

Active returns true/false if the giving app is active and has already received rendering.

func (*NApp) AddAsset

func (app *NApp) AddAsset(asset *trees.Markup, target ViewTarget)

AddAsset adds giving tree.Markup has assets to be loaded either in the head or body based on the posiiton desired.

func (*NApp) Do

func (app *NApp) Do(appFun func(*NApp)) *NApp

Do calls the giving function providing it with the NApp instance.

func (*NApp) InitApp

func (app *NApp) InitApp(location Location)

InitApp sets the Location to be used by the NApp and it's views and components.

func (*NApp) Location

func (app *NApp) Location() router.PushEvent

Location returns the current route. It stores all set routes and returns the last route else returning a

func (*NApp) Mounted

func (app *NApp) Mounted()

Mounted notifies all active views that they have been mounted.

func (*NApp) Navigate

func (app *NApp) Navigate(pe router.PushDirectiveEvent)

Navigate sets the giving app location and also sets the location of the NOOPLocation which returns that always.

func (*NApp) PushViews

func (app *NApp) PushViews(event router.PushEvent) []*NView

PushViews returns a slice of views that match and pass the provided path.

func (*NApp) Render

func (app *NApp) Render(es interface{}) *trees.Markup

Render returns the giving rendered tree of the app respective of the path found.

func (*NApp) RenderJSON

func (app *NApp) RenderJSON(es interface{}) AppJSON

RenderJSON returns the giving rendered tree of the app respective of the path found as jons structure with markup content.

func (*NApp) Resources

func (app *NApp) Resources() ([]*trees.Markup, []*trees.Markup)

Resources return the giving resource headers which relate with the view.

func (*NApp) UUID

func (app *NApp) UUID() string

UUID returns the uuid specific to the giving view.

func (*NApp) View

func (app *NApp) View(renderable interface{}, route string, target ViewTarget) *NView

View returns a new instance of the view object.

type NView

type NView struct {
	Reactive
	// contains filtered or unexported fields
}

NView defines a structure to encapsulates all rendering component for a given view.

func (*NView) Component

func (v *NView) Component(renderable interface{}, order RenderingOrder, route string, target string)

Component adds the provided component into the selected view.

func (*NView) Disabled

func (v *NView) Disabled() bool

Disabled returns true/false if the giving view is disabled.

func (*NView) Do

func (v *NView) Do(viewFun func(*NView)) *NView

Do calls the giving function providing it with the NApp instance.

func (*NView) Mounted

func (v *NView) Mounted()

Mounted publishes changes notifications that the view is mounted.

func (*NView) Render

func (v *NView) Render() *trees.Markup

Render returns the markup for the giving views.

func (*NView) RenderJSON

func (v *NView) RenderJSON() ViewJSON

RenderJSON returns the ViewJSON for the provided View and its current events and changes.

func (*NView) Rendered

func (v *NView) Rendered()

Rendered publishes changes notifications that the view is rendered.

func (*NView) Services

func (v *NView) Services() Services

Services return s a Service instance which contains fields used by the Components of a view to gain access to the specific functionality of it's app root.

func (*NView) Target

func (v *NView) Target() ViewTarget

Target returns the associated view target.

func (*NView) UUID

func (v *NView) UUID() string

UUID returns the uuid specific to the giving view.

func (*NView) Unmounted

func (v *NView) Unmounted()

Unmounted publishes changes notifications that the view is unmounted.

func (*NView) Updated

func (v *NView) Updated()

Updated publishes changes notifications that the view is updated.

type NoopLocation

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

NoopLocation defines a basic struct which implements the Location interface and is used to stand in for a app when not provided one.

func NewNoopLocation

func NewNoopLocation(app *NApp) *NoopLocation

NewNoopLocation returns a new instance of a NoopLocation.

func (*NoopLocation) Location

func (n *NoopLocation) Location() router.PushEvent

Location returns the current route. It stores all set routes and returns the last route else returning a

func (*NoopLocation) Navigate

func (n *NoopLocation) Navigate(pe router.PushDirectiveEvent)

Navigate sets the giving app location and also sets the location of the NOOPLocation which returns that always.

type Properties

type Properties interface {
	Get(string) interface{}
}

Properties defines a type which exposes a single method to retrieve values from.

type Reactive

type Reactive interface {
	Reactor
	Publish()
}

Reactive extends the ReactiveRenderable by exposing a Publish method which allows calling the update notifications list of a ReactiveRenderable.

func NewReactive

func NewReactive() Reactive

NewReactive returns an instance of a Reactive struct.

type Reactor

type Reactor interface {
	React(func())
}

Reactor defines an interface for functions subscribing for notifications to react.

type RenderCommand

type RenderCommand struct {
	Command string   `json:"Command"`
	App     AppJSON  `json:"App,omitempty"`
	View    ViewJSON `json:"View,omitempty"`
}

RenderCommand defines a struct to hold a giving command for the rendering of a App or View using the JSON format.

func AppRenderCommand

func AppRenderCommand(app *NApp, route interface{}) RenderCommand

AppRenderCommand returns a new RenderCommand for rendering a app.

func ViewRenderCommand

func ViewRenderCommand(view *NView) RenderCommand

ViewRenderCommand returns a new RenderCommand for rendering a view.

type Renderable

type Renderable interface {
	Render() *trees.Markup
}

Renderable provides a interface for a renderable type.

type RenderableData

type RenderableData struct {
	Name string
	Pkg  string
}

RenderableData defines a struct which contains the name of a giving renderable and it's package.

type Renderables

type Renderables []Renderable

Renderables defines a lists of Renderable structures.

type RenderingOrder

type RenderingOrder int

RenderingOrder defines a type used to define the order which rendering is to be done for a resource.

const (
	// FirstOrder defines that rendering be first in order.
	FirstOrder RenderingOrder = iota

	// AnyOrder defines that rendering be middle in order.
	AnyOrder

	// LastOrder defines that rendering be last in order.
	LastOrder
)

type Services

type Services struct {
	AppUUID   string
	Location  Location
	Mounted   Subscriptions
	Rendered  Subscriptions
	Updated   Subscriptions
	Unmounted Subscriptions
	Router    *router.Router
	ViewRoute router.Resolver
}

Services defines a struct which exposes certain fields to be accessible to others.

type StaticView

type StaticView struct {
	Content  *trees.Markup
	Mounted  Subscriptions
	Rendered Subscriptions
	Morph    bool
	// contains filtered or unexported fields
}

StaticView defines a MarkupRenderer implementing structure which returns its Content has its markup.

func Static

func Static(tree *trees.Markup) *StaticView

Static defines a toplevel function which returns a new instance of a StaticView using the provided markup as its content.

func (*StaticView) Render

func (s *StaticView) Render() *trees.Markup

Render returns the markup for the static view.

func (*StaticView) RenderHTML

func (s *StaticView) RenderHTML() template.HTML

RenderHTML returns the html template version of the StaticView content.

func (*StaticView) UUID

func (s *StaticView) UUID() string

UUID returns the RenderGroup UUID for identification.

type Subscription

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

Subscription defines a baseline structure that can be composed into any struct to provide a reactive view.

func NewSubscriptions

func NewSubscriptions() *Subscription

NewSubscriptions returns an instance of a Subscription pointer.

func (*Subscription) Clear

func (r *Subscription) Clear()

Clear destroys all subscribers in the lists.

func (*Subscription) Publish

func (r *Subscription) Publish()

Publish runs a through the subscription list and calls the registerd functions.

func (*Subscription) React

func (r *Subscription) React(sub func())

React adds a function into the subscription list for this reactor.

func (*Subscription) Reset

func (r *Subscription) Reset()

Reset resets the subscription has unused.

func (*Subscription) Used

func (r *Subscription) Used() bool

Used returns true/false if the subscription has been called to publish.

type Subscriptions

type Subscriptions interface {
	Reactive
	Clear()
	Reset()
	Used() bool
}

Subscriptions exposes an interface which combines a Reactive type and a clear function to dispose of subscribers.

type ViewJSON

type ViewJSON struct {
	AppID  string           `json:"AppID"`
	ViewID string           `json:"ViewID"`
	Tree   trees.MarkupJSON `json:"Tree"`
}

ViewJSON defines a struct which holds the giving sets of view changes to be rendered.

type ViewTarget

type ViewTarget int

ViewTarget defines a concrete type to define where the view should be rendered.

const (

	// BodyTarget defines the view target where the view is rendered in the body.
	BodyTarget ViewTarget = iota

	// HeadTarget defines the view target where the view is rendered in the head.
	HeadTarget

	// AfterBodyTarget defines the view target where the view is rendered after
	// body views content. Generally the browser moves anything outside of the body
	// into the body as last elements. So this will be the last elements rendered
	// in the border accordingly in the order they are added into the respective app.
	AfterBodyTarget
)

type ViewUpdate

type ViewUpdate struct {
	App  *NApp
	View *NView
}

ViewUpdate defines a struct which is used to notify the need to update a App and a given view. @notification:event

type ViewUpdateHandler

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

ViewUpdateHandler defines a structure type which implements the ViewUpdateSubscriber interface and the EventDistributor interface.

func NewViewUpdateHandler

func NewViewUpdateHandler(fn func(ViewUpdate)) *ViewUpdateHandler

NewViewUpdateHandler returns a new instance of a ViewUpdateHandler.

func (*ViewUpdateHandler) Handle

func (sn *ViewUpdateHandler) Handle(receive interface{})

Handle takes the giving value and asserts the expected value to match the ViewUpdate type then passes it to the Receive method.

func (*ViewUpdateHandler) Receive

func (sn *ViewUpdateHandler) Receive(elem ViewUpdate)

Receive takes the giving value and execute it against the underline handler.

type ViewUpdateNotification

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

ViewUpdateNotification defines a structure type which must be used to receive ViewUpdate type has a event.

func NewViewUpdateNotification

func NewViewUpdateNotification() *ViewUpdateNotification

NewViewUpdateNotification returns a new instance of NewViewUpdateNotification.

func NewViewUpdateNotificationWith

func NewViewUpdateNotificationWith(validation func(ViewUpdate) bool) *ViewUpdateNotification

NewViewUpdateNotificationWith returns a new instance of ViewUpdateNotification.

func (*ViewUpdateNotification) Handle

func (sn *ViewUpdateNotification) Handle(elem interface{})

Handle takes the giving value and asserts the expected value to be of the type and pass on to it's underline subscribers else ignoring the event.

func (*ViewUpdateNotification) Notify

Notify adds the given subscriber into the notification list and will await an update of a new event of the given ViewUpdate type.

func (*ViewUpdateNotification) UnNotify

func (sn *ViewUpdateNotification) UnNotify(sub ViewUpdateSubscriber)

UnNotify removes the given subscriber from the notification's list if found from future events.

type ViewUpdateSubscriber

type ViewUpdateSubscriber interface {
	Receive(ViewUpdate)
}

ViewUpdateSubscriber defines a interface that which is used to subscribe specifically for events ViewUpdate type.

Directories

Path Synopsis
cmd
gu
Package eventx attempts to provide a concrete go type for different events related to the DOM.
Package eventx attempts to provide a concrete go type for different events related to the DOM.
Package trees is a work inspired by a experiemental package by now authors of Vecty(github.com/gopherjs/vecty), although the provide similar API, the underline nature of how gutrees behave and function is heavily different from its original.
Package trees is a work inspired by a experiemental package by now authors of Vecty(github.com/gopherjs/vecty), although the provide similar API, the underline nature of how gutrees behave and function is heavily different from its original.
css
events
Package events defines the event binding system that combines different libraries to create a interesting event system.
Package events defines the event binding system that combines different libraries to create a interesting event system.

Jump to

Keyboard shortcuts

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