From cb8236eb9267aa2aabb1f06c8484aeb95903824f Mon Sep 17 00:00:00 2001 From: "Stanislav N. aka pztrn" Date: Fri, 7 Jan 2022 10:53:39 +0500 Subject: [PATCH] Move html/head/navbar into elements. --- .gitignore | 1 + bulpherjs.go | 6 +++--- {widgets => elements}/body.go | 2 +- {widgets => elements}/head.go | 7 +++---- {widgets => elements}/html.go | 2 +- {widgets => elements}/navbar.go | 14 ++++++-------- examples/helloworld/Makefile | 22 ++-------------------- examples/helloworld/main.go | 3 +-- 8 files changed, 18 insertions(+), 39 deletions(-) rename {widgets => elements}/body.go (97%) rename {widgets => elements}/head.go (88%) rename {widgets => elements}/html.go (98%) rename {widgets => elements}/navbar.go (80%) diff --git a/.gitignore b/.gitignore index 1d819cc..41948cc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea *DS_Store* +pkg diff --git a/bulpherjs.go b/bulpherjs.go index 9c8e055..3728f21 100644 --- a/bulpherjs.go +++ b/bulpherjs.go @@ -4,7 +4,7 @@ import ( "github.com/gopherjs/gopherjs/js" "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. @@ -12,7 +12,7 @@ type Application struct { options *ApplicationOptions startFunc func(*Application) - HTML *widgets.HTML + HTML *elements.HTML } // NewApplication creates new BulpherJS application. @@ -32,7 +32,7 @@ func (a *Application) Build() { func (a *Application) initialize(opts *ApplicationOptions) { a.options = opts - a.HTML = widgets.NewHTML() + a.HTML = elements.NewHTML() } // SetStartFunction sets start function which will be executed on app's diff --git a/widgets/body.go b/elements/body.go similarity index 97% rename from widgets/body.go rename to elements/body.go index 8040047..2a832e9 100644 --- a/widgets/body.go +++ b/elements/body.go @@ -1,4 +1,4 @@ -package widgets +package elements import ( "github.com/gopherjs/gopherjs/js" diff --git a/widgets/head.go b/elements/head.go similarity index 88% rename from widgets/head.go rename to elements/head.go index 736ff50..4e569ef 100644 --- a/widgets/head.go +++ b/elements/head.go @@ -1,10 +1,9 @@ -package widgets +package elements import ( "github.com/gopherjs/gopherjs/js" "go.dev.pztrn.name/bulpherjs/common" - "go.dev.pztrn.name/bulpherjs/elements" "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) // 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", ID: "", Rel: "stylesheet", })) - hw.AddChild(elements.NewMeta(&elements.MetaOptions{ + hw.AddChild(NewMeta(&MetaOptions{ Content: "width=device-width, initial-scale=1", Name: "viewport", })) diff --git a/widgets/html.go b/elements/html.go similarity index 98% rename from widgets/html.go rename to elements/html.go index 23a8925..0d9b2d9 100644 --- a/widgets/html.go +++ b/elements/html.go @@ -1,4 +1,4 @@ -package widgets +package elements import ( "github.com/gopherjs/gopherjs/js" diff --git a/widgets/navbar.go b/elements/navbar.go similarity index 80% rename from widgets/navbar.go rename to elements/navbar.go index 7534822..e7134e6 100644 --- a/widgets/navbar.go +++ b/elements/navbar.go @@ -1,9 +1,7 @@ -package widgets +package elements import ( "github.com/gopherjs/gopherjs/js" - - "go.dev.pztrn.name/bulpherjs/elements" ) // NavBarOptions is a "nav" HTML body element configuration structure. @@ -16,7 +14,7 @@ type NavBarOptions struct { type NavBar struct { options *NavBarOptions - navbar *elements.Nav + navbar *Nav } // NewNavBar creates new "nav" HTML element controlling structure. @@ -36,26 +34,26 @@ func (n *NavBar) Build() *js.Object { func (n *NavBar) initialize(opts *NavBarOptions) { n.options = opts - navopts := &elements.NavOptions{ + navopts := &NavOptions{ Class: "navbar", Data: map[string]string{}, Role: "navigation", } - n.navbar = elements.NewNav(navopts) + n.navbar = NewNav(navopts) if n.options.IsDark { n.navbar.AddClassesFromString("is-dark") } if n.options.Title != "" { - brandDiv := elements.NewDiv(&elements.DivOptions{ + brandDiv := NewDiv(&DivOptions{ Class: "navbar-brand", }) n.navbar.AddChild(brandDiv) - navMainLink := elements.NewA(&elements.AOptions{ + navMainLink := NewA(&AOptions{ Class: "navbar-item", Href: "/", Text: n.options.Title, diff --git a/examples/helloworld/Makefile b/examples/helloworld/Makefile index 71f7e2d..dcb0892 100644 --- a/examples/helloworld/Makefile +++ b/examples/helloworld/Makefile @@ -1,29 +1,11 @@ -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 + ${GOPHERJS} serve . -v help : Makefile @echo "helloworld Makefile available subcommands:\n" @sed -n 's/^## //p' $< -.DEFAULT_GOAL := help \ No newline at end of file +.DEFAULT_GOAL := help diff --git a/examples/helloworld/main.go b/examples/helloworld/main.go index f82742f..d81ab5a 100644 --- a/examples/helloworld/main.go +++ b/examples/helloworld/main.go @@ -28,7 +28,6 @@ import ( "go.dev.pztrn.name/bulpherjs" "go.dev.pztrn.name/bulpherjs/common" "go.dev.pztrn.name/bulpherjs/elements" - "go.dev.pztrn.name/bulpherjs/widgets" ) func main() { @@ -45,7 +44,7 @@ func main() { } func start(a *bulpherjs.Application) { - nb := widgets.NewNavBar(&widgets.NavBarOptions{ + nb := elements.NewNavBar(&elements.NavBarOptions{ IsDark: true, Title: "Example application", })