Giter VIP home page Giter VIP logo

app's Introduction

app

Build Status Go Report Card Coverage Status GoDoc

Package to build MacOS and Web apps using Go, HTML and CSS.

Table of Contents

Install

# MacOS 10.12 and above.
xcode-select --install
# Get package.
go get -u -v github.com/murlokswarm/app/...

Hello world

hello

Main

func main() {
	app.Run(&mac.Driver{
		OnRun: func() {
			newWindow()
		},

		OnReopen: func(hasVisibleWindow bool) {
			if !hasVisibleWindow {
				newWindow()
			}
		},
	})
}

func newWindow() {
	app.NewWindow(app.WindowConfig{
		Title:           "hello world",
		TitlebarHidden:  true,
		Width:           1280,
		Height:          768,
		BackgroundColor: "#21252b",
		DefaultURL:      "/Hello",
	})
}

app.Run starts the app. It takes an app.Driver as argument. Here we use the MacOS driver implementation. See other drivers.

When creating the window, we set the DefaultURL to our Hello component struct name: /Hello. It will make the component loaded when the window is displayed.

Component

func init() {
	app.Import(&Hello{})
}

type Hello struct {
	Name string
}

func (h *Hello) Render() string {
	return `
<div class="Hello">
	<h1>
		Hello
		{{if .Name}}
			{{.Name}}
		{{else}}
			world
		{{end}}!
	</h1>
	<input value="{{.Name}}" placeholder="Say something..." onchange="Name" autofocus>
</div>
	`
}

Components are structs that implement the app.Component interface.

Render method returns a string that contains HTML5. It can be templated following Go standard template syntax:

HTML events like onchange are mapped to the targetted component field or method. Here, onchange is mapped to the field Name.

CSS

/* [PACKAGE PATH]/resources/css/hello.css */

.Hello {
    /* Your CSS */
}

Because, we want a stylish Hello world, we define the CSS that will give us some cool look.

CSS files are located in [PACKAGE PATH]/resources/css/ directory. All .css files within that directory will be included.

See the full example.

Drivers

A driver contains specific code that allows the app package to work on multiple platforms.

Other drivers will come in the futur.

Documentation

Examples

From package:

From community:

app's People

Contributors

maxence-charriere avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.