finalize type.go documentation

This commit is contained in:
Martin Angers
2012-09-01 11:03:02 -04:00
parent 8ddd8c6655
commit 505516529b
2 changed files with 17 additions and 1 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ package goquery
// property.go : Inspect node: Contents(), Html(), Text(), Attr(), ** Does it make sense in a static HTML tree? Val()**, Length(), Size()
// traversal.go : Traversal: Find(), Children(), Parents...(), Next...(), Prev...(), Closest(), Siblings()
// DONE iteration.go : Iteration: Each(), Map()
// type.go : Selection and Document
// DONE type.go : Selection and Document
// TODO : Benchmarks
+16
View File
@@ -6,17 +6,27 @@ import (
"net/url"
)
// Document represents an HTML document to be manipulated. Unlike jQuery, which
// is loaded as part of a DOM document, and thus acts upon its containing
// document, GoQuery doesn't know which HTML document to act upon. So it needs
// to be told, and that's what the Document class is for. It holds the root
// document node to manipulate, and can make selections on this document.
type Document struct {
Root *html.Node
Url *url.URL
}
// NewDocumentFromNode() is a Document constructor that takes a root html Node
// as argument.
func NewDocumentFromNode(root *html.Node) (d *Document) {
// Create and fill the document
d = &Document{root, nil}
return
}
// NewDocument() is a Document constructor that takes a string URL as argument.
// It loads the specified document, parses it, and stores the root Document
// node, ready to be manipulated.
func NewDocument(url string) (d *Document, e error) {
// Load the URL
res, e := http.Get(url)
@@ -36,12 +46,18 @@ func NewDocument(url string) (d *Document, e error) {
return
}
// Selection represents a collection of nodes matching some criteria. The
// initial Selection can be created by using Document.Find(), and then
// manipulated using the jQuery-like chainable syntax and methods.
type Selection struct {
Nodes []*html.Node
document *Document
prevSel *Selection
}
// TODO : Keep those methods? When using pushStack, this should not be necessary,
// but maybe yes when iterating with Each or Map?
func newEmptySelection(doc *Document) *Selection {
return &Selection{nil, doc, nil}
}