Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
foolin committed May 8, 2020
1 parent 7c0044d commit c86c9b4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
48 changes: 24 additions & 24 deletions builtin_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"strings"
)

// Builtin functions are registered with a lowercase initial, eg: Text -> text()
// BuiltinFunctions builtin functions are registered with a lowercase initial, eg: Text -> text()
type BuiltinFunctions struct {
}

// absHref(baseUrl) get element attribute name `href`, and convert to absolute url, return *URL.
// AbsHref absHref(baseUrl) get element attribute name `href`, and convert to absolute url, return *URL.
// `baseUrl` is the base url like `https://example.com/`.
// //<a href="/foolin/pagser">Pagser</a>
// struct {
Expand All @@ -34,7 +34,7 @@ func (builtin BuiltinFunctions) AbsHref(selection *goquery.Selection, args ...st
return baseUrl.ResolveReference(hrefUrl), nil
}

// attr(name, defaultValue='') get element attribute value, return string.
// Attr attr(name, defaultValue='') get element attribute value, return string.
// outerHtml() get element outer html, return string.
// //<a href="https://github.com/foolin/pagser">Pagser</a>
// struct {
Expand All @@ -53,7 +53,7 @@ func (builtin BuiltinFunctions) Attr(node *goquery.Selection, args ...string) (o
return val, nil
}

// attrConcat(name, text1, $value, [ text2, ... text_n ])
// AttrConcat attrConcat(name, text1, $value, [ text2, ... text_n ])
// `name` get element attribute value by name,
// `text1, text2, ... text_n` The strings that you wish to join together,
// `$value` is placeholder for get element text
Expand Down Expand Up @@ -81,7 +81,7 @@ func (builtin BuiltinFunctions) AttrConcat(node *goquery.Selection, args ...stri
return builder.String(), nil
}

// attrEmpty(name, defaultValue) get element attribute value, return string.
// AttrEmpty attrEmpty(name, defaultValue) get element attribute value, return string.
// //<a href="https://github.com/foolin/pagser">Pagser</a>
// struct {
// Example string `pagser:".selector->AttrEmpty(href, '#')"`
Expand All @@ -99,7 +99,7 @@ func (builtin BuiltinFunctions) AttrEmpty(node *goquery.Selection, args ...strin
return value, nil
}

// attrSplit(name, sep=',', trim='true') get attribute value and split by separator to array string, return []string.
// AttrSplit attrSplit(name, sep=',', trim='true') get attribute value and split by separator to array string, return []string.
// struct {
// Examples []string `pagser:".selector->attrSplit('keywords', ',')"`
// }
Expand Down Expand Up @@ -130,7 +130,7 @@ func (builtin BuiltinFunctions) AttrSplit(node *goquery.Selection, args ...strin
return list, nil
}

// eachAttr() get each element attribute value, return []string.
// EachAttr eachAttr() get each element attribute value, return []string.
// //<a href="https://github.com/foolin/pagser">Pagser</a>
// struct {
// Examples []string `pagser:".selector->eachAttr(href)"`
Expand All @@ -147,7 +147,7 @@ func (builtin BuiltinFunctions) EachAttr(node *goquery.Selection, args ...string
return list, nil
}

// eachAttrEmpty(defaultValue) get each element attribute value, return []string.
// EachAttrEmpty eachAttrEmpty(defaultValue) get each element attribute value, return []string.
// //<a href="https://github.com/foolin/pagser">Pagser</a>
// struct {
// Examples []string `pagser:".selector->eachAttrEmpty(href, '#')"`
Expand All @@ -169,7 +169,7 @@ func (builtin BuiltinFunctions) EachAttrEmpty(node *goquery.Selection, args ...s
return list, nil
}

// eachHtml() get each element inner html, return []string.
// EachHtml eachHtml() get each element inner html, return []string.
// eachTextEmpty(defaultValue) get each element text, return []string.
// struct {
// Examples []string `pagser:".selector->eachHtml()"`
Expand All @@ -191,7 +191,7 @@ func (builtin BuiltinFunctions) EachHtml(node *goquery.Selection, args ...string
return list, nil
}

// eachOutHtml() get each element outer html, return []string.
// EachOutHtml eachOutHtml() get each element outer html, return []string.
// struct {
// Examples []string `pagser:".selector->eachOutHtml()"`
// }
Expand All @@ -212,7 +212,7 @@ func (builtin BuiltinFunctions) EachOutHtml(node *goquery.Selection, args ...str
return list, nil
}

// eachText() get each element text, return []string.
// EachText eachText() get each element text, return []string.
// struct {
// Examples []string `pagser:".selector->eachText('')"`
// }
Expand All @@ -224,7 +224,7 @@ func (builtin BuiltinFunctions) EachText(node *goquery.Selection, args ...string
return list, nil
}

