feat: added the html bultin module.

This commit is contained in:
Andrey Parhomenko 2024-06-07 21:26:51 +05:00
parent e8eb6b60f5
commit c989b004d9
4 changed files with 45 additions and 0 deletions

15
tests/html.xgo Normal file
View file

@ -0,0 +1,15 @@
fmt := import("fmt")
html := import("html").new_render()
fmt.println(
html.html({
lang: "en"
}).body(
html.head(),
html.body().body(
html.p().body(
">>>shit"
)
)
)
)

View file

@ -1,11 +1,39 @@
package htmlx package htmlx
import "github.com/d5/tengo/v2" import "github.com/d5/tengo/v2"
import "log"
var Module = map[string] tengo.Object{
"new_render" : &tengo.UserFunction{
Name: "new_render",
Value: func(args ...tengo.Object) (tengo.Object, error){
ret := &HTML{}
return ret, nil
},
},
}
type HTML struct{ type HTML struct{
tengo.ObjectImpl tengo.ObjectImpl
} }
func (html *HTML) Import(moduleName string) (any, error) {
log.Println("import:", moduleName)
switch moduleName {
case "html":
return html, nil
}
return nil, nil
}
func (html *HTML) TypeName() string {
return "blablabla"
}
func (html *HTML) String() (string) {
return "HTML{...}"
}
/* /*
html.div({ html.div({

View file

@ -5,6 +5,7 @@ import "surdeus.su/core/xgo/xmodules/cjson"
import "surdeus.su/core/xgo/xmodules/logx" import "surdeus.su/core/xgo/xmodules/logx"
import "surdeus.su/core/xgo/xmodules/paths" import "surdeus.su/core/xgo/xmodules/paths"
import "surdeus.su/core/xgo/xmodules/httpx" import "surdeus.su/core/xgo/xmodules/httpx"
import "surdeus.su/core/xgo/xmodules/htmlx"
import "github.com/d5/tengo/v2" import "github.com/d5/tengo/v2"
// The main map to import all the implemented modules. // The main map to import all the implemented modules.
@ -14,5 +15,6 @@ var Modules = func() *tengo.ModuleMap {
ret.AddBuiltinModule("log", logx.Module) ret.AddBuiltinModule("log", logx.Module)
ret.AddBuiltinModule("paths", paths.Module) ret.AddBuiltinModule("paths", paths.Module)
ret.AddBuiltinModule("http", httpx.Module) ret.AddBuiltinModule("http", httpx.Module)
ret.AddBuiltinModule("html", htmlx.Module)
return ret return ret
}() }()