export

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const ArchiveSchema = 1

ArchiveSchema is the version of the JSON archive envelope. Bump it if the on-disk shape changes in a way a future importer needs to distinguish.

Variables

This section is empty.

Functions

func DownloadsDir

func DownloadsDir() (string, error)

DownloadsDir returns ~/Downloads, creating it if needed.

func FormatMins

func FormatMins(minutes int) string

FormatMins formats a minute count as a human-readable duration string.

func RenderRecipe

func RenderRecipe(r *models.Recipe, opts Options, ren Renderer) ([]byte, error)

RenderRecipe traverses r in document order, dispatching to ren at each section, then returns ren.Result().

func SafeFilename

func SafeFilename(name string) string

SafeFilename returns a URL-safe slug from a recipe name (no extension).

func TagContextLabel

func TagContextLabel(ctx string) string

TagContextLabel returns a human-readable label for a tag context.

func ToMarkdown

func ToMarkdown(r *models.Recipe, opts Options) string

ToMarkdown renders a recipe as a Markdown document.

func ToPDF

func ToPDF(r *models.Recipe, opts Options) ([]byte, error)

ToPDF renders a recipe as a PDF document (Letter size).

func ToRTF

func ToRTF(r *models.Recipe, opts Options) string

ToRTF renders a recipe as an RTF 1.x document (cp1252 encoding).

func ToText

func ToText(r *models.Recipe, opts Options) string

ToText renders a recipe as plain text.

func UniqueFilePath

func UniqueFilePath(dir, base, ext string) string

UniqueFilePath returns a path in dir for base.ext that does not already exist. If base.ext is taken it tries base-2.ext, base-3.ext, and so on.

func WriteArchive

func WriteArchive(w io.Writer, recipes []*models.Recipe, format string) (int, error)

WriteArchive serialises fully-hydrated recipes to w in the given format ("json" or "text") and returns the number of recipes written.

Callers are responsible for loading each recipe with its ingredients and tags (e.g. via db.GetRecipe) before passing them in — this keeps the export package free of any database dependency.

Types

type Archive

type Archive struct {
	Schema     int              `json:"schema"`
	AppVersion string           `json:"app_version"`
	ExportedAt time.Time        `json:"exported_at"`
	Count      int              `json:"recipe_count"`
	Recipes    []*models.Recipe `json:"recipes"`
}

Archive is the top-level JSON envelope written by WriteArchive for the "json" format. It wraps the fully-hydrated recipes with enough metadata for a future `enplace import` to validate and round-trip them.

type Options

type Options struct {
	// Credits is displayed left-aligned in the export footer alongside the
	// version attribution. Use it to claim recipe authorship.
	Credits string
}

Options configures per-export behaviour. Pass a zero value for defaults.

type Renderer

type Renderer interface {
	// Title is called first with the recipe name.
	Title(name string)

	// Meta is called when at least one timing/servings field is present.
	// timingSummary is the pre-formatted "Prep X · Cook X" string (empty if
	// neither timing field is set). prepMins and cookMins may be nil.
	Meta(timingSummary string, prepMins, cookMins, servings *int, servingUnits string)

	// Hydration is called for bread/dough recipes immediately after Meta.
	// pct is the computed hydration percentage (e.g. 65.0 for 65%).
	// totalGrams is the total dough weight (wet + dry, rounded to the nearest gram).
	// starterAssumed is true when one or more starter ingredients were present
	// and counted as 100% hydration (50% flour / 50% water).
	Hydration(pct float64, totalGrams int, starterAssumed bool)

	// TagLine is called once per non-empty tag context.
	TagLine(ctxLabel, joined string)

	// Description is called when the recipe has a description.
	Description(text string)

	// IngredientsHeader is called before the first ingredient.
	IngredientsHeader()

	// IngredientSection is called when a new non-empty section header begins.
	IngredientSection(section string)

	// Ingredient is called for each ingredient row.
	Ingredient(display string)

	// DirectionsHeader is called before the directions text.
	DirectionsHeader()

	// Directions is called when the recipe has directions.
	Directions(text string)

	// SourceURL is called when the recipe has a source URL.
	SourceURL(url string)

	// Rating is called when the recipe has a non-nil rating value (1–5).
	// Called after Meta/Hydration and before Description.
	Rating(rating int)

	// BreadMetricsTable is called for bread/dough recipes just before the
	// footer, with the full baker's-percentage breakdown. starterAssumed is
	// true when at least one starter ingredient was present and counted as
	// 100% hydration (50% flour / 50% water).
	BreadMetricsTable(perIngredient []scaling.IngredientBakerPct, hydrationPct float64, starterAssumed bool)

	// Footer is called last with the credits string (may be empty) and the
	// application version attribution string.
	Footer(credits, versionStr string)

	// Result returns the final rendered output.
	Result() ([]byte, error)
}

Renderer is implemented by each export format. RenderRecipe calls its methods in document order and then calls Result to obtain the output.

Jump to

Keyboard shortcuts

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