Documentation
¶
Index ¶
- Constants
- func DownloadsDir() (string, error)
- func FormatMins(minutes int) string
- func RenderRecipe(r *models.Recipe, opts Options, ren Renderer) ([]byte, error)
- func SafeFilename(name string) string
- func TagContextLabel(ctx string) string
- func ToMarkdown(r *models.Recipe, opts Options) string
- func ToPDF(r *models.Recipe, opts Options) ([]byte, error)
- func ToRTF(r *models.Recipe, opts Options) string
- func ToText(r *models.Recipe, opts Options) string
- func UniqueFilePath(dir, base, ext string) string
- func WriteArchive(w io.Writer, recipes []*models.Recipe, format string) (int, error)
- type Archive
- type Options
- type Renderer
Constants ¶
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 ¶
DownloadsDir returns ~/Downloads, creating it if needed.
func FormatMins ¶
FormatMins formats a minute count as a human-readable duration string.
func RenderRecipe ¶
RenderRecipe traverses r in document order, dispatching to ren at each section, then returns ren.Result().
func SafeFilename ¶
SafeFilename returns a URL-safe slug from a recipe name (no extension).
func TagContextLabel ¶
TagContextLabel returns a human-readable label for a tag context.
func ToMarkdown ¶
ToMarkdown renders a recipe as a Markdown document.
func UniqueFilePath ¶
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 ¶
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)
// 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.