github.com/golazy/golazy@v0.0.7-0.20221012133820-968fe65a0b65/lazyview/document/component_test.go (about)

     1  package document
     2  
     3  import (
     4  	"os"
     5  
     6  	. "github.com/golazy/golazy/lazyview/html"
     7  	"github.com/golazy/golazy/lazyview/nodes"
     8  )
     9  
    10  func ExampleComponent() {
    11  
    12  	nodes.Beautify = true
    13  	defer (func() {
    14  		nodes.Beautify = false
    15  	})()
    16  
    17  	template := &Document{}
    18  	template.AddComponent(Component{
    19  		Scripts: []string{`document.Write("hello world");`},
    20  		Styles:  []string{`body{background: red;}`},
    21  		Head: []interface{}{
    22  			Script(Type("module"), Src("https://google.com/s.rs")),
    23  		},
    24  	})
    25  
    26  	template.With("hola mundo").WriteTo(os.Stdout)
    27  
    28  	// Output:
    29  	// <html>
    30  	// <head>
    31  	// <style>body{background: red;}</style>
    32  	// <script>document.Write("hello world");</script>
    33  	// <script type="module" src="https://google.com/s.rs"/>
    34  	// </head>
    35  	// <body>
    36  	// hola mundo</body>
    37  	// </html>
    38  
    39  }