// eachTextEmpty(defaultValue) get each element text, return []string.
// EachTextEmpty eachTextEmpty(defaultValue) get each element text, return []string.
// struct {
// Examples []string `pagser:".selector->eachTextEmpty('')"`
// }
Expand All @@ -244,7 +244,7 @@ func (builtin BuiltinFunctions) EachTextEmpty(node *goquery.Selection, args ...s
return list, nil
}

// eachTextJoin(sep) get each element text and join to string, return string.
// EachTextJoin eachTextJoin(sep) get each element text and join to string, return string.
// struct {
// Example string `pagser:".selector->eachTextJoin(',')"`
// }
Expand All @@ -260,7 +260,7 @@ func (builtin BuiltinFunctions) EachTextJoin(node *goquery.Selection, args ...st
return strings.Join(list, sep), nil
}

// eqAndAttr(index, name) reduces the set of matched elements to the one at the specified index, and attr() return string.
// EqAndAttr eqAndAttr(index, name) reduces the set of matched elements to the one at the specified index, and attr() return string.
// struct {
// Example string `pagser:".selector->eqAndAttr(0, href)"`
// }
Expand All @@ -277,7 +277,7 @@ func (builtin BuiltinFunctions) EqAndAttr(node *goquery.Selection, args ...strin
return node.Eq(idx).AttrOr(name, ""), nil
}

// eqAndHtml(index) reduces the set of matched elements to the one at the specified index, and html() return string.
// EqAndHtml eqAndHtml(index) reduces the set of matched elements to the one at the specified index, and html() return string.
// struct {
// Example string `pagser:".selector->eqAndHtml(0)"`
// }
Expand All @@ -293,7 +293,7 @@ func (builtin BuiltinFunctions) EqAndHtml(node *goquery.Selection, args ...strin
return node.Eq(idx).Html()
}

// eqAndOutHtml(index) reduces the set of matched elements to the one at the specified index, and outHtml() return string.
// EqAndOutHtml eqAndOutHtml(index) reduces the set of matched elements to the one at the specified index, and outHtml() return string.
// struct {
// Example string `pagser:".selector->eqAndOutHtml(0)"`
// }
Expand All @@ -309,7 +309,7 @@ func (builtin BuiltinFunctions) EqAndOutHtml(node *goquery.Selection, args ...st
return goquery.OuterHtml(node.Eq(idx))
}

// eqAndText(index) reduces the set of matched elements to the one at the specified index, return string.
// EqAndText eqAndText(index) reduces the set of matched elements to the one at the specified index, return string.
// struct {
// Example string `pagser:".selector->eqAndText(0)"`
// }
Expand All @@ -325,15 +325,15 @@ func (builtin BuiltinFunctions) EqAndText(node *goquery.Selection, args ...strin
return strings.TrimSpace(node.Eq(idx).Text()), nil
}

// html() get element inner html, return string.
// Html html() get element inner html, return string.
// struct {
// Example string `pagser:".selector->html()"`
// }
func (builtin BuiltinFunctions) Html(node *goquery.Selection, args ...string) (out interface{}, err error) {
return node.Html()
}

// outerHtml() get element outer html, return string.
// OutHtml outerHtml() get element outer html, return string.
// struct {
// Example string `pagser:".selector->outerHtml()"`
// }
Expand All @@ -345,23 +345,23 @@ func (builtin BuiltinFunctions) OutHtml(node *goquery.Selection, args ...string)
return html, nil
}

// size() returns the number of elements in the Selection object, return int.
// Size size() returns the number of elements in the Selection object, return int.
// struct {
// Size int `pagser:".selector->size()"`
// }
func (builtin BuiltinFunctions) Size(node *goquery.Selection, args ...string) (out interface{}, err error) {
return node.Size(), nil
}

//text() get element text, return string, this is default function, if not define function in struct tag.
// Text text() get element text, return string, this is default function, if not define function in struct tag.
// struct {
// Example string `pagser:".selector->text()"`
// }
func (builtin BuiltinFunctions) Text(node *goquery.Selection, args ...string) (out interface{}, err error) {
return strings.TrimSpace(node.Text()), nil
}

// textConcat(text1, $value, [ text2, ... text_n ])
// TextConcat textConcat(text1, $value, [ text2, ... text_n ])
// The `text1, text2, ... text_n` strings that you wish to join together,
// `$value` is placeholder for get element text, return string.
// struct {
Expand All @@ -383,7 +383,7 @@ func (builtin BuiltinFunctions) TextConcat(node *goquery.Selection, args ...stri
return builder.String(), nil
}

