1
0
mirror of https://github.com/MontFerret/ferret.git synced 2025-06-23 00:28:10 +02:00

New type system (#232)

* New type system

* Fixed dot notation for HTML elements
This commit is contained in:
Tim Voronov
2019-02-13 12:31:18 -05:00
committed by GitHub
parent b3bcbda3b9
commit 1af8b37a0f
185 changed files with 1379 additions and 820 deletions

View File

@ -2,9 +2,11 @@ package html
import (
"context"
"github.com/MontFerret/ferret/pkg/runtime/collections"
"github.com/MontFerret/ferret/pkg/runtime/core"
"github.com/MontFerret/ferret/pkg/runtime/values"
"github.com/MontFerret/ferret/pkg/runtime/values/types"
)
// Pagination creates an iterator that goes through pages using CSS selector.
@ -25,7 +27,7 @@ func Pagination(_ context.Context, args ...core.Value) (core.Value, error) {
return values.False, core.Errors(core.ErrInvalidType, ErrNotDynamic)
}
err = core.ValidateType(args[1], core.StringType)
err = core.ValidateType(args[1], types.String)
if err != nil {
return values.None, err
@ -36,6 +38,8 @@ func Pagination(_ context.Context, args ...core.Value) (core.Value, error) {
return &Paging{doc, selector}, nil
}
var PagingType = core.NewType("Paging")
type (
Paging struct {
document values.DHTMLDocument
@ -54,14 +58,14 @@ func (p *Paging) MarshalJSON() ([]byte, error) {
}
func (p *Paging) Type() core.Type {
return core.CustomType
return PagingType
}
func (p *Paging) String() string {
return core.CustomType.String()
return PagingType.String()
}
func (p *Paging) Compare(_ core.Value) int {
func (p *Paging) Compare(_ core.Value) int64 {
return 1
}