htmldoc

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 21, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package htmldoc : Provides local document interface for htmltest. Models a store of documents, individual documents and their internal and external references.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttrPresent added in v0.1.1

func AttrPresent(attrs []html.Attribute, key string) bool

AttrPresent : Is key present within attrs?

func ExtractAttrs added in v0.1.1

func ExtractAttrs(attrs []html.Attribute, keys []string) map[string]string

ExtractAttrs : From attrs extract the asked for keys

func GetAttr added in v0.2.0

func GetAttr(attrs []html.Attribute, key string) string

GetAttr : From attrs extract single attr

func GetID added in v0.3.0

func GetID(attrs []html.Attribute) string

GetID : Get hash/fragment id from node.Attrs

func URLStripQueryString

func URLStripQueryString(urlStr string) string

URLStripQueryString : Utility function to remove query string from given urlStr.

Types

type Document

type Document struct {
	FilePath string // Relative to the shell session
	SitePath string // Relative to the site root
	BasePath string // Base for relative links

	NodesOfInterest []*html.Node  // Slice of nodes to run checks on
	State           DocumentState // Link to a DocumentState struct
	DoctypeNode     *html.Node    // Pointer to doctype node if exists
	// contains filtered or unexported fields
}

Document struct, representation of a document within the tested site

func (*Document) Init added in v0.1.1

func (doc *Document) Init()

Init : Initialise the Document struct doesn't mesh nice with the NewXYZ() convention but many optional parameters for Document and no parameter overloading in Go

func (*Document) IsHashValid added in v0.1.1

func (doc *Document) IsHashValid(hash string) bool

IsHashValid : Is a hash/fragment present in this Document.

func (*Document) Parse

func (doc *Document) Parse()

Parse : Ask Document to parse its HTML file. Returns quickly if this has already been done. Thread safe. Either called when the document is tested or when another document needs data from this one.

type DocumentState

type DocumentState struct {
	FaviconPresent bool // Have we found a favicon in the document?
}

DocumentState struct, used by checks that depend on the document being parsed.

type DocumentStore added in v0.1.1

type DocumentStore struct {
	BasePath          string               // Path, relative to cwd, the site is located in
	IgnorePatterns    []interface{}        // Regexes of directories to ignore
	Documents         []*Document          // All of the documents, used to iterate over
	DocumentPathMap   map[string]*Document // Maps slash separated paths to documents
	DocumentExtension string               // File extension to look for
	DirectoryIndex    string               // What file is the index of the directory
}

DocumentStore struct, store of Documents including Document discovery

func NewDocumentStore added in v0.1.1

func NewDocumentStore() DocumentStore

NewDocumentStore : Create and return a new Document store.

func (*DocumentStore) AddDocument added in v0.1.1

func (dS *DocumentStore) AddDocument(doc *Document)

AddDocument : Add a document to the document store.

func (*DocumentStore) Discover added in v0.1.1

func (dS *DocumentStore) Discover()

Discover : Discover all documents within DocumentStore.BasePath.

func (*DocumentStore) ResolvePath added in v0.1.1

func (dS *DocumentStore) ResolvePath(refPath string) (*Document, bool)

ResolvePath : Resolves internal absolute paths to documents.

func (*DocumentStore) ResolveRef added in v0.1.1

func (dS *DocumentStore) ResolveRef(ref *Reference) (*Document, bool)

ResolveRef : Proxy to ResolvePath via ref.RefSitePath()

type Reference

type Reference struct {
	Document *Document  // Document node is in
	Node     *html.Node // Node reference was created from
	Path     string     // href/src taken verbatim from source
	URL      *url.URL   // URL object created from Path
}

Reference struct, representation of the link between a document and a resource.

func NewReference

func NewReference(document *Document, node *html.Node, path string) *Reference

NewReference : Create a new reference given a document, node and path. Generates the URL object.

func (*Reference) IsInternalAbsolute

func (ref *Reference) IsInternalAbsolute() bool

IsInternalAbsolute : Is an internal absolute link.

func (*Reference) RefSitePath added in v0.1.1

func (ref *Reference) RefSitePath() string

RefSitePath : For internals, return a path to the referenced file relative to the 'site root'.

func (*Reference) Scheme

func (ref *Reference) Scheme() string

Scheme : Returns the scheme of the reference. Uses URL.Scheme and adds "file" and "self" schemes for inter-file and intra-file references.

func (*Reference) URLString

func (ref *Reference) URLString() string

URLString : Proxy for URL.String but deals with other valid URL types, such as missing protocol URLs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL