fabioberger / humble

A client-side frontend web framework written in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

humble - A frontend framework for Go

###What is humble?

We knew Go was the language we loved working in on the backend for our web applications, but what if we could build our frontends in Go too? humble is a lightweight, modular framework for Go that has 3 main, modular pieces that work together and apart:

  • Routing:
    • Pointing URLs to different pages and partials (single page application), including query tokens
  • UI Rendering:
    • Easy to create/append/delete DOM elements to render common UI elements.
  • Models:
    • Keeping a JS object mapped to a RESTful API and performing easy CRUD actions

Installing

  • Install go if you don't already have it. The latest version is required for gopherjs.
  • Install gopherjs
  • Install humble itself with go get -u github.com/gophergala/humble
  • Import humble into your project like you would any other go package.

Running the Example

Assuming you have followed all of the steps above,

  • Install the backend server (also written in go). Run it with go run and keep it running.
  • Change into the example/todomvc directory.
  • Run gopherjs build github.com/gophergala/humble/example/todomvc/go -o js/app.js
  • Serve the todomvc directory (e.g. with python -m SimpleHTTPServer) and visit in your browser.

Routes

A dynamic router that reads and builds URLs of the form "/#/my/favourite/page/{id}" with unlimited literal and query tokens that are passed to a function handler. The function handlers are written in idiomatic Go, mimicking the http.Handler syntax.

Views

A easy way to wrap UI DOM elements that come up repeatedly or are modified extensively with JavaScript. Views are designed as Go interfaces and have to satisfy just 3 methods:

  • RenderHTML() that gives back the HTML it is associated with.
  • GetID() that gives it a unique ID (which can be auto-generated by including the included humble.Identifier type as an anonymous field)
  • OuterTag() that gives the outer tag that the view HTML is wrapped in. This is necessary for easy referencing of the view element rendered in the DOM but can be any tag (custom or semantically neutral) that the user needs.

This allows:

  • Easy create/append/delete of repeated View DOM elements.
  • Easily adding event listeners to any DOM element within View.
  • Organized view objects that control DOM with their own properties/methods

Models

A very lightweight wrapper to make CRUD actions easy HTTP requests to a RESTful API endpoint. Models are designed as Go interfaces and have to satisfy just 2 methods:

  • RootURL() that gives the REST API endpoint URL.
  • GetID() that gives it a unique ID (which can be auto-generated by including the included humble.Identifier type as an anonymous field)

This allows:

  • Easy CRUD actions that map to HTTP methods GET, POST, PUT, DELETE
  • Organized model objects with their own properties/methods

Examples

See the TodoMVC example in example/todomvc to see how it all fits together.

License

MIT License

About

A client-side frontend web framework written in Go


Languages

Language:Go 81.4%Language:CSS 18.6%