Initial commit with some working code and basic example.

This commit is contained in:
2020-03-21 13:04:54 +05:00
commit 490c5e5cc5
21 changed files with 919 additions and 0 deletions

9
metas/buildable.go Normal file
View File

@@ -0,0 +1,9 @@
package metas
import "github.com/gopherjs/gopherjs/js"
// Buildable is an interface which is used internally to ensure
// that item is buildable. Used mostly for child items.
type Buildable interface {
Build() *js.Object
}

35
metas/generic.go Normal file
View File

@@ -0,0 +1,35 @@
package metas
import (
"strings"
"github.com/gopherjs/gopherjs/js"
"go.dev.pztrn.name/bulpherjs/common"
)
// Generic is a structure embedded into other structures and provides
// some generic things like working with classes, IDs and others.
// Also this is the struct that holds real object.
type Generic struct {
Buildable
InnerItems
Object *js.Object
}
// AddClassesFromString adds classes to object from string. Classes
// should be specified like "class1 class2 ... classN".
func (g *Generic) AddClassesFromString(classes string) {
classesSplitted := strings.Split(classes, " ")
for _, class := range classesSplitted {
g.Object.Get(common.HTMLElementParameterClassList).Call(common.JSCallAdd, class)
}
}
// InitializeGeneric initializes itself and all embedded things. This
// function SHOULD NOT be called manually by end-user, it should be
// called only for elements.
func (g *Generic) InitializeGeneric() {
g.initializeInnerItems()
}

32
metas/inner.go Normal file
View File

@@ -0,0 +1,32 @@
package metas
import (
"github.com/gopherjs/gopherjs/js"
"go.dev.pztrn.name/bulpherjs/common"
)
// InnerItems is a meta structure that should be embedded in all other
// structures (notably element controlling ones). It provide ability to
// add child elements.
type InnerItems struct {
innerItems []Buildable
}
// AddChild adds child to element.
func (it *InnerItems) AddChild(object Buildable) {
it.innerItems = append(it.innerItems, object)
}
// BuildChilds build child elements and adds them to parent.
func (it *InnerItems) BuildChilds(parent *js.Object) {
for _, item := range it.innerItems {
itemObj := item.Build()
parent.Call(common.JSCallAppendChild, itemObj)
}
}
// Initializes child elements storage.
func (it *InnerItems) initializeInnerItems() {
it.innerItems = make([]Buildable, 0)
}