lib

package
v0.1.1-0...-c2b0454 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

This package provides functions to download content from the https://lds.org and lookup scriptures, magazines, General Conference talks, and much more from the downloaded content. It exports a variety of functions to access all the content.

Index

Constants

View Source
const RootPath = "/"

Variables

View Source
var DataDirectory = ".ldss"
View Source
var ErrNotFound error

Functions

func DlAndOpen

func DlAndOpen(item Item) error

func Open

func Open() error

func Register

func Register(name string, src Source)
func Search(item Item, keywords []string, c chan<- SearchResult)

func SetReferenceParseReader

func SetReferenceParseReader(open QueryFileFunc)

Sets a function that will be called to get the ldss reference language file for a passed language. This will likely be from a file, but could be from another source, such as an embedded resource. This should not be set after the first call to Lookup()

Types

type Closer

type Closer interface {
	Close() error
}

type Content

type Content string

Content pulled from a node in the SQlite database. Is the content of the node formatted as HTML

func (Content) Filter

func (content Content) Filter(verses []int) Content

func (Content) Highlight

func (content Content) Highlight(verses []int, class string) Content
func (content Content) Links(l Lang) []Reference

func (Content) Parse

func (c Content) Parse() *ContentParser

func (Content) Search

func (content Content) Search(keywords []string) SearchResult

Search the content for the given keywords and return a search result containing the verses in which the results were found and the a weighted score based on the number of occurrences.

TODO Give extra points to sequences of words in the correct order (ignoring punctuation)

type ContentParser

type ContentParser struct {
	// contains filtered or unexported fields
}

func (*ContentParser) NextParagraph

func (c *ContentParser) NextParagraph() bool

func (*ContentParser) NextText

func (c *ContentParser) NextText() bool

func (*ContentParser) ParagraphStyle

func (c *ContentParser) ParagraphStyle() ParagraphStyle

func (*ContentParser) ParagraphVerse

func (c *ContentParser) ParagraphVerse() int

func (*ContentParser) Text

func (c *ContentParser) Text() string

func (*ContentParser) TextStyle

func (c *ContentParser) TextStyle() TextStyle

type Contenter

type Contenter interface {
	Content() Content
	Subtitle() string
	SectionName() string
	Footnotes(verses []int) []Footnote
}

type Footnote

type Footnote struct {
	Item     Item
	Name     string        `json:"name"`
	LinkName string        `json:"linkName"`
	Content  template.HTML `json:"content"`
}

func (*Footnote) References

func (f *Footnote) References() []Reference

type Item

type Item interface {
	Name() string
	Children() []Item
	Path() string
	Lang() Lang
	Parent() Item
	Next() Item
	Prev() Item
}

func AutoDownload

func AutoDownload(open func() (Item, error)) (Item, error)

Calls the open function and downloads any missing content if has not been downloaded yet. If it does download something, it will retry the open function repeatedly until it gets no download errors (or repeated ones). It provides information about these downloads and the final result through a series of messages from the returned channel.

func GenericNextPrevious

func GenericNextPrevious(item Item, direction int) Item

Gets the next or previous sibling of an item using it's interface functions. Used to implement Next and Previous on the Item interface. Only pass -1 or 1 to direction.

type Lang

type Lang interface {
	Name() string
	EnglishName() string
	Code() string
	Matches(string) bool
}

func Languages

func Languages() []Lang

func LookupLanguage

func LookupLanguage(id string) Lang

LookupLanguage finds a language by any of the accepted methods, compares ID, Code, and InternalCode

type Opener

type Opener interface {
	Open() error
}

type ParagraphStyle

type ParagraphStyle int
const (
	ParagraphStyleNormal ParagraphStyle = iota
	ParagraphStyleTitle
	ParagraphStyleChapter
	ParagraphStyleSummary
)

func (ParagraphStyle) String

func (p ParagraphStyle) String() string

type QueryFileFunc

type QueryFileFunc func(lang Lang) ([]byte, error)

type Reference

type Reference struct {
	Path              string
	Lang              Lang
	VerseSelected     int
	VersesHighlighted []int
	VersesExtra       []int
	Small, Name       string
	Keywords          []string
}

func Parse

func Parse(lang Lang, q string) []Reference

func ParsePath

func ParsePath(lang Lang, p string) Reference

func (Reference) Check

func (r Reference) Check() error

func (*Reference) Clean

func (r *Reference) Clean()

func (Reference) Lookup

func (r Reference) Lookup() (Item, error)

Lookup finds an Item by it's path. Expects a fully qualified path. "/" will return the catalog. Will return an error if there is an error loading the item or it is not downloaded.

func (Reference) MarshalJSON

func (r Reference) MarshalJSON() ([]byte, error)

func (Reference) String

func (r Reference) String() string

func (Reference) URL

func (r Reference) URL() string

type SearchResult

type SearchResult struct {
	Reference
	Weight int
}

type SearchResults

type SearchResults []SearchResult

func SearchSort

func SearchSort(item Item, keywords []string) SearchResults

func (SearchResults) Len

func (r SearchResults) Len() int

func (SearchResults) Less

func (r SearchResults) Less(i, j int) bool

func (SearchResults) Swap

func (r SearchResults) Swap(i, j int)

type Source

type Source interface {
	dl.Downloader
	Langs() []Lang

	Lookup(lang Lang, path string) (Item, error)
}

type TextStyle

type TextStyle int
const (
	TextStyleNormal TextStyle = iota
	TextStyleLink
	TextStyleFootnote
)

func (TextStyle) String

func (t TextStyle) String() string

Directories

Path Synopsis
sources

Jump to

Keyboard shortcuts

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