transpile

package
v4.6.2 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: BSD-3-Clause, MIT, OFL-1.1 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Markdown

func Markdown(input io.Reader, output io.Writer) error

Markdown formats the provided bytes using whatever Markdown engine we're currently using.

func Mothball

func Mothball(c Category, w io.Writer) error

Mothball packages a Category up for a production server run.

Types

type AnswerResponse

type AnswerResponse struct {
	Correct bool
}

AnswerResponse is handed back when we ask for an answer to be checked.

type Category

type Category interface {
	// Inventory lists every puzzle in the category.
	Inventory() ([]int, error)

	// Puzzle provides a Puzzle structure for the given point value.
	Puzzle(points int) (Puzzle, error)

	// Open returns an io.ReadCloser for the given filename.
	Open(points int, filename string) (ReadSeekCloser, error)

	// Answer returns whether the given answer is correct.
	Answer(points int, answer string) bool
}

Category defines the functionality required to be a puzzle category.

func NewFsCategory

func NewFsCategory(fs afero.Fs, cat string) Category

NewFsCategory returns a Category based on which files are present. If 'mkcategory' is present and executable, an FsCommandCategory is returned. Otherwise, FsCategory is returned.

type FsCategory

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

FsCategory provides a category backed by a .md file.

func (FsCategory) Answer

func (c FsCategory) Answer(points int, answer string) bool

Answer checks whether an answer is correct.

func (FsCategory) Inventory

func (c FsCategory) Inventory() ([]int, error)

Inventory returns a list of point values for this category.

func (FsCategory) Open

func (c FsCategory) Open(points int, filename string) (ReadSeekCloser, error)

Open returns an io.ReadCloser for the given filename.

func (FsCategory) Puzzle

func (c FsCategory) Puzzle(points int) (Puzzle, error)

Puzzle returns a Puzzle structure for the given point value.

type FsCommandCategory

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

FsCommandCategory provides a category backed by running an external command.

func (FsCommandCategory) Answer

func (c FsCommandCategory) Answer(points int, answer string) bool

Answer checks whether an answer is correct.

func (FsCommandCategory) Inventory

func (c FsCommandCategory) Inventory() ([]int, error)

Inventory returns a list of point values for this category.

func (FsCommandCategory) Open

func (c FsCommandCategory) Open(points int, filename string) (ReadSeekCloser, error)

Open returns an io.ReadCloser for the given filename.

func (FsCommandCategory) Puzzle

func (c FsCommandCategory) Puzzle(points int) (Puzzle, error)

Puzzle returns a Puzzle structure for the given point value.

type FsCommandPuzzle

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

FsCommandPuzzle provides an FsPuzzle backed by running a command.

func (FsCommandPuzzle) Answer

func (fp FsCommandPuzzle) Answer(answer string) bool

Answer checks whether the given answer is correct.

func (FsCommandPuzzle) Open

func (fp FsCommandPuzzle) Open(filename string) (ReadSeekCloser, error)

Open returns a newly-opened file. BUG(neale): FsCommandPuzzle.Open() reads everything into memory, and will suck for large files.

func (FsCommandPuzzle) Puzzle

func (fp FsCommandPuzzle) Puzzle() (Puzzle, error)

Puzzle returns a Puzzle struct for the current puzzle.

type FsPuzzle

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

FsPuzzle is a single puzzle's directory.

func (FsPuzzle) Answer

func (fp FsPuzzle) Answer(answer string) bool

Answer checks whether the given answer is correct.

func (FsPuzzle) Open

func (fp FsPuzzle) Open(name string) (ReadSeekCloser, error)

Open returns a newly-opened file.

func (FsPuzzle) Puzzle

func (fp FsPuzzle) Puzzle() (Puzzle, error)

Puzzle returns a Puzzle struct for the current puzzle.

type Inventory

type Inventory map[string][]int

Inventory maps category names to lists of point values.

func FsInventory

func FsInventory(fs afero.Fs) (Inventory, error)

FsInventory returns a mapping of category names to puzzle point values.

type InventoryResponse

type InventoryResponse struct {
	Puzzles []int
}

InventoryResponse is what's handed back when we ask for an inventory.

type NopReadCloser

type NopReadCloser struct {
}

NopReadCloser provides an io.ReadCloser which does nothing.

func (NopReadCloser) Close

func (n NopReadCloser) Close() error

