presets

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 5 Imported by: 0

README

presets

import "github.com/lucasassuncao/yedit/presets"

Package presets defines the Source interface for per-field YAML presets and provides a filesystem-backed implementation.

Clients can either implement Source directly (e.g. as a thin adapter over an existing preset registry) or pass an fs.FS to FromFS to get a default implementation that loads presets from a YAML tree.

Index

type Source

Source supplies YAML preset snippets keyed by (field, preset name). The editor uses it to populate the preset picker and to seed the YAML editor when a block is opened.

type Source interface {
    // ListFields returns the field names that have at least one preset.
    ListFields() []string

    // ListPresets returns the preset names available for the given field,
    // or an empty slice if the field has no presets.
    ListPresets(field string) []string

    // PresetYAML returns the YAML snippet for (field, name) or an error if
    // either is unknown.
    PresetYAML(field, name string) (string, error)
}

func FromFS
func FromFS(fsys fs.FS, root string) Source

FromFS returns a Source backed by an fs.FS rooted at root (use "." for the whole filesystem).

Layout convention:

<root>/<field>/<preset>.yaml

ListFields enumerates the directories under root; ListPresets enumerates the .yaml files within each field directory (stripping the extension).

FromFS is convenient for clients that ship presets as a Go embed.FS.

Generated by gomarkdoc

Documentation

Overview

Package presets defines the Source interface for per-field YAML presets and provides a filesystem-backed implementation.

Clients can either implement Source directly (e.g. as a thin adapter over an existing preset registry) or pass an fs.FS to FromFS to get a default implementation that loads presets from a YAML tree.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Source

type Source interface {
	// ListFields returns the field names that have at least one preset.
	ListFields() []string

	// ListPresets returns the preset names available for the given field,
	// or an empty slice if the field has no presets.
	ListPresets(field string) []string

	// PresetYAML returns the YAML snippet for (field, name) or an error if
	// either is unknown.
	PresetYAML(field, name string) (string, error)
}

Source supplies YAML preset snippets keyed by (field, preset name). The editor uses it to populate the preset picker and to seed the YAML editor when a block is opened.

func FromFS

func FromFS(fsys fs.FS, root string) Source

FromFS returns a Source backed by an fs.FS rooted at root (use "." for the whole filesystem).

Layout convention:

<root>/<field>/<preset>.yaml

ListFields enumerates the directories under root; ListPresets enumerates the .yaml files within each field directory (stripping the extension).

FromFS is convenient for clients that ship presets as a Go embed.FS.

Jump to

Keyboard shortcuts

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