1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-01-26 03:51:57 +02:00

Rename variables and methods to match styleguide

This commit is contained in:
David Landry 2018-10-05 16:35:08 -04:00
parent 689cd7187c
commit 90c2c702e4
15 changed files with 412 additions and 412 deletions

View File

@ -11,7 +11,7 @@ import (
type Topic struct {
Name string `json:"name"`
Description string `json:"description"`
Url string `json:"url"`
URL string `json:"url"`
}
func main() {
@ -23,7 +23,7 @@ func main() {
}
for _, topic := range topics {
fmt.Println(fmt.Sprintf("%s: %s %s", topic.Name, topic.Description, topic.Url))
fmt.Println(fmt.Sprintf("%s: %s %s", topic.Name, topic.Description, topic.URL))
}
}

File diff suppressed because it is too large Load Diff

View File

@ -43,8 +43,8 @@ type (
pos int
}
HtmlNodeIterator struct {
values values.HtmlNode
HTMLNodeIterator struct {
values values.HTMLNode
pos int
}
)
@ -56,7 +56,7 @@ func ToIterator(value core.Value) (Iterator, error) {
case core.ObjectType:
return NewObjectIterator(value.(*values.Object)), nil
case core.HtmlElementType, core.HtmlDocumentType:
return NewHtmlNodeIterator(value.(values.HtmlNode)), nil
return NewHTMLNodeIterator(value.(values.HTMLNode)), nil
default:
return nil, core.TypeError(
value.Type(),
@ -214,15 +214,15 @@ func (iterator *ObjectIterator) Next() (core.Value, core.Value, error) {
return values.None, values.None, ErrExhausted
}
func NewHtmlNodeIterator(input values.HtmlNode) *HtmlNodeIterator {
return &HtmlNodeIterator{input, 0}
func NewHTMLNodeIterator(input values.HTMLNode) *HTMLNodeIterator {
return &HTMLNodeIterator{input, 0}
}
func (iterator *HtmlNodeIterator) HasNext() bool {
func (iterator *HTMLNodeIterator) HasNext() bool {
return iterator.values.Length() > values.NewInt(iterator.pos)
}
func (iterator *HtmlNodeIterator) Next() (core.Value, core.Value, error) {
func (iterator *HTMLNodeIterator) Next() (core.Value, core.Value, error) {
if iterator.values.Length() > values.NewInt(iterator.pos) {
idx := iterator.pos
val := iterator.values.GetChildNode(values.NewInt(idx))

View File

@ -15,8 +15,8 @@ const (
DateTimeType Type = 5
ArrayType Type = 6
ObjectType Type = 7
HtmlElementType Type = 8
HtmlDocumentType Type = 9
HTMLElementType Type = 8
HTMLDocumentType Type = 9
BinaryType Type = 10
)
@ -29,8 +29,8 @@ var typestr = map[Type]string{
DateTimeType: "datetime",
ArrayType: "array",
ObjectType: "object",
HtmlElementType: "HTMLElement",
HtmlDocumentType: "HTMLDocument",
HTMLElementType: "HTMLElement",
HTMLDocumentType: "HTMLDocument",
BinaryType: "BinaryType",
}

View File

@ -3,7 +3,7 @@ package values
import "github.com/MontFerret/ferret/pkg/runtime/core"
type (
HtmlNode interface {
HTMLNode interface {
core.Value
NodeType() Int
@ -14,7 +14,7 @@ type (
InnerText() String
InnerHtml() String
InnerHTML() String
Value() core.Value
@ -31,9 +31,9 @@ type (
QuerySelectorAll(selector String) core.Value
}
HtmlDocument interface {
HtmlNode
HTMLDocument interface {
HTMLNode
Url() core.Value
URL() core.Value
}
)

View File

@ -13,7 +13,7 @@ import (
* @param selector (String) - Selector
* @returns str (String) - String value of inner html.
*/
func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) {
func InnerHTML(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)
if err != nil {
@ -35,7 +35,7 @@ func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) {
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
}
return doc.InnerHtmlBySelector(values.NewString(selector))
return doc.InnerHTMLBySelector(values.NewString(selector))
}
/*
@ -44,7 +44,7 @@ func InnerHtml(_ context.Context, args ...core.Value) (core.Value, error) {
* @param selector (String) - Selector
* @returns array (Array) - Array of string values.
*/
func InnerHtmlAll(_ context.Context, args ...core.Value) (core.Value, error) {
func InnerHTMLAll(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 2, 2)
if err != nil {
@ -66,7 +66,7 @@ func InnerHtmlAll(_ context.Context, args ...core.Value) (core.Value, error) {
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
}
return doc.InnerHtmlBySelectorAll(values.NewString(selector))
return doc.InnerHTMLBySelectorAll(values.NewString(selector))
}
/*
@ -97,7 +97,7 @@ func InnerText(_ context.Context, args ...core.Value) (core.Value, error) {
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
}
return doc.InnerHtmlBySelector(values.NewString(selector))
return doc.InnerHTMLBySelector(values.NewString(selector))
}
/*
@ -128,5 +128,5 @@ func InnerTextAll(_ context.Context, args ...core.Value) (core.Value, error) {
return values.EmptyString, core.Error(core.ErrInvalidType, "expected dynamic document")
}
return doc.InnerHtmlBySelectorAll(values.NewString(selector))
return doc.InnerHTMLBySelectorAll(values.NewString(selector))
}

View File

@ -2,7 +2,7 @@ package common
import "golang.org/x/net/html"
func ToHtmlType(nt html.NodeType) int {
func ToHTMLType(nt html.NodeType) int {
switch nt {
case html.DocumentNode:
return 9

View File

@ -21,7 +21,7 @@ import (
"time"
)
type HtmlDocument struct {
type HTMLDocument struct {
sync.Mutex
logger *zerolog.Logger
conn *rpcc.Conn
@ -31,11 +31,11 @@ type HtmlDocument struct {
element *HtmlElement
}
func LoadHtmlDocument(
func LoadHTMLDocument(
ctx context.Context,
conn *rpcc.Conn,
url string,
) (*HtmlDocument, error) {
) (*HTMLDocument, error) {
if conn == nil {
return nil, core.Error(core.ErrMissedArgument, "connection")
}
@ -84,7 +84,7 @@ func LoadHtmlDocument(
return nil, err
}
root, innerHtml, err := getRootElement(client)
root, innerHTML, err := getRootElement(client)
if err != nil {
return nil, err
@ -96,13 +96,13 @@ func LoadHtmlDocument(
return nil, err
}
return NewHtmlDocument(
return NewHTMLDocument(
logging.FromContext(ctx),
conn,
client,
broker,
root,
innerHtml,
innerHTML,
), nil
}
@ -117,29 +117,29 @@ func getRootElement(client *cdp.Client) (dom.Node, values.String, error) {
return dom.Node{}, values.EmptyString, err
}
innerHtml, err := client.DOM.GetOuterHTML(ctx, dom.NewGetOuterHTMLArgs().SetNodeID(d.Root.NodeID))
innerHTML, err := client.DOM.GetOuterHTML(ctx, dom.NewGetOuterHTMLArgs().SetNodeID(d.Root.NodeID))
if err != nil {
return dom.Node{}, values.EmptyString, err
}
return d.Root, values.NewString(innerHtml.OuterHTML), nil
return d.Root, values.NewString(innerHTML.OuterHTML), nil
}
func NewHtmlDocument(
func NewHTMLDocument(
logger *zerolog.Logger,
conn *rpcc.Conn,
client *cdp.Client,
broker *events.EventBroker,
root dom.Node,
innerHtml values.String,
) *HtmlDocument {
doc := new(HtmlDocument)
innerHTML values.String,
) *HTMLDocument {
doc := new(HTMLDocument)
doc.logger = logger
doc.conn = conn
doc.client = client
doc.events = broker
doc.element = NewHtmlElement(doc.logger, client, broker, root.NodeID, root, innerHtml)
doc.element = NewHtmlElement(doc.logger, client, broker, root.NodeID, root, innerHTML)
doc.url = ""
if root.BaseURL != nil {
@ -150,7 +150,7 @@ func NewHtmlDocument(
doc.Lock()
defer doc.Unlock()
updated, innerHtml, err := getRootElement(client)
updated, innerHTML, err := getRootElement(client)
if err != nil {
doc.logger.Error().
@ -165,7 +165,7 @@ func NewHtmlDocument(
doc.element.Close()
// create a new root element wrapper
doc.element = NewHtmlElement(doc.logger, client, broker, updated.NodeID, updated, innerHtml)
doc.element = NewHtmlElement(doc.logger, client, broker, updated.NodeID, updated, innerHTML)
doc.url = ""
if updated.BaseURL != nil {
@ -176,32 +176,32 @@ func NewHtmlDocument(
return doc
}
func (doc *HtmlDocument) MarshalJSON() ([]byte, error) {
func (doc *HTMLDocument) MarshalJSON() ([]byte, error) {
doc.Lock()
defer doc.Unlock()
return doc.element.MarshalJSON()
}
func (doc *HtmlDocument) Type() core.Type {
return core.HtmlDocumentType
func (doc *HTMLDocument) Type() core.Type {
return core.HTMLDocumentType
}
func (doc *HtmlDocument) String() string {
func (doc *HTMLDocument) String() string {
doc.Lock()
defer doc.Unlock()
return doc.url.String()
}
func (doc *HtmlDocument) Unwrap() interface{} {
func (doc *HTMLDocument) Unwrap() interface{} {
doc.Lock()
defer doc.Unlock()
return doc.element
}
func (doc *HtmlDocument) Hash() int {
func (doc *HTMLDocument) Hash() int {
doc.Lock()
defer doc.Unlock()
@ -216,21 +216,21 @@ func (doc *HtmlDocument) Hash() int {
return out
}
func (doc *HtmlDocument) Clone() core.Value {
func (doc *HTMLDocument) Clone() core.Value {
return values.None
}
func (doc *HtmlDocument) Compare(other core.Value) int {
func (doc *HTMLDocument) Compare(other core.Value) int {
doc.Lock()
defer doc.Unlock()
switch other.Type() {
case core.HtmlDocumentType:
other := other.(*HtmlDocument)
case core.HTMLDocumentType:
other := other.(*HTMLDocument)
return doc.url.Compare(other.url)
default:
if other.Type() > core.HtmlDocumentType {
if other.Type() > core.HTMLDocumentType {
return -1
}
@ -238,7 +238,7 @@ func (doc *HtmlDocument) Compare(other core.Value) int {
}
}
func (doc *HtmlDocument) Close() error {
func (doc *HTMLDocument) Close() error {
doc.Lock()
defer doc.Unlock()
@ -287,95 +287,95 @@ func (doc *HtmlDocument) Close() error {
return doc.conn.Close()
}
func (doc *HtmlDocument) NodeType() values.Int {
func (doc *HTMLDocument) NodeType() values.Int {
doc.Lock()
defer doc.Unlock()
return doc.element.NodeType()
}
func (doc *HtmlDocument) NodeName() values.String {
func (doc *HTMLDocument) NodeName() values.String {
doc.Lock()
defer doc.Unlock()
return doc.element.NodeName()
}
func (doc *HtmlDocument) Length() values.Int {
func (doc *HTMLDocument) Length() values.Int {
doc.Lock()
defer doc.Unlock()
return doc.element.Length()
}
func (doc *HtmlDocument) InnerText() values.String {
func (doc *HTMLDocument) InnerText() values.String {
doc.Lock()
defer doc.Unlock()
return doc.element.InnerText()
}
func (doc *HtmlDocument) InnerHtml() values.String {
func (doc *HTMLDocument) InnerHTML() values.String {
doc.Lock()
defer doc.Unlock()
return doc.element.InnerHtml()
return doc.element.InnerHTML()
}
func (doc *HtmlDocument) Value() core.Value {
func (doc *HTMLDocument) Value() core.Value {
doc.Lock()
defer doc.Unlock()
return doc.element.Value()
}
func (doc *HtmlDocument) GetAttributes() core.Value {
func (doc *HTMLDocument) GetAttributes() core.Value {
doc.Lock()
defer doc.Unlock()
return doc.element.GetAttributes()
}
func (doc *HtmlDocument) GetAttribute(name values.String) core.Value {
func (doc *HTMLDocument) GetAttribute(name values.String) core.Value {
doc.Lock()
defer doc.Unlock()
return doc.element.GetAttribute(name)
}
func (doc *HtmlDocument) GetChildNodes() core.Value {
func (doc *HTMLDocument) GetChildNodes() core.Value {
doc.Lock()
defer doc.Unlock()
return doc.element.GetChildNodes()
}
func (doc *HtmlDocument) GetChildNode(idx values.Int) core.Value {
func (doc *HTMLDocument) GetChildNode(idx values.Int) core.Value {
doc.Lock()
defer doc.Unlock()
return doc.element.GetChildNode(idx)
}
func (doc *HtmlDocument) QuerySelector(selector values.String) core.Value {
func (doc *HTMLDocument) QuerySelector(selector values.String) core.Value {
doc.Lock()
defer doc.Unlock()
return doc.element.QuerySelector(selector)
}
func (doc *HtmlDocument) QuerySelectorAll(selector values.String) core.Value {
func (doc *HTMLDocument) QuerySelectorAll(selector values.String) core.Value {
doc.Lock()
defer doc.Unlock()
return doc.element.QuerySelectorAll(selector)
}
func (doc *HtmlDocument) Url() core.Value {
func (doc *HTMLDocument) URL() core.Value {
return doc.url
}
func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.String, error) {
func (doc *HTMLDocument) InnerHTMLBySelector(selector values.String) (values.String, error) {
res, err := eval.Eval(
doc.client,
fmt.Sprintf(`
@ -385,7 +385,7 @@ func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.Str
return "";
}
return el.innerHtml;
return el.innerHTML;
`, eval.ParamString(selector.String())),
true,
false,
@ -402,7 +402,7 @@ func (doc *HtmlDocument) InnerHtmlBySelector(selector values.String) (values.Str
return values.EmptyString, nil
}
func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values.Array, error) {
func (doc *HTMLDocument) InnerHTMLBySelectorAll(selector values.String) (*values.Array, error) {
res, err := eval.Eval(
doc.client,
fmt.Sprintf(`
@ -414,7 +414,7 @@ func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values
}
elements.forEach((i) => {
result.push(i.innerHtml);
result.push(i.innerHTML);
});
return result;
@ -434,7 +434,7 @@ func (doc *HtmlDocument) InnerHtmlBySelectorAll(selector values.String) (*values
return values.NewArray(0), nil
}
func (doc *HtmlDocument) InnerTextBySelector(selector values.String) (values.String, error) {
func (doc *HTMLDocument) InnerTextBySelector(selector values.String) (values.String, error) {
res, err := eval.Eval(
doc.client,
fmt.Sprintf(`
@ -461,7 +461,7 @@ func (doc *HtmlDocument) InnerTextBySelector(selector values.String) (values.Str
return values.EmptyString, nil
}
func (doc *HtmlDocument) InnerTextBySelectorAll(selector values.String) (*values.Array, error) {
func (doc *HTMLDocument) InnerTextBySelectorAll(selector values.String) (*values.Array, error) {
res, err := eval.Eval(
doc.client,
fmt.Sprintf(`
@ -493,7 +493,7 @@ func (doc *HtmlDocument) InnerTextBySelectorAll(selector values.String) (*values
return values.NewArray(0), nil
}
func (doc *HtmlDocument) ClickBySelector(selector values.String) (values.Boolean, error) {
func (doc *HTMLDocument) ClickBySelector(selector values.String) (values.Boolean, error) {
res, err := eval.Eval(
doc.client,
fmt.Sprintf(`
@ -523,7 +523,7 @@ func (doc *HtmlDocument) ClickBySelector(selector values.String) (values.Boolean
return values.False, nil
}
func (doc *HtmlDocument) ClickBySelectorAll(selector values.String) (values.Boolean, error) {
func (doc *HTMLDocument) ClickBySelectorAll(selector values.String) (values.Boolean, error) {
res, err := eval.Eval(
doc.client,
fmt.Sprintf(`
@ -555,7 +555,7 @@ func (doc *HtmlDocument) ClickBySelectorAll(selector values.String) (values.Bool
return values.False, nil
}
func (doc *HtmlDocument) InputBySelector(selector values.String, value core.Value) (values.Boolean, error) {
func (doc *HTMLDocument) InputBySelector(selector values.String, value core.Value) (values.Boolean, error) {
res, err := eval.Eval(
doc.client,
fmt.Sprintf(
@ -591,7 +591,7 @@ func (doc *HtmlDocument) InputBySelector(selector values.String, value core.Valu
return values.False, nil
}
func (doc *HtmlDocument) WaitForSelector(selector values.String, timeout values.Int) error {
func (doc *HTMLDocument) WaitForSelector(selector values.String, timeout values.Int) error {
task := events.NewWaitTask(
doc.client,
fmt.Sprintf(`
@ -612,7 +612,7 @@ func (doc *HtmlDocument) WaitForSelector(selector values.String, timeout values.
return err
}
func (doc *HtmlDocument) WaitForNavigation(timeout values.Int) error {
func (doc *HTMLDocument) WaitForNavigation(timeout values.Int) error {
timer := time.NewTimer(time.Millisecond * time.Duration(timeout))
onEvent := make(chan bool)
listener := func(_ interface{}) {
@ -636,7 +636,7 @@ func (doc *HtmlDocument) WaitForNavigation(timeout values.Int) error {
}
}
func (doc *HtmlDocument) Navigate(url values.String) error {
func (doc *HTMLDocument) Navigate(url values.String) error {
ctx := context.Background()
repl, err := doc.client.Page.Navigate(ctx, page.NewNavigateArgs(url.String()))

View File

@ -21,7 +21,7 @@ import (
const DefaultTimeout = time.Second * 30
type HtmlElement struct {
type HTMLElement struct {
sync.Mutex
logger *zerolog.Logger
client *cdp.Client
@ -30,7 +30,7 @@ type HtmlElement struct {
id dom.NodeID
nodeType values.Int
nodeName values.String
innerHtml values.String
innerHTML values.String
innerText *common.LazyValue
value core.Value
rawAttrs []string
@ -44,7 +44,7 @@ func LoadElement(
client *cdp.Client,
broker *events.EventBroker,
id dom.NodeID,
) (*HtmlElement, error) {
) (*HTMLElement, error) {
if client == nil {
return nil, core.Error(core.ErrMissedArgument, "client")
}
@ -65,31 +65,31 @@ func LoadElement(
return nil, core.Error(err, strconv.Itoa(int(id)))
}
innerHtml, err := loadInnerHtml(client, id)
innerHTML, err := loadInnerHTML(client, id)
if err != nil {
return nil, core.Error(err, strconv.Itoa(int(id)))
}
return NewHtmlElement(
return NewHTMLElement(
logger,
client,
broker,
id,
node.Node,
innerHtml,
innerHTML,
), nil
}
func NewHtmlElement(
func NewHTMLElement(
logger *zerolog.Logger,
client *cdp.Client,
broker *events.EventBroker,
id dom.NodeID,
node dom.Node,
innerHtml values.String,
) *HtmlElement {
el := new(HtmlElement)
innerHTML values.String,
) *HTMLElement {
el := new(HTMLElement)
el.logger = logger
el.client = client
el.broker = broker
@ -97,7 +97,7 @@ func NewHtmlElement(
el.id = id
el.nodeType = values.NewInt(node.NodeType)
el.nodeName = values.NewString(node.NodeName)
el.innerHtml = innerHtml
el.innerHTML = innerHTML
el.innerText = common.NewLazyValue(el.loadInnerText)
el.rawAttrs = node.Attributes[:]
el.attributes = common.NewLazyValue(el.loadAttrs)
@ -120,7 +120,7 @@ func NewHtmlElement(
return el
}
func (el *HtmlElement) Close() error {
func (el *HTMLElement) Close() error {
el.Lock()
defer el.Unlock()
@ -140,11 +140,11 @@ func (el *HtmlElement) Close() error {
return nil
}
func (el *HtmlElement) Type() core.Type {
return core.HtmlElementType
func (el *HTMLElement) Type() core.Type {
return core.HTMLElementType
}
func (el *HtmlElement) MarshalJSON() ([]byte, error) {
func (el *HTMLElement) MarshalJSON() ([]byte, error) {
val, err := el.innerText.Value()
if err != nil {
@ -154,29 +154,29 @@ func (el *HtmlElement) MarshalJSON() ([]byte, error) {
return json.Marshal(val.String())
}
func (el *HtmlElement) String() string {
return el.InnerHtml().String()
func (el *HTMLElement) String() string {
return el.InnerHTML().String()
}
func (el *HtmlElement) Compare(other core.Value) int {
func (el *HTMLElement) Compare(other core.Value) int {
switch other.Type() {
case core.HtmlDocumentType:
other := other.(*HtmlElement)
other := other.(*HTMLElement)
id := int(el.id)
otherId := int(other.id)
otherID := int(other.id)
if id == otherId {
if id == otherID {
return 0
}
if id > otherId {
if id > otherID {
return 1
}
return -1
default:
if other.Type() > core.HtmlElementType {
if other.Type() > core.HTMLElementType {
return -1
}
@ -184,17 +184,17 @@ func (el *HtmlElement) Compare(other core.Value) int {
}
}
func (el *HtmlElement) Unwrap() interface{} {
func (el *HTMLElement) Unwrap() interface{} {
return el
}
func (el *HtmlElement) Hash() int {
func (el *HTMLElement) Hash() int {
el.Lock()
defer el.Unlock()
h := sha512.New()
out, err := h.Write([]byte(el.innerHtml))
out, err := h.Write([]byte(el.innerHTML))
if err != nil {
el.logger.Error().
@ -208,7 +208,7 @@ func (el *HtmlElement) Hash() int {
return out
}
func (el *HtmlElement) Value() core.Value {
func (el *HTMLElement) Value() core.Value {
if !el.IsConnected() {
return el.value
}
@ -232,23 +232,23 @@ func (el *HtmlElement) Value() core.Value {
return val
}
func (el *HtmlElement) Clone() core.Value {
func (el *HTMLElement) Clone() core.Value {
return values.None
}
func (el *HtmlElement) Length() values.Int {
func (el *HTMLElement) Length() values.Int {
return values.NewInt(len(el.children))
}
func (el *HtmlElement) NodeType() values.Int {
func (el *HTMLElement) NodeType() values.Int {
return el.nodeType
}
func (el *HtmlElement) NodeName() values.String {
func (el *HTMLElement) NodeName() values.String {
return el.nodeName
}
func (el *HtmlElement) GetAttributes() core.Value {
func (el *HTMLElement) GetAttributes() core.Value {
val, err := el.attributes.Value()
if err != nil {
@ -259,7 +259,7 @@ func (el *HtmlElement) GetAttributes() core.Value {
return val.Clone()
}
func (el *HtmlElement) GetAttribute(name values.String) core.Value {
func (el *HTMLElement) GetAttribute(name values.String) core.Value {
attrs, err := el.attributes.Value()
if err != nil {
@ -275,7 +275,7 @@ func (el *HtmlElement) GetAttribute(name values.String) core.Value {
return val
}
func (el *HtmlElement) GetChildNodes() core.Value {
func (el *HTMLElement) GetChildNodes() core.Value {
val, err := el.loadedChildren.Value()
if err != nil {
@ -285,7 +285,7 @@ func (el *HtmlElement) GetChildNodes() core.Value {
return val
}
func (el *HtmlElement) GetChildNode(idx values.Int) core.Value {
func (el *HTMLElement) GetChildNode(idx values.Int) core.Value {
val, err := el.loadedChildren.Value()
if err != nil {
@ -295,7 +295,7 @@ func (el *HtmlElement) GetChildNode(idx values.Int) core.Value {
return val.(*values.Array).Get(idx)
}
func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
func (el *HTMLElement) QuerySelector(selector values.String) core.Value {
if !el.IsConnected() {
return values.NewArray(0)
}
@ -330,7 +330,7 @@ func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
return res
}
func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value {
func (el *HTMLElement) QuerySelectorAll(selector values.String) core.Value {
if !el.IsConnected() {
return values.NewArray(0)
}
@ -371,7 +371,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value {
return arr
}
func (el *HtmlElement) InnerText() values.String {
func (el *HTMLElement) InnerText() values.String {
val, err := el.innerText.Value()
if err != nil {
@ -381,14 +381,14 @@ func (el *HtmlElement) InnerText() values.String {
return val.(values.String)
}
func (el *HtmlElement) InnerHtml() values.String {
func (el *HTMLElement) InnerHTML() values.String {
el.Lock()
defer el.Unlock()
return el.innerHtml
return el.innerHTML
}
func (el *HtmlElement) Click() (values.Boolean, error) {
func (el *HTMLElement) Click() (values.Boolean, error) {
ctx, cancel := contextWithTimeout()
defer cancel()
@ -396,22 +396,22 @@ func (el *HtmlElement) Click() (values.Boolean, error) {
return events.DispatchEvent(ctx, el.client, el.id, "click")
}
func (el *HtmlElement) Input(value core.Value) error {
func (el *HTMLElement) Input(value core.Value) error {
ctx, cancel := contextWithTimeout()
defer cancel()
return el.client.DOM.SetAttributeValue(ctx, dom.NewSetAttributeValueArgs(el.id, "value", value.String()))
}
func (el *HtmlElement) IsConnected() values.Boolean {
func (el *HTMLElement) IsConnected() values.Boolean {
el.Lock()
defer el.Unlock()
return el.connected
}
func (el *HtmlElement) loadInnerText() (core.Value, error) {
h := el.InnerHtml()
func (el *HTMLElement) loadInnerText() (core.Value, error) {
h := el.InnerHTML()
if h == values.EmptyString {
return h, nil
@ -434,11 +434,11 @@ func (el *HtmlElement) loadInnerText() (core.Value, error) {
return values.NewString(parsed.Text()), nil
}
func (el *HtmlElement) loadAttrs() (core.Value, error) {
func (el *HTMLElement) loadAttrs() (core.Value, error) {
return parseAttrs(el.rawAttrs), nil
}
func (el *HtmlElement) loadChildren() (core.Value, error) {
func (el *HTMLElement) loadChildren() (core.Value, error) {
if !el.IsConnected() {
return values.NewArray(0), nil
}
@ -458,11 +458,11 @@ func (el *HtmlElement) loadChildren() (core.Value, error) {
return loaded, nil
}
func (el *HtmlElement) handlePageReload(message interface{}) {
func (el *HTMLElement) handlePageReload(message interface{}) {
el.Close()
}
func (el *HtmlElement) handleAttrModified(message interface{}) {
func (el *HTMLElement) handleAttrModified(message interface{}) {
reply, ok := message.(*dom.AttributeModifiedReply)
// well....
@ -500,7 +500,7 @@ func (el *HtmlElement) handleAttrModified(message interface{}) {
attrs.Set(values.NewString(reply.Name), values.NewString(reply.Value))
}
func (el *HtmlElement) handleAttrRemoved(message interface{}) {
func (el *HTMLElement) handleAttrRemoved(message interface{}) {
reply, ok := message.(*dom.AttributeRemovedReply)
// well....
@ -539,7 +539,7 @@ func (el *HtmlElement) handleAttrRemoved(message interface{}) {
attrs.Remove(values.NewString(reply.Name))
}
func (el *HtmlElement) handleChildrenCountChanged(message interface{}) {
func (el *HTMLElement) handleChildrenCountChanged(message interface{}) {
reply, ok := message.(*dom.ChildNodeCountUpdatedReply)
if !ok {
@ -568,7 +568,7 @@ func (el *HtmlElement) handleChildrenCountChanged(message interface{}) {
el.children = createChildrenArray(node.Node.Children)
}
func (el *HtmlElement) handleChildInserted(message interface{}) {
func (el *HTMLElement) handleChildInserted(message interface{}) {
reply, ok := message.(*dom.ChildNodeInsertedReply)
if !ok {
@ -579,26 +579,26 @@ func (el *HtmlElement) handleChildInserted(message interface{}) {
return
}
targetIdx := -1
prevId := reply.PreviousNodeID
nextId := reply.Node.NodeID
targetIDx := -1
prevID := reply.PreviousNodeID
nextID := reply.Node.NodeID
el.Lock()
defer el.Unlock()
for idx, id := range el.children {
if id == prevId {
targetIdx = idx
if id == prevID {
targetIDx = idx
break
}
}
if targetIdx == -1 {
if targetIDx == -1 {
return
}
arr := el.children
el.children = append(arr[:targetIdx], append([]dom.NodeID{nextId}, arr[targetIdx:]...)...)
el.children = append(arr[:targetIDx], append([]dom.NodeID{nextID}, arr[targetIDx:]...)...)
if !el.loadedChildren.Ready() {
return
@ -611,7 +611,7 @@ func (el *HtmlElement) handleChildInserted(message interface{}) {
}
loadedArr := loaded.(*values.Array)
loadedEl, err := LoadElement(el.logger, el.client, el.broker, nextId)
loadedEl, err := LoadElement(el.logger, el.client, el.broker, nextID)
if err != nil {
el.logger.Error().
@ -623,9 +623,9 @@ func (el *HtmlElement) handleChildInserted(message interface{}) {
return
}
loadedArr.Insert(values.NewInt(targetIdx), loadedEl)
loadedArr.Insert(values.NewInt(targetIDx), loadedEl)
newInnerHtml, err := loadInnerHtml(el.client, el.id)
newInnerHTML, err := loadInnerHTML(el.client, el.id)
if err != nil {
el.logger.Error().
@ -637,10 +637,10 @@ func (el *HtmlElement) handleChildInserted(message interface{}) {
return
}
el.innerHtml = newInnerHtml
el.innerHTML = newInnerHTML
}
func (el *HtmlElement) handleChildDeleted(message interface{}) {
func (el *HTMLElement) handleChildDeleted(message interface{}) {
reply, ok := message.(*dom.ChildNodeRemovedReply)
if !ok {
@ -651,25 +651,25 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) {
return
}
targetIdx := -1
targetId := reply.NodeID
targetIDx := -1
targetID := reply.NodeID
el.Lock()
defer el.Unlock()
for idx, id := range el.children {
if id == targetId {
targetIdx = idx
if id == targetID {
targetIDx = idx
break
}
}
if targetIdx == -1 {
if targetIDx == -1 {
return
}
arr := el.children
el.children = append(arr[:targetIdx], arr[targetIdx+1:]...)
el.children = append(arr[:targetIDx], arr[targetIDx+1:]...)
if !el.loadedChildren.Ready() {
return
@ -682,9 +682,9 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) {
}
loadedArr := loaded.(*values.Array)
loadedArr.RemoveAt(values.NewInt(targetIdx))
loadedArr.RemoveAt(values.NewInt(targetIDx))
newInnerHtml, err := loadInnerHtml(el.client, el.id)
newInnerHTML, err := loadInnerHTML(el.client, el.id)
if err != nil {
el.logger.Error().
@ -696,5 +696,5 @@ func (el *HtmlElement) handleChildDeleted(message interface{}) {
return
}
el.innerHtml = newInnerHtml
el.innerHTML = newInnerHTML
}

View File

@ -47,10 +47,10 @@ func DispatchEvent(
return values.False, nil
}
evtId := evt.Result.ObjectID
evtID := evt.Result.ObjectID
// release the event object
defer client.Runtime.ReleaseObject(ctx, runtime.NewReleaseObjectArgs(*evtId))
defer client.Runtime.ReleaseObject(ctx, runtime.NewReleaseObjectArgs(*evtID))
res, err := client.Runtime.CallFunctionOn(
ctx,

View File

@ -51,7 +51,7 @@ func parseAttrs(attrs []string) *values.Object {
return res
}
func loadInnerHtml(client *cdp.Client, id dom.NodeID) (values.String, error) {
func loadInnerHTML(client *cdp.Client, id dom.NodeID) (values.String, error) {
res, err := client.DOM.GetOuterHTML(context.Background(), dom.NewGetOuterHTMLArgs().SetNodeID(id))
if err != nil {

View File

@ -6,15 +6,15 @@ import (
"github.com/PuerkitoBio/goquery"
)
type HtmlDocument struct {
type HTMLDocument struct {
*HtmlElement
url values.String
}
func NewHtmlDocument(
func NewHTMLDocument(
url string,
node *goquery.Document,
) (*HtmlDocument, error) {
) (*HTMLDocument, error) {
if url == "" {
return nil, core.Error(core.ErrMissedArgument, "document url")
}
@ -29,21 +29,21 @@ func NewHtmlDocument(
return nil, err
}
return &HtmlDocument{el, values.NewString(url)}, nil
return &HTMLDocument{el, values.NewString(url)}, nil
}
func (el *HtmlDocument) Type() core.Type {
return core.HtmlDocumentType
func (el *HTMLDocument) Type() core.Type {
return core.HTMLDocumentType
}
func (el *HtmlDocument) Compare(other core.Value) int {
func (el *HTMLDocument) Compare(other core.Value) int {
switch other.Type() {
case core.HtmlDocumentType:
otherDoc := other.(values.HtmlDocument)
case core.HTMLDocumentType:
otherDoc := other.(values.HTMLDocument)
return el.url.Compare(otherDoc.Url())
return el.url.Compare(otherDoc.URL())
default:
if other.Type() > core.HtmlDocumentType {
if other.Type() > core.HTMLDocumentType {
return -1
}
@ -51,6 +51,6 @@ func (el *HtmlDocument) Compare(other core.Value) int {
}
}
func (el *HtmlDocument) Url() core.Value {
func (el *HTMLDocument) URL() core.Value {
return el.url
}

View File

@ -9,39 +9,39 @@ import (
"github.com/PuerkitoBio/goquery"
)
type HtmlElement struct {
type HTMLElement struct {
selection *goquery.Selection
attrs *values.Object
children *values.Array
}
func NewHtmlElement(node *goquery.Selection) (*HtmlElement, error) {
func NewHTMLElement(node *goquery.Selection) (*HTMLElement, error) {
if node == nil {
return nil, core.Error(core.ErrMissedArgument, "element selection")
}
return &HtmlElement{node, nil, nil}, nil
return &HTMLElement{node, nil, nil}, nil
}
func (el *HtmlElement) MarshalJSON() ([]byte, error) {
func (el *HTMLElement) MarshalJSON() ([]byte, error) {
return json.Marshal(el.InnerText().String())
}
func (el *HtmlElement) Type() core.Type {
return core.HtmlElementType
func (el *HTMLElement) Type() core.Type {
return core.HTMLElementType
}
func (el *HtmlElement) String() string {
return el.InnerHtml().String()
func (el *HTMLElement) String() string {
return el.InnerHTML().String()
}
func (el *HtmlElement) Compare(other core.Value) int {
func (el *HTMLElement) Compare(other core.Value) int {
switch other.Type() {
case core.HtmlElementType:
case core.HTMLElementType:
// TODO: complete the comparison
return -1
default:
if other.Type() > core.HtmlElementType {
if other.Type() > core.HTMLElementType {
return -1
}
@ -49,11 +49,11 @@ func (el *HtmlElement) Compare(other core.Value) int {
}
}
func (el *HtmlElement) Unwrap() interface{} {
func (el *HTMLElement) Unwrap() interface{} {
return el.selection
}
func (el *HtmlElement) Hash() int {
func (el *HTMLElement) Hash() int {
h := sha512.New()
str, err := el.selection.Html()
@ -71,13 +71,13 @@ func (el *HtmlElement) Hash() int {
return out
}
func (el *HtmlElement) Clone() core.Value {
c, _ := NewHtmlElement(el.selection.Clone())
func (el *HTMLElement) Clone() core.Value {
c, _ := NewHTMLElement(el.selection.Clone())
return c
}
func (el *HtmlElement) NodeType() values.Int {
func (el *HTMLElement) NodeType() values.Int {
nodes := el.selection.Nodes
if len(nodes) == 0 {
@ -87,11 +87,11 @@ func (el *HtmlElement) NodeType() values.Int {
return values.NewInt(common.ToHtmlType(nodes[0].Type))
}
func (el *HtmlElement) NodeName() values.String {
func (el *HTMLElement) NodeName() values.String {
return values.NewString(goquery.NodeName(el.selection))
}
func (el *HtmlElement) Length() values.Int {
func (el *HTMLElement) Length() values.Int {
if el.children == nil {
el.children = el.parseChildren()
}
@ -99,7 +99,7 @@ func (el *HtmlElement) Length() values.Int {
return el.children.Length()
}
func (el *HtmlElement) Value() core.Value {
func (el *HTMLElement) Value() core.Value {
val, ok := el.selection.Attr("value")
if ok {
@ -109,11 +109,11 @@ func (el *HtmlElement) Value() core.Value {
return values.EmptyString
}
func (el *HtmlElement) InnerText() values.String {
func (el *HTMLElement) InnerText() values.String {
return values.NewString(el.selection.Text())
}
func (el *HtmlElement) InnerHtml() values.String {
func (el *HTMLElement) InnerHTML() values.String {
h, err := el.selection.Html()
if err != nil {
@ -123,7 +123,7 @@ func (el *HtmlElement) InnerHtml() values.String {
return values.NewString(h)
}
func (el *HtmlElement) GetAttributes() core.Value {
func (el *HTMLElement) GetAttributes() core.Value {
if el.attrs == nil {
el.attrs = el.parseAttrs()
}
@ -131,7 +131,7 @@ func (el *HtmlElement) GetAttributes() core.Value {
return el.attrs
}
func (el *HtmlElement) GetAttribute(name values.String) core.Value {
func (el *HTMLElement) GetAttribute(name values.String) core.Value {
v, ok := el.selection.Attr(name.String())
if ok {
@ -141,7 +141,7 @@ func (el *HtmlElement) GetAttribute(name values.String) core.Value {
return values.None
}
func (el *HtmlElement) GetChildNodes() core.Value {
func (el *HTMLElement) GetChildNodes() core.Value {
if el.children == nil {
el.children = el.parseChildren()
}
@ -149,7 +149,7 @@ func (el *HtmlElement) GetChildNodes() core.Value {
return el.children
}
func (el *HtmlElement) GetChildNode(idx values.Int) core.Value {
func (el *HTMLElement) GetChildNode(idx values.Int) core.Value {
if el.children == nil {
el.children = el.parseChildren()
}
@ -157,14 +157,14 @@ func (el *HtmlElement) GetChildNode(idx values.Int) core.Value {
return el.children.Get(idx)
}
func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
func (el *HTMLElement) QuerySelector(selector values.String) core.Value {
selection := el.selection.Find(selector.String())
if selection == nil {
return values.None
}
res, err := NewHtmlElement(selection)
res, err := NewHTMLElement(selection)
if err != nil {
return values.None
@ -173,7 +173,7 @@ func (el *HtmlElement) QuerySelector(selector values.String) core.Value {
return res
}
func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value {
func (el *HTMLElement) QuerySelectorAll(selector values.String) core.Value {
selection := el.selection.Find(selector.String())
if selection == nil {
@ -183,7 +183,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value {
arr := values.NewArray(selection.Length())
selection.Each(func(i int, selection *goquery.Selection) {
el, err := NewHtmlElement(selection)
el, err := NewHTMLElement(selection)
if err == nil {
arr.Push(el)
@ -193,7 +193,7 @@ func (el *HtmlElement) QuerySelectorAll(selector values.String) core.Value {
return arr
}
func (el *HtmlElement) parseAttrs() *values.Object {
func (el *HTMLElement) parseAttrs() *values.Object {
obj := values.NewObject()
for _, name := range common.Attributes {
@ -207,7 +207,7 @@ func (el *HtmlElement) parseAttrs() *values.Object {
return obj
}
func (el *HtmlElement) parseChildren() *values.Array {
func (el *HTMLElement) parseChildren() *values.Array {
children := el.selection.Children()
arr := values.NewArray(10)
@ -215,14 +215,14 @@ func (el *HtmlElement) parseChildren() *values.Array {
children.Each(func(i int, selection *goquery.Selection) {
//name := goquery.NodeName(selection)
//if name != "#text" && name != "#comment" {
// child, err := NewHtmlElement(selection)
// child, err := NewHTMLElement(selection)
//
// if err == nil {
// arr.Push(child)
// }
//}
child, err := NewHtmlElement(selection)
child, err := NewHTMLElement(selection)
if err == nil {
arr.Push(child)

View File

@ -12,7 +12,7 @@ import (
* @params text (String) - The string to parse as JSON.
* @returns FQL value (Value)
*/
func JsonParse(_ context.Context, args ...core.Value) (core.Value, error) {
func JSONParse(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)
if err != nil {
@ -35,7 +35,7 @@ func JsonParse(_ context.Context, args ...core.Value) (core.Value, error) {
* @params value (Value) - The input value to serialize.
* @returns json (String)
*/
func JsonStringify(_ context.Context, args ...core.Value) (core.Value, error) {
func JSONStringify(_ context.Context, args ...core.Value) (core.Value, error) {
err := core.ValidateArgs(args, 1, 1)
if err != nil {

View File

@ -74,20 +74,20 @@ func IsObject(_ context.Context, inputs ...core.Value) (core.Value, error) {
return isTypeof(inputs[0], core.ObjectType), nil
}
func IsHtmlElement(_ context.Context, inputs ...core.Value) (core.Value, error) {
func IsHTMLElement(_ context.Context, inputs ...core.Value) (core.Value, error) {
if len(inputs) == 0 {
return values.None, core.ErrMissedArgument
}
return isTypeof(inputs[0], core.HtmlElementType), nil
return isTypeof(inputs[0], core.HTMLElementType), nil
}
func IsHtmlDocument(_ context.Context, inputs ...core.Value) (core.Value, error) {
func IsHTMLDocument(_ context.Context, inputs ...core.Value) (core.Value, error) {
if len(inputs) == 0 {
return values.None, core.ErrMissedArgument
}
return isTypeof(inputs[0], core.HtmlDocumentType), nil
return isTypeof(inputs[0], core.HTMLDocumentType), nil
}
func IsBinary(_ context.Context, inputs ...core.Value) (core.Value, error) {