Skip to content

Commit f06ae7e

Browse files
committed
restructure packages
1 parent a16fe59 commit f06ae7e

File tree

10 files changed

+149
-149
lines changed

10 files changed

+149
-149
lines changed

domx/document.go renamed to document.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
package domx
1+
package dom
22

33
import (
44
"strings"
55

66
"golang.org/x/net/html"
77
"golang.org/x/net/html/atom"
88

9-
"github.com/crhntr/dom"
9+
"github.com/crhntr/dom/spec"
1010
)
1111

1212
type Document struct {
1313
node *html.Node
1414
}
1515

16-
func (d *Document) NodeType() dom.NodeType { return nodeType(d.node.Type) }
17-
func (d *Document) CloneNode(deep bool) dom.Node { return NewNode(cloneNode(d.node, deep)) }
18-
func (d *Document) IsSameNode(other dom.Node) bool { return isSameNode(d.node, other) }
19-
func (d *Document) GetElementsByTagName(name string) dom.ElementCollection {
16+
func (d *Document) NodeType() spec.NodeType { return nodeType(d.node.Type) }
17+
func (d *Document) CloneNode(deep bool) spec.Node { return NewNode(cloneNode(d.node, deep)) }
18+
func (d *Document) IsSameNode(other spec.Node) bool { return isSameNode(d.node, other) }
19+
func (d *Document) GetElementsByTagName(name string) spec.ElementCollection {
2020
return getElementsByTagName(d.node, name)
2121
}
2222

23-
func (d *Document) GetElementsByClassName(name string) dom.ElementCollection {
23+
func (d *Document) GetElementsByClassName(name string) spec.ElementCollection {
2424
return getElementsByClassName(d.node, name)
2525
}
2626

27-
func (d *Document) QuerySelector(query string) dom.Element {
27+
func (d *Document) QuerySelector(query string) spec.Element {
2828
return querySelector(d.node, query)
2929
}
3030

31-
func (d *Document) QuerySelectorAll(query string) dom.NodeList[dom.Element] {
31+
func (d *Document) QuerySelectorAll(query string) spec.NodeList[spec.Element] {
3232
return querySelectorAll(d.node, query)
3333
}
34-
func (d *Document) Contains(other dom.Node) bool { return contains(d.node, other) }
34+
func (d *Document) Contains(other spec.Node) bool { return contains(d.node, other) }
3535

3636
// TextContent returns an empty string.
3737
// The spec says it should return null
@@ -40,7 +40,7 @@ func (d *Document) TextContent() string { return "" }
4040

4141
// Document
4242

43-
func (*Document) CreateElement(localName string) dom.Element {
43+
func (*Document) CreateElement(localName string) spec.Element {
4444
localName = strings.ToLower(localName)
4545
return &Element{
4646
node: &html.Node{
@@ -51,7 +51,7 @@ func (*Document) CreateElement(localName string) dom.Element {
5151
}
5252
}
5353

54-
func (*Document) CreateElementIs(localName, is string) dom.Element {
54+
func (*Document) CreateElementIs(localName, is string) spec.Element {
5555
localName = strings.ToLower(localName)
5656
return &Element{
5757
node: &html.Node{
@@ -63,7 +63,7 @@ func (*Document) CreateElementIs(localName, is string) dom.Element {
6363
}
6464
}
6565

66-
func (*Document) CreateTextNode(text string) dom.Text {
66+
func (*Document) CreateTextNode(text string) spec.Text {
6767
return &Text{
6868
node: &html.Node{
6969
Type: html.TextNode,

domx/document_test.go renamed to document_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package domx
1+
package dom
22

33
import (
44
"strings"
@@ -9,15 +9,15 @@ import (
99

1010
"golang.org/x/net/html"
1111

12-
"github.com/crhntr/dom"
12+
"github.com/crhntr/dom/spec"
1313
)
1414

1515
func TestDocument_NodeType(t *testing.T) {
1616
// language=html
1717
textHTML := `<!DOCTYPE html><html lang="us-en"><head><title></title></head><body><span></span></body</html>`
1818
document, _ := parseDocument(t, textHTML, "")
1919

20-
assert.Equal(t, dom.NodeTypeDocument, document.NodeType())
20+
assert.Equal(t, spec.NodeTypeDocument, document.NodeType())
2121
}
2222

2323
func TestDocument_CloneNode(t *testing.T) {

domx/text.go

Lines changed: 0 additions & 33 deletions
This file was deleted.

domx/element.go renamed to element.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package domx
1+
package dom
22

33
import (
44
"bytes"
55
"strings"
66

77
"golang.org/x/net/html"
88

9-
"github.com/crhntr/dom"
9+
"github.com/crhntr/dom/spec"
1010
)
1111

1212
type Element struct {
@@ -15,16 +15,16 @@ type Element struct {
1515

1616
// NewNode
1717

18-
func (e *Element) NodeType() dom.NodeType { return nodeType(e.node.Type) }
19-
func (e *Element) IsConnected() bool { return isConnected(e.node) }
20-
func (e *Element) OwnerDocument() dom.Document { return ownerDocument(e.node) }
21-
func (e *Element) ParentNode() dom.Node { return parentNode(e.node) }
22-
func (e *Element) ParentElement() dom.Element { return parentElement(e.node) }
23-
func (e *Element) PreviousSibling() dom.ChildNode { return previousSibling(e.node) }
24-
func (e *Element) NextSibling() dom.ChildNode { return nextSibling(e.node) }
25-
func (e *Element) TextContent() string { return textContent(e.node) }
26-
func (e *Element) CloneNode(deep bool) dom.Node { return NewNode(cloneNode(e.node, deep)) }
27-
func (e *Element) IsSameNode(other dom.Node) bool { return isSameNode(e.node, other) }
18+
func (e *Element) NodeType() spec.NodeType { return nodeType(e.node.Type) }
19+
func (e *Element) IsConnected() bool { return isConnected(e.node) }
20+
func (e *Element) OwnerDocument() spec.Document { return ownerDocument(e.node) }
21+
func (e *Element) ParentNode() spec.Node { return parentNode(e.node) }
22+
func (e *Element) ParentElement() spec.Element { return parentElement(e.node) }
23+
func (e *Element) PreviousSibling() spec.ChildNode { return previousSibling(e.node) }
24+
func (e *Element) NextSibling() spec.ChildNode { return nextSibling(e.node) }
25+
func (e *Element) TextContent() string { return textContent(e.node) }
26+
func (e *Element) CloneNode(deep bool) spec.Node { return NewNode(cloneNode(e.node, deep)) }
27+
func (e *Element) IsSameNode(other spec.Node) bool { return isSameNode(e.node, other) }
2828
func (e *Element) Length() int {
2929
c := e.node.FirstChild
3030
result := 0
@@ -37,41 +37,41 @@ func (e *Element) Length() int {
3737

3838
// ParentNode
3939

40-
func (e *Element) Children() dom.ElementCollection { return children(e.node) }
41-
func (e *Element) FirstElementChild() dom.Element { return firstElementChild(e.node) }
42-
func (e *Element) LastElementChild() dom.Element { return lastElementChild(e.node) }
43-
func (e *Element) ChildElementCount() int { return childElementCount(e.node) }
44-
func (e *Element) Prepend(nodes ...dom.ChildNode) { prependNodes(e.node, nodes) }
45-
func (e *Element) Append(nodes ...dom.ChildNode) { appendNodes(e.node, nodes) }
46-
func (e *Element) ReplaceChildren(nodes ...dom.ChildNode) { replaceChildren(e.node, nodes) }
47-
func (e *Element) GetElementsByTagName(name string) dom.ElementCollection {
40+
func (e *Element) Children() spec.ElementCollection { return children(e.node) }
41+
func (e *Element) FirstElementChild() spec.Element { return firstElementChild(e.node) }
42+
func (e *Element) LastElementChild() spec.Element { return lastElementChild(e.node) }
43+
func (e *Element) ChildElementCount() int { return childElementCount(e.node) }
44+
func (e *Element) Prepend(nodes ...spec.ChildNode) { prependNodes(e.node, nodes) }
45+
func (e *Element) Append(nodes ...spec.ChildNode) { appendNodes(e.node, nodes) }
46+
func (e *Element) ReplaceChildren(nodes ...spec.ChildNode) { replaceChildren(e.node, nodes) }
47+
func (e *Element) GetElementsByTagName(name string) spec.ElementCollection {
4848
return getElementsByTagName(e.node, name)
4949
}
5050

51-
func (e *Element) GetElementsByClassName(name string) dom.ElementCollection {
51+
func (e *Element) GetElementsByClassName(name string) spec.ElementCollection {
5252
return getElementsByClassName(e.node, name)
5353
}
5454

55-
func (e *Element) QuerySelector(query string) dom.Element { return querySelector(e.node, query) }
56-
func (e *Element) QuerySelectorAll(query string) dom.NodeList[dom.Element] {
55+
func (e *Element) QuerySelector(query string) spec.Element { return querySelector(e.node, query) }
56+
func (e *Element) QuerySelectorAll(query string) spec.NodeList[spec.Element] {
5757
return querySelectorAll(e.node, query)
5858
}
59-
func (e *Element) Closest(selector string) dom.Element { return closest(e.node, selector) }
60-
func (e *Element) Matches(selector string) bool { return matches(e.node, selector) }
59+
func (e *Element) Closest(selector string) spec.Element { return closest(e.node, selector) }
60+
func (e *Element) Matches(selector string) bool { return matches(e.node, selector) }
6161

62-
func (e *Element) HasChildNodes() bool { return hasChildNodes(e.node) }
63-
func (e *Element) ChildNodes() dom.NodeList[dom.Node] { return childNodes(e.node) }
64-
func (e *Element) FirstChild() dom.ChildNode { return firstChild(e.node) }
65-
func (e *Element) LastChild() dom.ChildNode { return lastChild(e.node) }
66-
func (e *Element) Contains(other dom.Node) bool { return contains(e.node, other) }
67-
func (e *Element) InsertBefore(node, child dom.ChildNode) dom.ChildNode {
62+
func (e *Element) HasChildNodes() bool { return hasChildNodes(e.node) }
63+
func (e *Element) ChildNodes() spec.NodeList[spec.Node] { return childNodes(e.node) }
64+
func (e *Element) FirstChild() spec.ChildNode { return firstChild(e.node) }
65+
func (e *Element) LastChild() spec.ChildNode { return lastChild(e.node) }
66+
func (e *Element) Contains(other spec.Node) bool { return contains(e.node, other) }
67+
func (e *Element) InsertBefore(node, child spec.ChildNode) spec.ChildNode {
6868
return insertBefore(e.node, node, child)
6969
}
70-
func (e *Element) AppendChild(node dom.ChildNode) dom.ChildNode { return appendChild(e.node, node) }
71-
func (e *Element) ReplaceChild(node, child dom.ChildNode) dom.ChildNode {
70+
func (e *Element) AppendChild(node spec.ChildNode) spec.ChildNode { return appendChild(e.node, node) }
71+
func (e *Element) ReplaceChild(node, child spec.ChildNode) spec.ChildNode {
7272
return replaceChild(e.node, node, child)
7373
}
74-
func (e *Element) RemoveChild(node dom.ChildNode) dom.ChildNode { return removeChild(e.node, node) }
74+
func (e *Element) RemoveChild(node spec.ChildNode) spec.ChildNode { return removeChild(e.node, node) }
7575

7676
// Element
7777

@@ -193,7 +193,7 @@ func (list SiblingElements) Length() int {
193193
return result
194194
}
195195

196-
func (list SiblingElements) Item(index int) dom.Element {
196+
func (list SiblingElements) Item(index int) spec.Element {
197197
childIndex := 0
198198
for c := list.firstChild; c != nil; c = c.NextSibling {
199199
if c.Type != html.ElementNode {
@@ -207,7 +207,7 @@ func (list SiblingElements) Item(index int) dom.Element {
207207
return nil
208208
}
209209

210-
func (list SiblingElements) NamedItem(name string) dom.Element {
210+
func (list SiblingElements) NamedItem(name string) spec.Element {
211211
for c := list.firstChild; c != nil; c = c.NextSibling {
212212
if c.Type != html.ElementNode {
213213
continue
@@ -223,14 +223,14 @@ type ElementList []*html.Node
223223

224224
func (list ElementList) Length() int { return len(list) }
225225

226-
func (list ElementList) Item(index int) dom.Element {
226+
func (list ElementList) Item(index int) spec.Element {
227227
if index < 0 || index >= len(list) {
228228
return nil
229229
}
230230
return &Element{node: list[index]}
231231
}
232232

233-
func (list ElementList) NamedItem(name string) dom.Element {
233+
func (list ElementList) NamedItem(name string) spec.Element {
234234
for _, el := range list {
235235
if isNamed(el, name) {
236236
return &Element{node: el}

domx/element_test.go renamed to element_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package domx
1+
package dom
22

33
import (
44
"strings"
@@ -8,7 +8,7 @@ import (
88
"github.com/stretchr/testify/require"
99
"golang.org/x/net/html"
1010

11-
"github.com/crhntr/dom"
11+
"github.com/crhntr/dom/spec"
1212
)
1313

1414
func TestElement_NodeType(t *testing.T) {
@@ -19,7 +19,7 @@ func TestElement_NodeType(t *testing.T) {
1919
node: parsedDocument.FirstChild.NextSibling,
2020
}
2121

22-
assert.Equal(t, dom.NodeTypeElement, document.NodeType())
22+
assert.Equal(t, spec.NodeTypeElement, document.NodeType())
2323
}
2424

2525
func TestElement_IsConnected(t *testing.T) {
@@ -90,8 +90,8 @@ func TestElement_ParentNode(t *testing.T) {
9090

9191
parent := app.ParentNode()
9292
require.NotNil(t, parent)
93-
require.Equal(t, dom.NodeTypeDocument, parent.NodeType())
94-
_, ok := parent.(dom.Document)
93+
require.Equal(t, spec.NodeTypeDocument, parent.NodeType())
94+
_, ok := parent.(spec.Document)
9595
require.True(t, ok)
9696
}
9797

0 commit comments

Comments
 (0)