Move html/head/navbar into elements.

This commit is contained in:
Stanislav Nikitin 2022-01-07 10:53:39 +05:00
parent 7d42229098
commit cb8236eb92
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
8 changed files with 18 additions and 39 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.idea
*DS_Store*
pkg

View File

@ -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

View File

@ -1,4 +1,4 @@
package widgets
package elements
import (
"github.com/gopherjs/gopherjs/js"

View File

@ -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",
}))

View File

@ -1,4 +1,4 @@
package widgets
package elements
import (
"github.com/gopherjs/gopherjs/js"

View File

@ -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,

View File

@ -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
.DEFAULT_GOAL := help

View File

@ -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",
})