コード例 #1
0
ファイル: query.go プロジェクト: devacto/grobot
// Is checks the current matched set of elements against a selector and
// returns true if at least one of these elements matches.
func (s *Selection) Is(selector string) bool {
	if len(s.Nodes) > 0 {
		return s.IsMatcher(cascadia.MustCompile(selector))
	}

	return false
}
コード例 #2
0
ファイル: manipulation.go プロジェクト: devacto/grobot
// ReplaceWith replaces each element in the set of matched elements with the
// nodes matched by the given selector.
// It returns the removed elements.
//
// This follows the same rules as Selection.Append.
func (s *Selection) ReplaceWith(selector string) *Selection {
	return s.ReplaceWithMatcher(cascadia.MustCompile(selector))
}
コード例 #3
0
ファイル: manipulation.go プロジェクト: devacto/grobot
// RemoveFiltered removes the set of matched elements by selector.
// It returns the Selection of removed nodes.
func (s *Selection) RemoveFiltered(selector string) *Selection {
	return s.RemoveMatcher(cascadia.MustCompile(selector))
}
コード例 #4
0
ファイル: manipulation.go プロジェクト: devacto/grobot
// Before inserts the matched elements before each element in the set of matched elements.
//
// This follows the same rules as Selection.Append.
func (s *Selection) Before(selector string) *Selection {
	return s.BeforeMatcher(cascadia.MustCompile(selector))
}
コード例 #5
0
ファイル: traversal.go プロジェクト: devacto/grobot
// ChildrenFiltered gets the child elements of each element in the Selection,
// filtered by the specified selector. It returns a new
// Selection object containing these elements.
func (s *Selection) ChildrenFiltered(selector string) *Selection {
	return filterAndPush(s, getChildrenNodes(s.Nodes, siblingAll), cascadia.MustCompile(selector))
}
コード例 #6
0
ファイル: traversal.go プロジェクト: devacto/grobot
// ParentsFiltered gets the ancestors of each element in the current
// Selection. It returns a new Selection object with the matched elements.
func (s *Selection) ParentsFiltered(selector string) *Selection {
	return filterAndPush(s, getParentsNodes(s.Nodes, nil, nil), cascadia.MustCompile(selector))
}
コード例 #7
0
ファイル: filter.go プロジェクト: devacto/grobot
// Not removes elements from the Selection that match the selector string.
// It returns a new Selection object with the matching elements removed.
func (s *Selection) Not(selector string) *Selection {
	return s.NotMatcher(cascadia.MustCompile(selector))
}
コード例 #8
0
ファイル: traversal.go プロジェクト: devacto/grobot
// PrevUntil gets all preceding siblings of each element up to but not
// including the element matched by the selector. It returns a new Selection
// object containing the matched elements.
func (s *Selection) PrevUntil(selector string) *Selection {
	return pushStack(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
		cascadia.MustCompile(selector), nil))
}
コード例 #9
0
ファイル: traversal.go プロジェクト: devacto/grobot
// ParentsFilteredUntilNodes is like ParentsUntilNodes, with the
// option to filter the results based on a selector string. It returns a new
// Selection object containing the matched elements.
func (s *Selection) ParentsFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection {
	return filterAndPush(s, getParentsNodes(s.Nodes, nil, nodes), cascadia.MustCompile(filterSelector))
}
コード例 #10
0
ファイル: traversal.go プロジェクト: devacto/grobot
// PrevAllFiltered gets all the preceding siblings of each element in the
// Selection filtered by a selector. It returns a new Selection object
// containing the matched elements.
func (s *Selection) PrevAllFiltered(selector string) *Selection {
	return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevAll, nil, nil), cascadia.MustCompile(selector))
}
コード例 #11
0
ファイル: traversal.go プロジェクト: devacto/grobot
// Find gets the descendants of each element in the current set of matched
// elements, filtered by a selector. It returns a new Selection object
// containing these matched elements.
func (s *Selection) Find(selector string) *Selection {
	return pushStack(s, findWithMatcher(s.Nodes, cascadia.MustCompile(selector)))
}
コード例 #12
0
ファイル: traversal.go プロジェクト: devacto/grobot
// ParentsFilteredUntil is like ParentsUntil, with the option to filter the
// results based on a selector string. It returns a new Selection
// object containing the matched elements.
func (s *Selection) ParentsFilteredUntil(filterSelector, untilSelector string) *Selection {
	return filterAndPush(s, getParentsNodes(s.Nodes, cascadia.MustCompile(untilSelector), nil), cascadia.MustCompile(filterSelector))
}
コード例 #13
0
ファイル: traversal.go プロジェクト: devacto/grobot
// ParentsUntil gets the ancestors of each element in the Selection, up to but
// not including the element matched by the selector. It returns a new Selection
// object containing the matched elements.
func (s *Selection) ParentsUntil(selector string) *Selection {
	return pushStack(s, getParentsNodes(s.Nodes, cascadia.MustCompile(selector), nil))
}
コード例 #14
0
ファイル: manipulation.go プロジェクト: devacto/grobot
// WrapInner wraps an HTML structure, matched by the given selector, around the
// content of element in the set of matched elements. The matched child is
// cloned before being inserted into the document.
//
// It returns the original set of elements.
func (s *Selection) WrapInner(selector string) *Selection {
	return s.WrapInnerMatcher(cascadia.MustCompile(selector))
}
コード例 #15
0
ファイル: traversal.go プロジェクト: devacto/grobot
// PrevFilteredUntil is like PrevUntil, with the option to filter
// the results based on a selector string.
// It returns a new Selection object containing the matched elements.
func (s *Selection) PrevFilteredUntil(filterSelector, untilSelector string) *Selection {
	return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
		cascadia.MustCompile(untilSelector), nil), cascadia.MustCompile(filterSelector))
}
コード例 #16
0
ファイル: manipulation.go プロジェクト: devacto/grobot
// Append appends the elements specified by the selector to the end of each element
// in the set of matched elements, following those rules:
//
// 1) The selector is applied to the root document.
//
// 2) Elements that are part of the document will be moved to the new location.
//
// 3) If there are multiple locations to append to, cloned nodes will be
// appended to all target locations except the last one, which will be moved
// as noted in (2).
func (s *Selection) Append(selector string) *Selection {
	return s.AppendMatcher(cascadia.MustCompile(selector))
}
コード例 #17
0
ファイル: traversal.go プロジェクト: devacto/grobot
// PrevFilteredUntilSelection is like PrevUntilSelection, with the
// option to filter the results based on a selector string. It returns a new
// Selection object containing the matched elements.
func (s *Selection) PrevFilteredUntilSelection(filterSelector string, sel *Selection) *Selection {
	return s.PrevMatcherUntilSelection(cascadia.MustCompile(filterSelector), sel)
}
コード例 #18
0
ファイル: expand.go プロジェクト: devacto/grobot
// Add adds the selector string's matching nodes to those in the current
// selection and returns a new Selection object.
// The selector string is run in the context of the document of the current
// Selection object.
func (s *Selection) Add(selector string) *Selection {
	return s.AddNodes(findWithMatcher([]*html.Node{s.document.rootNode}, cascadia.MustCompile(selector))...)
}
コード例 #19
0
ファイル: traversal.go プロジェクト: devacto/grobot
// PrevFilteredUntilNodes is like PrevUntilNodes, with the
// option to filter the results based on a selector string. It returns a new
// Selection object containing the matched elements.
func (s *Selection) PrevFilteredUntilNodes(filterSelector string, nodes ...*html.Node) *Selection {
	return filterAndPush(s, getSiblingNodes(s.Nodes, siblingPrevUntil,
		nil, nodes), cascadia.MustCompile(filterSelector))
}
コード例 #20
0
ファイル: filter.go プロジェクト: devacto/grobot
// Filter reduces the set of matched elements to those that match the selector string.
// It returns a new Selection object for this subset of matching elements.
func (s *Selection) Filter(selector string) *Selection {
	return s.FilterMatcher(cascadia.MustCompile(selector))
}
コード例 #21
0
ファイル: traversal.go プロジェクト: devacto/grobot
// Closest gets the first element that matches the selector by testing the
// element itself and traversing up through its ancestors in the DOM tree.
func (s *Selection) Closest(selector string) *Selection {
	cs := cascadia.MustCompile(selector)
	return s.ClosestMatcher(cs)
}