Initial commit with some working code and basic example.
This commit is contained in:
29
examples/helloworld/Makefile
Normal file
29
examples/helloworld/Makefile
Normal file
@@ -0,0 +1,29 @@
|
||||
GO := $(shell which go)
|
||||
GO112_VERSION := 1.12.16
|
||||
GO112 := go${GO112_VERSION}
|
||||
|
||||
GOPHERJS := $(shell which gopherjs 2> /dev/null)
|
||||
|
||||
## start-web : Starts GopherJS serving.
|
||||
start-web:
|
||||
GOPHERJS_GOROOT="${HOME}/sdk/${GO112}" ${GOPHERJS} serve . -v
|
||||
|
||||
## prepare : Installs Go 1.12 and GopherJS. Go must be already installed.
|
||||
prepare: prepare-go prepare-gopherjs
|
||||
|
||||
## prepare-go : Prepares specific Go tooling for GopherJS. Go must be already installed.
|
||||
prepare-go:
|
||||
@echo "* Getting Go 1.12.16 (required by gopherjs)"
|
||||
@${GO} get golang.org/dl/${GO112}
|
||||
@${GO112} download
|
||||
|
||||
## prepare-gopherjs: Prepares GopherJS (e.g. compiles it).
|
||||
prepare-gopherjs:
|
||||
@echo "* Getting gopherjs..."
|
||||
@${GO112} get -u -v github.com/gopherjs/gopherjs
|
||||
|
||||
help : Makefile
|
||||
@echo "helloworld Makefile available subcommands:\n"
|
||||
@sed -n 's/^## //p' $<
|
||||
|
||||
.DEFAULT_GOAL := help
|
13
examples/helloworld/README.md
Normal file
13
examples/helloworld/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# BulpherJS Hello World
|
||||
|
||||
This directory contains "hello world" example application with example Makefile. Feel free to use it in your applications.
|
||||
|
||||
To start issue this command:
|
||||
|
||||
```shell
|
||||
make start-web
|
||||
```
|
||||
|
||||
And open http://localhost:8080.
|
||||
|
||||
Makefile is self-documentational with default goal to show help. Issue ``make`` to get list of available targets.
|
73
examples/helloworld/main.go
Normal file
73
examples/helloworld/main.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
"go.dev.pztrn.name/bulpherjs/elements"
|
||||
)
|
||||
|
||||
func main() {
|
||||
document := js.Global.Get("document")
|
||||
document.Call("addEventListener", "DOMContentLoaded", func(event *js.Object) {
|
||||
js.Global.Get("console").Call("log", "Hello world!")
|
||||
|
||||
constructHeader()
|
||||
constructBody()
|
||||
})
|
||||
}
|
||||
|
||||
func constructBody() {
|
||||
mainSection := elements.NewSection(&elements.SectionOptions{Class: "section"})
|
||||
|
||||
mainDiv := elements.NewDiv(&elements.DivOptions{
|
||||
Class: "container",
|
||||
ID: "mainContainer",
|
||||
})
|
||||
mainSection.AddChild(mainDiv)
|
||||
|
||||
// Columns divs.
|
||||
columnsDiv := elements.NewDiv(&elements.DivOptions{
|
||||
Class: "columns",
|
||||
ID: "mainColumns",
|
||||
})
|
||||
mainDiv.AddChild(columnsDiv)
|
||||
|
||||
// Click-Me button should be in the middle of screen.
|
||||
centerDiv := elements.NewDiv(&elements.DivOptions{
|
||||
Class: "column is-half is-offset-two-fifths",
|
||||
})
|
||||
columnsDiv.AddChild(centerDiv)
|
||||
|
||||
startTestButton := elements.NewButton(&elements.ButtonOptions{
|
||||
Class: "button is-large is-rounded is-primary",
|
||||
Text: "Click Me!",
|
||||
OnClickHandler: func(e *js.Object) {
|
||||
common.Log("Button clicked! Hooray")
|
||||
},
|
||||
})
|
||||
centerDiv.AddChild(startTestButton)
|
||||
|
||||
js.Global.Get(common.HTMLElementDocument).
|
||||
Get(common.HTMLElementBody).
|
||||
Call(common.JSCallAppendChild, mainSection.Build())
|
||||
}
|
||||
|
||||
func constructHeader() {
|
||||
link := elements.NewLink(&elements.LinkOptions{
|
||||
Href: "//cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css",
|
||||
ID: "",
|
||||
Rel: "stylesheet",
|
||||
})
|
||||
|
||||
js.Global.Get(common.HTMLElementDocument).Get(common.HTMLElementHead).Call(common.JSCallAppendChild, link.Build())
|
||||
|
||||
metaViewport := elements.NewMeta(&elements.MetaOptions{
|
||||
Content: "width=device-width, initial-scale=1",
|
||||
Name: "viewport",
|
||||
})
|
||||
|
||||
js.Global.Get(common.HTMLElementDocument).Get(common.HTMLElementHead).Call(common.JSCallAppendChild, metaViewport.Build())
|
||||
|
||||
js.Global.Get(common.HTMLElementDocument).Set(common.HTMLHeadElementTitle, "BulpherJS Hello World application")
|
||||
}
|
Reference in New Issue
Block a user