Initial commit with some working code and basic example.
This commit is contained in:
67
elements/a.go
Normal file
67
elements/a.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
"go.dev.pztrn.name/bulpherjs/metas"
|
||||
)
|
||||
|
||||
// AOptions is an "a" HTML element configuration structure.
|
||||
type AOptions struct {
|
||||
Class string
|
||||
Href string
|
||||
ID string
|
||||
Text string
|
||||
}
|
||||
|
||||
// A is a controlling structure that describes everything for "a" HTML
|
||||
// element.
|
||||
type A struct {
|
||||
metas.Generic
|
||||
options *AOptions
|
||||
}
|
||||
|
||||
// NewA creates new "a" element controlling structure.
|
||||
func NewA(opts *AOptions) *A {
|
||||
a := &A{}
|
||||
a.initialize(opts)
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// Build builds element and calls Build() for all child elements.
|
||||
func (a *A) Build() *js.Object {
|
||||
a.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementA)
|
||||
|
||||
if a.options == nil {
|
||||
return a.Object
|
||||
}
|
||||
|
||||
if a.options.Class != "" {
|
||||
a.AddClassesFromString(a.options.Class)
|
||||
}
|
||||
|
||||
if a.options.Href != "" {
|
||||
a.Object.Set(common.HTMLElementParameterHref, a.options.Href)
|
||||
}
|
||||
|
||||
if a.options.ID != "" {
|
||||
a.Object.Set(common.HTMLElementParameterID, a.options.ID)
|
||||
}
|
||||
|
||||
if a.options.Text != "" {
|
||||
a.Object.Set("textContent", a.options.Text)
|
||||
}
|
||||
|
||||
a.BuildChilds(a.Object)
|
||||
|
||||
return a.Object
|
||||
}
|
||||
|
||||
// Initializes controlling structure with necessary parameters.
|
||||
func (a *A) initialize(opts *AOptions) {
|
||||
a.options = opts
|
||||
|
||||
a.InitializeGeneric()
|
||||
}
|
67
elements/button.go
Normal file
67
elements/button.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
"go.dev.pztrn.name/bulpherjs/metas"
|
||||
)
|
||||
|
||||
// ButtonOptions is a "button" HTML element configuration structure.
|
||||
type ButtonOptions struct {
|
||||
Class string
|
||||
ID string
|
||||
OnClickHandler func(e *js.Object)
|
||||
Text string
|
||||
}
|
||||
|
||||
// Button is a controlling structure for "button" HTML element.
|
||||
type Button struct {
|
||||
metas.Generic
|
||||
|
||||
options *ButtonOptions
|
||||
}
|
||||
|
||||
// NewButton creates new "button" HTML element controlling structure.
|
||||
func NewButton(buttonOptions *ButtonOptions) *Button {
|
||||
b := &Button{}
|
||||
b.initialize(buttonOptions)
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
// Build builds element and calls Build() for all child elements.
|
||||
func (b *Button) Build() *js.Object {
|
||||
b.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementButton)
|
||||
|
||||
if b.options == nil {
|
||||
return b.Object
|
||||
}
|
||||
|
||||
if b.options.Class != "" {
|
||||
b.AddClassesFromString(b.options.Class)
|
||||
}
|
||||
|
||||
if b.options.ID != "" {
|
||||
b.Object.Set("id", b.options.ID)
|
||||
}
|
||||
|
||||
if b.options.Text != "" {
|
||||
b.Object.Set("textContent", b.options.Text)
|
||||
}
|
||||
|
||||
if b.options.OnClickHandler != nil {
|
||||
b.Object.Set("onclick", b.options.OnClickHandler)
|
||||
}
|
||||
|
||||
b.BuildChilds(b.Object)
|
||||
|
||||
return b.Object
|
||||
}
|
||||
|
||||
// Initializes controlling structure with necessary parameters.
|
||||
func (b *Button) initialize(buttonOptions *ButtonOptions) {
|
||||
b.options = buttonOptions
|
||||
|
||||
b.InitializeGeneric()
|
||||
}
|
56
elements/div.go
Normal file
56
elements/div.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
"go.dev.pztrn.name/bulpherjs/metas"
|
||||
)
|
||||
|
||||
// DivOptions is a "div" HTML element configuration structure.
|
||||
type DivOptions struct {
|
||||
Class string
|
||||
ID string
|
||||
}
|
||||
|
||||
// Div is a controlling structure for "div" HTML element.
|
||||
type Div struct {
|
||||
metas.Generic
|
||||
options *DivOptions
|
||||
}
|
||||
|
||||
// NewDiv creates new "div" HTML element controlling structure.
|
||||
func NewDiv(divOptions *DivOptions) *Div {
|
||||
d := &Div{}
|
||||
d.initialize(divOptions)
|
||||
|
||||
return d
|
||||
}
|
||||
|
||||
// Build builds element and calls Build() for all child elements.
|
||||
func (d *Div) Build() *js.Object {
|
||||
d.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementDiv)
|
||||
|
||||
if d.options == nil {
|
||||
return d.Object
|
||||
}
|
||||
|
||||
if d.options.Class != "" {
|
||||
d.AddClassesFromString(d.options.Class)
|
||||
}
|
||||
|
||||
if d.options.ID != "" {
|
||||
d.Object.Set(common.HTMLElementParameterID, d.options.ID)
|
||||
}
|
||||
|
||||
d.BuildChilds(d.Object)
|
||||
|
||||
return d.Object
|
||||
}
|
||||
|
||||
// Initializes controlling structure with necessary parameters.
|
||||
func (d *Div) initialize(divOptions *DivOptions) {
|
||||
d.options = divOptions
|
||||
|
||||
d.InitializeGeneric()
|
||||
}
|
51
elements/link.go
Normal file
51
elements/link.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
)
|
||||
|
||||
// LinkOptions is a "link" HTML head element configuration structure.
|
||||
type LinkOptions struct {
|
||||
Href string
|
||||
ID string
|
||||
Rel string
|
||||
}
|
||||
|
||||
// Link is a controlling structure for "link" HTML head element.
|
||||
type Link struct {
|
||||
options *LinkOptions
|
||||
}
|
||||
|
||||
// NewLink creates new "link" HTML head controlling structure.
|
||||
func NewLink(linkOptions *LinkOptions) *Link {
|
||||
l := &Link{}
|
||||
l.initialize(linkOptions)
|
||||
|
||||
return l
|
||||
}
|
||||
|
||||
// Build builds element.
|
||||
func (l *Link) Build() *js.Object {
|
||||
link := js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementLink)
|
||||
|
||||
if l.options == nil {
|
||||
return link
|
||||
}
|
||||
|
||||
if l.options.Href != "" {
|
||||
link.Set(common.HTMLElementParameterHref, l.options.Href)
|
||||
}
|
||||
|
||||
if l.options.Rel != "" {
|
||||
link.Set(common.HTMLElementParameterRel, l.options.Rel)
|
||||
}
|
||||
|
||||
return link
|
||||
}
|
||||
|
||||
// Initializes controlling structure with necessary parameters.
|
||||
func (l *Link) initialize(linkOptions *LinkOptions) {
|
||||
l.options = linkOptions
|
||||
}
|
55
elements/meta.go
Normal file
55
elements/meta.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
)
|
||||
|
||||
// MetaOptions is a "meta" HTML head element configuration structure.
|
||||
type MetaOptions struct {
|
||||
Charset string
|
||||
Content string
|
||||
Name string
|
||||
}
|
||||
|
||||
// Meta is a controlling structure for "meta" HTML head element.
|
||||
type Meta struct {
|
||||
options *MetaOptions
|
||||
}
|
||||
|
||||
// NewMeta creates "meta" HTML head controlling structure.
|
||||
func NewMeta(metaOptions *MetaOptions) *Meta {
|
||||
m := &Meta{}
|
||||
m.initialize(metaOptions)
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
// Build builds element.
|
||||
func (m *Meta) Build() *js.Object {
|
||||
meta := js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementMeta)
|
||||
|
||||
if m.options == nil {
|
||||
return meta
|
||||
}
|
||||
|
||||
if m.options.Charset != "" {
|
||||
meta.Set(common.HTMLMetaParameterCharset, m.options.Charset)
|
||||
}
|
||||
|
||||
if m.options.Content != "" {
|
||||
meta.Set(common.HTMLMetaParameterContent, m.options.Content)
|
||||
}
|
||||
|
||||
if m.options.Name != "" {
|
||||
meta.Set(common.HTMLMetaParameterName, m.options.Name)
|
||||
}
|
||||
|
||||
return meta
|
||||
}
|
||||
|
||||
// Initializes controlling structure with necessary parameters.
|
||||
func (m *Meta) initialize(metaOptions *MetaOptions) {
|
||||
m.options = metaOptions
|
||||
}
|
63
elements/nav.go
Normal file
63
elements/nav.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
"go.dev.pztrn.name/bulpherjs/metas"
|
||||
)
|
||||
|
||||
// NavOptions is a "nav" HTML element configuration structure.
|
||||
type NavOptions struct {
|
||||
Class string
|
||||
Data map[string]string
|
||||
Role string
|
||||
}
|
||||
|
||||
// Nav is a controlling structure for "nav" HTML element.
|
||||
type Nav struct {
|
||||
metas.Generic
|
||||
options *NavOptions
|
||||
}
|
||||
|
||||
// NewNav creates new "nav" HTML element controlling structure.
|
||||
func NewNav(navOptions *NavOptions) *Nav {
|
||||
n := &Nav{}
|
||||
n.initialize(navOptions)
|
||||
|
||||
return n
|
||||
}
|
||||
|
||||
// Build builds element and calls Build() for all child elements.
|
||||
func (n *Nav) Build() *js.Object {
|
||||
n.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementNav)
|
||||
|
||||
if n.options == nil {
|
||||
return n.Object
|
||||
}
|
||||
|
||||
if n.options.Class != "" {
|
||||
n.AddClassesFromString(n.options.Class)
|
||||
}
|
||||
|
||||
if n.options.Role != "" {
|
||||
n.Object.Set(common.HTMLElementParameterRole, n.options.Role)
|
||||
}
|
||||
|
||||
if n.options.Data != nil {
|
||||
for k, v := range n.options.Data {
|
||||
n.Object.Set(k, v)
|
||||
}
|
||||
}
|
||||
|
||||
n.BuildChilds(n.Object)
|
||||
|
||||
return n.Object
|
||||
}
|
||||
|
||||
// Initializes controlling structure with necessary parameters.
|
||||
func (n *Nav) initialize(navOptions *NavOptions) {
|
||||
n.options = navOptions
|
||||
|
||||
n.InitializeGeneric()
|
||||
}
|
61
elements/p.go
Normal file
61
elements/p.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
"go.dev.pztrn.name/bulpherjs/metas"
|
||||
)
|
||||
|
||||
// POptions is a "p" HTML element configuration structure.
|
||||
type POptions struct {
|
||||
Class string
|
||||
ID string
|
||||
Text string
|
||||
}
|
||||
|
||||
// P is a controlling structure for "p" HTML element.
|
||||
type P struct {
|
||||
metas.Generic
|
||||
options *POptions
|
||||
}
|
||||
|
||||
// NewP creates new "p" HTML element controlling structure.
|
||||
func NewP(opts *POptions) *P {
|
||||
p := &P{}
|
||||
p.initialize(opts)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
// Build builds element and calls Build() for all child elements.
|
||||
func (p *P) Build() *js.Object {
|
||||
p.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementP)
|
||||
|
||||
if p.options == nil {
|
||||
return p.Object
|
||||
}
|
||||
|
||||
if p.options.Class != "" {
|
||||
p.AddClassesFromString(p.options.Class)
|
||||
}
|
||||
|
||||
if p.options.ID != "" {
|
||||
p.Object.Set(common.HTMLElementParameterID, p.options.ID)
|
||||
}
|
||||
|
||||
if p.options.Text != "" {
|
||||
p.Object.Set("textContent", p.options.Text)
|
||||
}
|
||||
|
||||
p.BuildChilds(p.Object)
|
||||
|
||||
return p.Object
|
||||
}
|
||||
|
||||
// Initializes controlling structure with necessary parameters.
|
||||
func (p *P) initialize(opts *POptions) {
|
||||
p.options = opts
|
||||
|
||||
p.InitializeGeneric()
|
||||
}
|
48
elements/section.go
Normal file
48
elements/section.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package elements
|
||||
|
||||
import (
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
|
||||
"go.dev.pztrn.name/bulpherjs/common"
|
||||
"go.dev.pztrn.name/bulpherjs/metas"
|
||||
)
|
||||
|
||||
// SectionOptions is a "section" HTML element configuration structure.
|
||||
type SectionOptions struct {
|
||||
Class string
|
||||
}
|
||||
|
||||
// Section is a controlling structure for "section" HTML element.
|
||||
type Section struct {
|
||||
metas.Generic
|
||||
|
||||
options *SectionOptions
|
||||
}
|
||||
|
||||
// NewSection creates new "section" HTML element controlling structure.
|
||||
func NewSection(sectionOptions *SectionOptions) *Section {
|
||||
s := &Section{}
|
||||
s.initialize(sectionOptions)
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
// Build builds element and calls Build() for all child elements.
|
||||
func (s *Section) Build() *js.Object {
|
||||
s.Object = js.Global.Get(common.HTMLElementDocument).Call(common.JSCallCreateElement, common.HTMLElementSection)
|
||||
|
||||
if s.options.Class != "" {
|
||||
s.AddClassesFromString(s.options.Class)
|
||||
}
|
||||
|
||||
s.BuildChilds(s.Object)
|
||||
|
||||
return s.Object
|
||||
}
|
||||
|
||||
// Initializes controlling structure with necessary parameters.
|
||||
func (s *Section) initialize(sectionOptions *SectionOptions) {
|
||||
s.options = sectionOptions
|
||||
|
||||
s.InitializeGeneric()
|
||||
}
|
Reference in New Issue
Block a user