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

     1  package document
     2  
     3  import (
     4  	"io"
     5  	"os"
     6  
     7  	. "github.com/golazy/golazy/lazyview/html"
     8  	"github.com/golazy/golazy/lazyview/nodes"
     9  )
    10  
    11  func ExampleLayout() {
    12  	nodes.Beautify = true
    13  	defer (func() {
    14  		nodes.Beautify = false
    15  	})()
    16  
    17  	template := &Document{}
    18  
    19  	template.With("hola mundo").WriteTo(os.Stdout)
    20  
    21  	// Output:
    22  	// <html>
    23  	// <head>
    24  	// </head>
    25  	// <body>
    26  	// hola mundo</body>
    27  	// </html>
    28  }
    29  func ExampleLayout_complete() {
    30  	nodes.Beautify = true
    31  	defer (func() {
    32  		nodes.Beautify = false
    33  	})()
    34  
    35  	template := &Document{
    36  		Lang:     "en",
    37  		Title:    "lazyview",
    38  		Viewport: "width=device-width",
    39  		Styles:   []string{"body{margin:0;padding:0;box-sizing: border-box;}"},
    40  		Head: []interface{}{
    41  			Script(Async(), Src("https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js"), Crossorigin(("anonymous"))),
    42  			Script(Type("module"),
    43  				nodes.Raw(`import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';`),
    44  			),
    45  		},
    46  		Scripts: []string{
    47  			`document.write("hello");`,
    48  		},
    49  		LayoutBody: func(l *Document, content ...interface{}) io.WriterTo {
    50  			return Body(Main(content...))
    51  		},
    52  	}
    53  
    54  	template.With("hello").WriteTo(os.Stdout)
    55  
    56  	// Output:
    57  	// <html lang="en">
    58  	// <head>
    59  	// <title>lazyview</title>
    60  	// <meta name="viewport" content="width=device-width"/>
    61  	// <style>body{margin:0;padding:0;box-sizing: border-box;}</style>
    62  	// <script>document.write("hello");</script>
    63  	// <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js" crossorigin="anonymous"/>
    64  	// <script type="module">import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';</script>
    65  	// </head>
    66  	// <body>
    67  	// <main>hello</main>
    68  	// </body>
    69  	// </html>
    70  
    71  }