Move html/head/navbar into elements.
This commit is contained in:
parent
7d42229098
commit
cb8236eb92
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
.idea
|
.idea
|
||||||
*DS_Store*
|
*DS_Store*
|
||||||
|
pkg
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
||||||
|
|
||||||
"go.dev.pztrn.name/bulpherjs/common"
|
"go.dev.pztrn.name/bulpherjs/common"
|
||||||
"go.dev.pztrn.name/bulpherjs/widgets"
|
"go.dev.pztrn.name/bulpherjs/elements"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Application is a controlling structure for whole application.
|
// Application is a controlling structure for whole application.
|
||||||
@ -12,7 +12,7 @@ type Application struct {
|
|||||||
options *ApplicationOptions
|
options *ApplicationOptions
|
||||||
startFunc func(*Application)
|
startFunc func(*Application)
|
||||||
|
|
||||||
HTML *widgets.HTML
|
HTML *elements.HTML
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewApplication creates new BulpherJS application.
|
// NewApplication creates new BulpherJS application.
|
||||||
@ -32,7 +32,7 @@ func (a *Application) Build() {
|
|||||||
func (a *Application) initialize(opts *ApplicationOptions) {
|
func (a *Application) initialize(opts *ApplicationOptions) {
|
||||||
a.options = opts
|
a.options = opts
|
||||||
|
|
||||||
a.HTML = widgets.NewHTML()
|
a.HTML = elements.NewHTML()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStartFunction sets start function which will be executed on app's
|
// SetStartFunction sets start function which will be executed on app's
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package widgets
|
package elements
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
@ -1,10 +1,9 @@
|
|||||||
package widgets
|
package elements
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
||||||
|
|
||||||
"go.dev.pztrn.name/bulpherjs/common"
|
"go.dev.pztrn.name/bulpherjs/common"
|
||||||
"go.dev.pztrn.name/bulpherjs/elements"
|
|
||||||
"go.dev.pztrn.name/bulpherjs/metas"
|
"go.dev.pztrn.name/bulpherjs/metas"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -46,13 +45,13 @@ func (hw *Head) initialize(opts *HeadOptions) {
|
|||||||
hw.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallGetElementsByTagName, common.HTMLElementHead).Index(0)
|
hw.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallGetElementsByTagName, common.HTMLElementHead).Index(0)
|
||||||
|
|
||||||
// Add default header elements.
|
// Add default header elements.
|
||||||
hw.AddChild(elements.NewLink(&elements.LinkOptions{
|
hw.AddChild(NewLink(&LinkOptions{
|
||||||
Href: "//cdn.jsdelivr.net/npm/bulma@" + bulmaVersion + "/css/bulma.min.css",
|
Href: "//cdn.jsdelivr.net/npm/bulma@" + bulmaVersion + "/css/bulma.min.css",
|
||||||
ID: "",
|
ID: "",
|
||||||
Rel: "stylesheet",
|
Rel: "stylesheet",
|
||||||
}))
|
}))
|
||||||
|
|
||||||
hw.AddChild(elements.NewMeta(&elements.MetaOptions{
|
hw.AddChild(NewMeta(&MetaOptions{
|
||||||
Content: "width=device-width, initial-scale=1",
|
Content: "width=device-width, initial-scale=1",
|
||||||
Name: "viewport",
|
Name: "viewport",
|
||||||
}))
|
}))
|
@ -1,4 +1,4 @@
|
|||||||
package widgets
|
package elements
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
@ -1,9 +1,7 @@
|
|||||||
package widgets
|
package elements
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gopherjs/gopherjs/js"
|
"github.com/gopherjs/gopherjs/js"
|
||||||
|
|
||||||
"go.dev.pztrn.name/bulpherjs/elements"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NavBarOptions is a "nav" HTML body element configuration structure.
|
// NavBarOptions is a "nav" HTML body element configuration structure.
|
||||||
@ -16,7 +14,7 @@ type NavBarOptions struct {
|
|||||||
type NavBar struct {
|
type NavBar struct {
|
||||||
options *NavBarOptions
|
options *NavBarOptions
|
||||||
|
|
||||||
navbar *elements.Nav
|
navbar *Nav
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNavBar creates new "nav" HTML element controlling structure.
|
// NewNavBar creates new "nav" HTML element controlling structure.
|
||||||
@ -36,26 +34,26 @@ func (n *NavBar) Build() *js.Object {
|
|||||||
func (n *NavBar) initialize(opts *NavBarOptions) {
|
func (n *NavBar) initialize(opts *NavBarOptions) {
|
||||||
n.options = opts
|
n.options = opts
|
||||||
|
|
||||||
navopts := &elements.NavOptions{
|
navopts := &NavOptions{
|
||||||
Class: "navbar",
|
Class: "navbar",
|
||||||
Data: map[string]string{},
|
Data: map[string]string{},
|
||||||
Role: "navigation",
|
Role: "navigation",
|
||||||
}
|
}
|
||||||
|
|
||||||
n.navbar = elements.NewNav(navopts)
|
n.navbar = NewNav(navopts)
|
||||||
|
|
||||||
if n.options.IsDark {
|
if n.options.IsDark {
|
||||||
n.navbar.AddClassesFromString("is-dark")
|
n.navbar.AddClassesFromString("is-dark")
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.options.Title != "" {
|
if n.options.Title != "" {
|
||||||
brandDiv := elements.NewDiv(&elements.DivOptions{
|
brandDiv := NewDiv(&DivOptions{
|
||||||
Class: "navbar-brand",
|
Class: "navbar-brand",
|
||||||
})
|
})
|
||||||
|
|
||||||
n.navbar.AddChild(brandDiv)
|
n.navbar.AddChild(brandDiv)
|
||||||
|
|
||||||
navMainLink := elements.NewA(&elements.AOptions{
|
navMainLink := NewA(&AOptions{
|
||||||
Class: "navbar-item",
|
Class: "navbar-item",
|
||||||
Href: "/",
|
Href: "/",
|
||||||
Text: n.options.Title,
|
Text: n.options.Title,
|
@ -1,29 +1,11 @@
|
|||||||
GO := $(shell which go)
|
|
||||||
GO112_VERSION := 1.12.16
|
|
||||||
GO112 := go${GO112_VERSION}
|
|
||||||
|
|
||||||
GOPHERJS := $(shell which gopherjs 2> /dev/null)
|
GOPHERJS := $(shell which gopherjs 2> /dev/null)
|
||||||
|
|
||||||
## start-web : Starts GopherJS serving.
|
## start-web : Starts GopherJS serving.
|
||||||
start-web:
|
start-web:
|
||||||
GOPHERJS_GOROOT="${HOME}/sdk/${GO112}" ${GOPHERJS} serve . -v
|
${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
|
help : Makefile
|
||||||
@echo "helloworld Makefile available subcommands:\n"
|
@echo "helloworld Makefile available subcommands:\n"
|
||||||
@sed -n 's/^## //p' $<
|
@sed -n 's/^## //p' $<
|
||||||
|
|
||||||
.DEFAULT_GOAL := help
|
.DEFAULT_GOAL := help
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"go.dev.pztrn.name/bulpherjs"
|
"go.dev.pztrn.name/bulpherjs"
|
||||||
"go.dev.pztrn.name/bulpherjs/common"
|
"go.dev.pztrn.name/bulpherjs/common"
|
||||||
"go.dev.pztrn.name/bulpherjs/elements"
|
"go.dev.pztrn.name/bulpherjs/elements"
|
||||||
"go.dev.pztrn.name/bulpherjs/widgets"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -45,7 +44,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func start(a *bulpherjs.Application) {
|
func start(a *bulpherjs.Application) {
|
||||||
nb := widgets.NewNavBar(&widgets.NavBarOptions{
|
nb := elements.NewNavBar(&elements.NavBarOptions{
|
||||||
IsDark: true,
|
IsDark: true,
|
||||||
Title: "Example application",
|
Title: "Example application",
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user