-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhead.go
83 lines (70 loc) · 1.65 KB
/
head.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package html
import "strconv"
// Head defines the HTML head element
type HeadElement struct {
Container
title string
css *CSSElement
styles *StyleElement
}
func Head() *HeadElement {
head := &HeadElement{
css: NewCSS(),
styles: NewStyles(),
}
head.Add(head.css)
head.Add(head.styles)
return head
}
// Write writes the HTML head tag and head data
func (head *HeadElement) Write(tw *TagWriter) {
tw.WriteTag(TagHead, head)
}
// AddTitle Adds a title to the Header
func (head *HeadElement) AddTitle(title string) {
head.title = title
head.Add(NewTitle(title))
}
// GetTitle will return the last title set
func (head *HeadElement) GetTitle() string {
return head.title
}
// Head defines the HTML head title element
type Title struct {
Attributes
Title string
}
// NewTitle will create a new HTML head title with the given title string
func NewTitle(title string) *Title {
return &Title{
Title: title,
}
}
// Write writes the HTML head title tag and title
func (t *Title) Write(tw *TagWriter) {
tw.WriteTag(TagTitle, t)
}
// WriteContent writes the HTML title
func (t *Title) WriteContent(tw *TagWriter) {
tw.WriteString(t.Title)
}
type MetaElement struct {
Attributes
text string
}
// MetaRefresh will create a meta tag forcing a refresh in number of seconds. Link is optional
func MetaRefresh(seconds int, link string) *MetaElement {
m := &MetaElement{}
m.AddAttr("http-equiv", "refresh")
content := strconv.Itoa(seconds)
if len(link) > 0 {
content += "; URL=" + link
}
m.AddAttr("content", content)
return m
}
func (m *MetaElement) Write(tw *TagWriter) {
tw.WriteTag(TagMeta, m)
}
func (m *MetaElement) WriteContent(tw *TagWriter) {
}