layout

package
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

README

layout

Package layout provides helpers to generate an html document

Functions

func AddComponent

func AddComponent(c Component)

func Layout

func Layout(content ...interface{}) io.WriterTo

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>
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

func PageStyle

func PageStyle() string

func SimpleCSS

func SimpleCSS() string

Sub Packages

Examples

Component
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>

Readme created from Go doc with goreadme

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

func Layout(content ...interface{}) io.WriterTo
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

func PageStyle

func PageStyle() string

func SimpleCSS

func SimpleCSS() string

Types

type Component

type Component struct {
	Styles  []string
	Scripts []string
	Head    []interface{}
}
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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL