Skip to content

Commit b49744d

Browse files
John DoakJohn Doak
authored andcommitted
go fmt + adding 'as' attribute to link tag
1 parent 5b99ac1 commit b49744d

10 files changed

Lines changed: 60 additions & 35 deletions

html/component_else.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ type GearType interface {
1717
GearID() string
1818
TagType() html.HTMLAttr
1919
Execute(pipe Pipeline) string
20-
}
20+
}

html/component_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package html
22

33
import (
44
"context"
5+
"html/template"
56
"strings"
67
"testing"
7-
"html/template"
88
)
99

1010
type fakeGear struct {
@@ -33,7 +33,7 @@ func TestComponent(t *testing.T) {
3333
GlobalAttrs: GlobalAttrs{
3434
AccessKey: "key",
3535
},
36-
Gear: fakeGear{name: "myComponent"},
36+
Gear: fakeGear{name: "myComponent"},
3737
TagValue: TextElement("value"),
3838
Events: (&Events{}).AddScript(OnError, "handleError"),
3939
},

html/component_wasm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ type GearType interface {
2121
SetUpdateFlag()
2222
RemoveUpdateFlag()
2323
UpdateDOM() error
24-
}
24+
}

html/event_wasm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
// to events in WASM code. "this" is set to the js.Value of the object that the event was attached to
1414
// in its state at the time of the call. root is set to the value of the root object that the "this"
1515
// object is within. Without componenets, this will be "document". If contained in a set of components,
16-
// this will be the component's shadowRoot that this element is contained within.
16+
// this will be the component's shadowRoot that this element is contained within.
1717
// "args" represents arguments sent to this function, which are application defined.
1818
type WasmFunc func(this js.Value, root js.Value, args interface{})
1919

@@ -23,7 +23,7 @@ type wasmEvent struct {
2323
listenerEvent ListenerType
2424
release bool
2525
fn WasmFunc
26-
args interface{}
26+
args interface{}
2727
}
2828

2929
// Call calls the attached event passing along the component's shadowPath to allow finding the
@@ -118,7 +118,7 @@ func (e *Events) AddWasmHandler(id string, et EventType, fn WasmFunc, args inter
118118
handlerEvent: et,
119119
release: release,
120120
fn: fn,
121-
args: args,
121+
args: args,
122122
},
123123
)
124124
return e
@@ -148,15 +148,15 @@ func (e *Events) AddWasmListener(id string, et ListenerType, fn WasmFunc, args i
148148
listenerEvent: et,
149149
release: release,
150150
fn: fn,
151-
args: args,
151+
args: args,
152152
},
153153
)
154154
return e
155155
}
156156

