parser

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package parser implements types and methods to parse markdown files in a filesystem to HTML to a destination filesystem that can be used to serve needforheat manuals.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotSourceFS = errors.New("parser: type does not implement SourceFS interface")
)
View Source
var (
	ErrTemplateNotFound = errors.New("template file could not be found")
)

Functions

func GetDestinationDirPath

func GetDestinationDirPath(source fs.FS, dirPath string) (string, error)

Get the path to copy a directory to at the destination filesystem. Use dirPath at sourceFS to determine the path the directory should be copied to at the destination filesystem.

An error will be returned if source is not a SourceFS.

func GetDestinationFilePath

func GetDestinationFilePath(source fs.FS, filePath string) (string, error)

Get the path to copy a file to at the destination filesystem. Use filePath at sourceFS to determine the path the file should be copied to at the destination filesystem.

An error will be returned if source is not a SourceFS.

func NewDeviceRepoSource

func NewDeviceRepoSource(url string, auth transport.AuthMethod) (fs.FS, error)

Create a new source filesystem from a directory at path.

func NewLabDirSource

func NewLabDirSource(path string) (fs.FS, error)

Create a new source filesystem from a directory at path.

func NewLabRepoSource

func NewLabRepoSource(url string, branch string, auth transport.AuthMethod) (fs.FS, error)

Create a new source filesystem from a directory at path.

Types

type DeviceRepoSource

type DeviceRepoSource struct {
	fs.FS
	// contains filtered or unexported fields
}

DeviceRepoSource is a git repo that contains manuals made by developers of a device.

func (DeviceRepoSource) GetDestinationDirPath

func (repo DeviceRepoSource) GetDestinationDirPath(dirPath string) string

Get the path to copy a directory to at the destination filesystem. Use dirPath at sourceFS to determine the path the directory should be copied to at the destination filesystem.

func (DeviceRepoSource) GetDestinationFilePath

func (repo DeviceRepoSource) GetDestinationFilePath(filePath string) string

Get the path to copy a file to at the destination filesystem. Use filePath at sourceFS to determine the path the file should be copied to at the destination filesystem.

type HTMLTemplate

type HTMLTemplate struct {
	Language string
	Title    string
	Body     template.HTML
}

HTMLTemplate contains data for filling a template.html.

type LabDirSource

type LabDirSource struct {
	fs.FS
}

LabDirSource is a local directory that contains manuals made by a lab.

func (LabDirSource) GetDestinationDirPath

func (dir LabDirSource) GetDestinationDirPath(dirPath string) string

Get the path to copy a directory to at the destination filesystem. Use dirPath at sourceFS to determine the path the directory should be copied to at the destination filesystem.

func (LabDirSource) GetDestinationFilePath

func (dir LabDirSource) GetDestinationFilePath(filePath string) string

Get the path to copy a file to at the destination filesystem. Use filePath at sourceFS to determine the path the file should be copied to at the destination filesystem.

type LabRepoSource

type LabRepoSource struct {
	fs.FS
}

LabRepoSource is a git repo that contains manuals made by a lab.

func (LabRepoSource) GetDestinationDirPath

func (repo LabRepoSource) GetDestinationDirPath(dirPath string) string

Get the path to copy a directory to at the destination filesystem. Use dirPath at sourceFS to determine the path the directory should be copied to at the destination filesystem.

func (LabRepoSource) GetDestinationFilePath

func (repo LabRepoSource) GetDestinationFilePath(filePath string) string

Get the path to copy a file to at the destination filesystem. Use filePath at sourceFS to determine the path the file should be copied to at the destination filesystem.

type ManualCategory

type ManualCategory string

ManualCategory is the type of manual.

const (
	ManualCategoryUnknown  ManualCategory = "unknown"
	ManualCategoryDevice   ManualCategory = "devices"
	ManualCategoryCampaign ManualCategory = "campaigns"
)

type Parser

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

A Parser can parse manuals written in markdown to html files.

Following the folder structure specification, the parser will parse all markdown files to HTML while checking languages and creating a structure that can be served by a [Server].

func New

func New(destFS fs.FS) *Parser

Create a new Parser that uses sourceFS as its filesystem to parse manuals.

func (*Parser) Parse

func (p *Parser) Parse(sourceFS fs.FS) error

Parse files following the folder structure specification to a filesystem that a [Server] can use to serve HTML.

destFS has to be a writable filessytem.

type SourceFS

type SourceFS interface {
	// Get the path to copy a file to at the destination filesystem.
	// Use filePath at sourceFS to determine the path the file should be copied to at the destination filesystem.
	GetDestinationFilePath(filePath string) string

	// Get the path to copy a directory to at the destination filesystem.
	// Use dirPath at sourceFS to determine the path the directory should be copied to at the destination filesystem.
	GetDestinationDirPath(dirPath string) string
}

Source is an interface for a filesystem that can be used as a source for a Parser.

Jump to

Keyboard shortcuts

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