// textEmpty(defaultValue) get element text, if empty will return defaultValue, return string.
// TextEmpty textEmpty(defaultValue) get element text, if empty will return defaultValue, return string.
// struct {
// Example string `pagser:".selector->TextEmpty('')"`
// }
Expand All @@ -399,7 +399,7 @@ func (builtin BuiltinFunctions) TextEmpty(node *goquery.Selection, args ...strin
return value, nil
}

// textSplit(sep=',', trim='true') get element text and split by separator to array string, return []string.
// TextSplit textSplit(sep=',', trim='true') get element text and split by separator to array string, return []string.
// struct {
// Examples []string `pagser:".selector->textSplit('|')"`
// }
Expand Down
22 changes: 11 additions & 11 deletions builtin_selections.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import (
"strings"
)

// Builtin functions are registered with a lowercase initial, eg: Text -> text()
// BuiltinSelections builtin selection functions are registered with a lowercase initial, eg: Text -> text()
type BuiltinSelections struct {
}

// child(selector='') gets the child elements of each element in the Selection,
// Child child(selector='') gets the child elements of each element in the Selection,
// Filtered by the specified selector if selector not empty,
// It returns Selection object containing these elements for nested struct..
// struct {
Expand All @@ -30,7 +30,7 @@ func (builtin BuiltinSelections) Child(node *goquery.Selection, args ...string)
return node.Children(), nil
}

// eq(index) reduces the set of matched elements to the one at the specified index.
// Eq eq(index) reduces the set of matched elements to the one at the specified index.
// If a negative index is given, it counts backwards starting at the end of the set.
// It returns a Selection object for nested struct, and an empty Selection object if the
// index is invalid.
Expand All @@ -51,7 +51,7 @@ func (builtin BuiltinSelections) Eq(node *goquery.Selection, args ...string) (ou
return node.Eq(idx), nil
}

// first() First reduces the set of matched elements to the first in the set.
// First first() First reduces the set of matched elements to the first in the set.
// It returns a new Selection object, and an empty Selection object if the
// the selection is empty.
// It returns Selection object containing these elements for nested struct.
Expand All @@ -64,7 +64,7 @@ func (builtin BuiltinSelections) First(node *goquery.Selection, args ...string)
return node.First(), nil
}

// last(selector='') reduces the set of matched elements to the last in the set.
// Last last(selector='') reduces the set of matched elements to the last in the set.
// It returns a new Selection object, and an empty Selection object if
// the selection is empty.
// struct {
Expand All @@ -76,7 +76,7 @@ func (builtin BuiltinSelections) Last(node *goquery.Selection, args ...string) (
return node.Last(), nil
}

// next(selector='') gets the immediately following sibling of each element in the Selection.
// Next next(selector='') gets the immediately following sibling of each element in the Selection.
// Filtered by the specified selector if selector not empty,
// It returns Selection object containing these elements for nested struct.
// struct {
Expand All @@ -95,7 +95,7 @@ func (builtin BuiltinSelections) Next(node *goquery.Selection, args ...string) (
return node.Next(), nil
}

// parent(selector='') gets the parent elements of each element in the Selection.
// Parent parent(selector='') gets the parent elements of each element in the Selection.
// Filtered by the specified selector if selector not empty,
// It returns Selection object containing these elements for nested struct.
// struct {
Expand All @@ -114,7 +114,7 @@ func (builtin BuiltinSelections) Parent(node *goquery.Selection, args ...string)
return node.Parent(), nil
}

// parents(selector='') gets the parent elements of each element in the Selection.
// Parents parents(selector='') gets the parent elements of each element in the Selection.
// Filtered by the specified selector if selector not empty,
// It returns Selection object containing these elements for nested struct.
// struct {
Expand All @@ -133,7 +133,7 @@ func (builtin BuiltinSelections) Parents(node *goquery.Selection, args ...string
return node.Parents(), nil
}

// parentsUntil(selector) gets the ancestors of each element in the Selection, up to but
// ParentsUntil parentsUntil(selector) 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.
// It returns Selection object containing these elements for nested struct.
Expand All @@ -150,7 +150,7 @@ func (builtin BuiltinSelections) ParentsUntil(node *goquery.Selection, args ...s
return node.ParentsUntil(selector), nil
}

// prev() gets the immediately preceding sibling of each element in the Selection.
// Prev prev() gets the immediately preceding sibling of each element in the Selection.
// Filtered by the specified selector if selector not empty,
// It returns Selection object containing these elements for nested struct.
// struct {
Expand All @@ -169,7 +169,7 @@ func (builtin BuiltinSelections) Prev(node *goquery.Selection, args ...string) (
return node.Prev(), nil
}

// siblings() gets the siblings of each element in the Selection.
// Siblings siblings() gets the siblings of each element in the Selection.
// Filtered by the specified selector if selector not empty,
// It returns Selection object containing these elements for nested struct.
// struct {
Expand Down

0 comments on commit c86c9b4

Please sign in to comment.