Documentation ¶
Overview ¶
Package layout provides helpers to generate an html document
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var BasicLayout = &LayoutTemplate{ Lang: "en", Title: "lazyview", Viewport: "width=device-width", Styles: []string{SimpleCSS(), PageStyle()}, Head: []interface{}{ Script(Async(), Src("https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js"), Crossorigin(("anonymous"))), Script(Type("module"), nodes.Raw(`import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';`), ), }, LayoutBody: LayoutBody, }
View Source
var DefaultLayout = &LayoutTemplate{}
Functions ¶
func AddComponent ¶
func AddComponent(c Component)
func Layout ¶
Example ¶
nodes.Beautify = true defer (func() { nodes.Beautify = false })() template := &LayoutTemplate{} template.With("hola mundo").WriteTo(os.Stdout)
Output: <html> <head/> <body> hola mundo</body> </html>
Example (Complete) ¶
nodes.Beautify = true defer (func() { nodes.Beautify = false })() template := &LayoutTemplate{ Lang: "en", Title: "lazyview", Viewport: "width=device-width", Styles: []string{"body{margin:0;padding:0;box-sizing: border-box;}"}, Head: []interface{}{ Script(Async(), Src("https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js"), Crossorigin(("anonymous"))), Script(Type("module"), nodes.Raw(`import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';`), ), }, Scripts: []string{ `document.write("hello");`, }, LayoutBody: func(l *LayoutTemplate, content ...interface{}) io.WriterTo { return Body(Main(content...)) }, } template.With("hello").WriteTo(os.Stdout)
Output: <html lang="en"> <head> <title>lazyview</title> <meta name="viewport" content="width=device-width"/> <style>body{margin:0;padding:0;box-sizing: border-box;}</style> <script>document.write("hello");</script> <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js" crossorigin="anonymous"/> <script type="module">import hotwiredTurbo from 'https://cdn.skypack.dev/@hotwired/turbo';</script> </head> <body> <main>hello</main> </body> </html>
func LayoutBody ¶
func LayoutBody(l *LayoutTemplate, content ...interface{}) io.WriterTo
Types ¶
type Component ¶
Example ¶
nodes.Beautify = true defer (func() { nodes.Beautify = false })() template := &LayoutTemplate{} template.AddComponent(Component{ Scripts: []string{`document.Write("hello world");`}, Styles: []string{`body{background: red;}`}, Head: []interface{}{ Script(Type("module"), Src("https://google.com/s.rs")), }, }) template.With("hola mundo").WriteTo(os.Stdout)
Output: <html> <head> <style>body{background: red;}</style> <script>document.Write("hello world");</script> <script type="module" src="https://google.com/s.rs"/> </head> <body> hola mundo</body> </html>
type LayoutTemplate ¶
type LayoutTemplate struct { Styles []string Scripts []string Head []interface{} Components []Component Lang string Title string Viewport string LayoutBody func(l *LayoutTemplate, content ...interface{}) io.WriterTo }
func (*LayoutTemplate) AddComponent ¶
func (l *LayoutTemplate) AddComponent(c Component)
func (*LayoutTemplate) With ¶
func (l *LayoutTemplate) With(content ...interface{}) io.WriterTo
Click to show internal directories.
Click to hide internal directories.