Close satisfies io.Closer.

func (NopReadCloser) Read

func (n NopReadCloser) Read(b []byte) (int, error)

Read satisfies io.Reader.

type Puzzle

type Puzzle struct {
	// Debug contains debugging information, omitted in mothballs
	Debug PuzzleDebug

	// Authors names all authors of this puzzle
	Authors []string

	// Attachments is a list of filenames used by this puzzle
	Attachments []string

	// Scripts is a list of EMCAScript files needed by the client for this puzzle
	Scripts []string

	// Body is the HTML rendering of this puzzle
	Body string

	// AnswerPattern contains the pattern (regular expression?) used to match valid answers
	AnswerPattern string

	// AnswerHashes contains hashes of all answers for this puzzle
	AnswerHashes []string

	// Answers lists all acceptable answers, omitted in mothballs
	Answers []string

	// Extra is send unchanged to the client.
	// Eventually, Objective, KSAs, and Success will move into Extra.
	Extra map[string]any

	// Objective is the learning objective for this puzzle
	Objective string

	// KSAs lists all KSAs achieved upon successfull completion of this puzzle
	KSAs []string

	// Success lists the criteria for successfully understanding this puzzle
	Success struct {
		// Acceptable describes the minimum work required to be considered successfully understanding this puzzle's concepts
		Acceptable string

		// Mastery describes the work required to be considered mastering this puzzle's conceptss
		Mastery string
	}
}

Puzzle contains everything about a puzzle that a client will see.

type PuzzleDebug

type PuzzleDebug struct {
	Log     []string
	Errors  []string
	Hints   []string
	Notes   string
	Summary string
}

type PuzzleProvider

type PuzzleProvider interface {
	// Puzzle returns a Puzzle struct for the current puzzle.
	Puzzle() (Puzzle, error)

	// Open returns a newly-opened file.
	Open(filename string) (ReadSeekCloser, error)

	// Answer returns whether the provided answer is correct.
	Answer(answer string) bool
}

PuzzleProvider establishes the functionality required to provide one puzzle.

func NewFsPuzzle

func NewFsPuzzle(fs afero.Fs) PuzzleProvider

NewFsPuzzle returns a new FsPuzzle.

func NewFsPuzzlePoints

func NewFsPuzzlePoints(fs afero.Fs, points int) PuzzleProvider

NewFsPuzzlePoints returns a new FsPuzzle for points.

type ReadSeekCloser

type ReadSeekCloser interface {
	io.Reader
	io.Seeker
	io.Closer
}

ReadSeekCloser provides io.Reader, io.Seeker, and io.Closer.

type RecursiveBasePathFs

type RecursiveBasePathFs struct {
	afero.Fs
	// contains filtered or unexported fields
}

RecursiveBasePathFs is an overloaded afero.BasePathFs that has a recursive RealPath().

func NewRecursiveBasePathFs

func NewRecursiveBasePathFs(source afero.Fs, path string) *RecursiveBasePathFs

NewRecursiveBasePathFs returns a new RecursiveBasePathFs.

func (*RecursiveBasePathFs) RealPath

func (b *RecursiveBasePathFs) RealPath(name string) (path string, err error)

RealPath returns the real path to a file, "breaking out" of the RecursiveBasePathFs.

type StaticAttachment

type StaticAttachment struct {
	Filename       string // Filename presented as part of puzzle
	FilesystemPath string // Filename in backing FS (URL, mothball, or local FS)
}

StaticAttachment carries information about an attached file.

func (*StaticAttachment) UnmarshalYAML

func (sa *StaticAttachment) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML allows a StaticAttachment to be specified as a single string. The way the yaml library works is weird.

type StaticPuzzle

type StaticPuzzle struct {
	Authors       []string
	Attachments   []StaticAttachment
	Scripts       []StaticAttachment
	AnswerPattern string
	Answers       []string
	Debug         PuzzleDebug
	Extra         map[string]any
	Objective     string
	Success       struct {
		Acceptable string
		Mastery    string
	}
	KSAs []string
}

StaticPuzzle contains everything a static puzzle might tell us.

Notes

Bugs

  • FsCategory.Answer should probably always return false, to prevent you from running uncompiled puzzles with participants.

  • FsCommandPuzzle.Open() reads everything into memory, and will suck for large files.

Jump to

Keyboard shortcuts

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