157157
// WasmEvents returns a list of functions that will attach Wasm events specified by
158158
// .AddWasm(). This is for internal use only and has no compatibility promises.
159-
func (e *Events) WasmEvents() ([]func(*Doc, []string)) {
159+
func (e *Events) WasmEvents() []func(*Doc, []string) {
160160
if e.wasmEvents == nil {
161161
return nil
162162
}

html/form_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import (
88

99
func TestLabel(t *testing.T) {
1010
tests := []struct {
11-
desc string
12-
label *Label
13-
want string
11+
desc string
12+
label *Label
13+
want string
1414
}{
1515
{
16-
desc: "Empty attributes",
17-
label: &Label{},
18-
want: "<label >\n</label>",
16+
desc: "Empty attributes",
17+
label: &Label{},
18+
want: "<label >\n</label>",
1919
},
20-
20+
2121
{
2222
desc: "All attributes + 1 global + 1 event + 1 element",
2323
label: &Label{

html/i_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ func TestI(t *testing.T) {
2424
GlobalAttrs: GlobalAttrs{
2525
AccessKey: "key",
2626
},
27-
Element: TextElement("text"),
28-
Events: (&Events{}).AddScript(OnError, "handleError"),
27+
Element: TextElement("text"),
28+
Events: (&Events{}).AddScript(OnError, "handleError"),
2929
},
3030
want: `<i accesskey="key" onerror="handleError">text
3131
</i>`,

html/link.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ const (
3434
StylesheetRL RelationshipLink = "stylesheet"
3535
)
3636

37+
// AsLink is a a value used in the Link As attribute.
38+
type AsLink string
39+
40+
const (
41+
AsAudio AsLink = "audio"
42+
AsDocument AsLink = "document"
43+
AsEmbed AsLink = "embed"
44+
AsFetch AsLink = "fetch"
45+
AsFont AsLink = "font"
46+
AsImage AsLink = "image"
47+
AsObject AsLink = "object"
48+
AsScript AsLink = "script"
49+
AsStyle AsLink = "style"
50+
AsTrack AsLink = "track"
51+
AsVideo AsLink = "video"
52+
AsWorker AsLink = "worker"
53+
)
54+
3755
type Sizes struct {
3856
Height int
3957
Width int
@@ -80,6 +98,12 @@ type Link struct {
8098
// Rel (required) specifies the relationship between the current document and the linked document.
8199
Rel RelationshipLink
82100

101+
// As is only used when rel="preload" or rel="prefetch" has been set on the <link> element.
102+
// It specifies the type of content being loaded by the <link>, which is necessary for request matching,
103+
// application of correct content security policy, and setting of correct Accept request header.
104+
// Furthermore, rel="preload" uses this as a signal for request prioritization.
105+
As AsLink
106+
83107
// Sizes specifies the size of the linked resource. Only for rel="icon".
84108
Sizes Sizes
85109

html/link_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ func TestLink(t *testing.T) {
3636
Href: u,
3737
CrossOrigin: AnnonymousCO,
3838
HrefLang: "english",
39+
As: AsVideo,
3940
Media: "media",
4041
ReferrerPolicy: Origin,
4142
Rel: AlternateRL,
4243
Sizes: Sizes{Width: 5, Height: 10},
4344
Type: "type",
4445
},
4546
want: `<link href="/subpage" crossorigin="anonymous" hreflang="english" media="media" ` +
46-
`referrerpolicy="origin" rel="alternate" sizes="10x5" type="type" accesskey="key">`,
47+
`referrerpolicy="origin" rel="alternate" as="video" sizes="10x5" type="type" accesskey="key">`,
4748
},
4849
}
4950

html/textarea.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type WrapType string
1919
const (
2020
// SoftWrap specifies the text in the textarea is not wrapped when submitted in a form. This is default.
2121
SoftWrap WrapType = "soft"
22-
// HardWrap specifies the text in the textarea is wrapped (contains newlines)
22+
// HardWrap specifies the text in the textarea is wrapped (contains newlines)
2323
// when submitted in a form. When "hard" is used, the cols attribute must be specified.
2424
HardWrap WrapType = "hard"
2525
)

html/textarea_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ import (
88

99
func TestTextArea(t *testing.T) {
1010
tests := []struct {
11-
desc string
11+
desc string
1212
textArea *TextArea
13-
want string
13+
want string
1414
}{
1515
{
1616
desc: "All attributes + 1 global + 1 event ",
1717
textArea: &TextArea{
1818
GlobalAttrs: GlobalAttrs{
1919
AccessKey: "key",
2020
},
21-
Name: "name",
22-
Form: "formid",
23-
Cols: 10,
24-
MaxLength: 1000,
25-
Rows: 40,
26-
DirName: "name.dir",
27-
Wrap: HardWrap,
21+
Name: "name",
22+
Form: "formid",
23+
Cols: 10,
24+
MaxLength: 1000,
25+
Rows: 40,
26+
DirName: "name.dir",
27+
Wrap: HardWrap,
2828
Placeholder: "placeholder",
29-
AutoFocus: true,
30-
Disabled: true,
31-
ReadOnly: true,
32-
Required: true,
33-
Element: TextElement("text"),
34-
Events: (&Events{}).AddScript(OnError, "handleError"),
29+
AutoFocus: true,
30+
Disabled: true,
31+
ReadOnly: true,
32+
Required: true,
33+
Element: TextElement("text"),
34+
Events: (&Events{}).AddScript(OnError, "handleError"),
3535
},
3636

3737
want: strings.TrimSpace(`

0 commit comments

Comments
 (0)