Documentation
¶
Index ¶
- Constants
- func ElementToHTML(out io.Writer, cssBaseClass string, elem *Element) error
- func FmtHelp(src string, appName string, version string, releaseDate string, ...) string
- func ModelToHTML(out io.Writer, model *Model) error
- func ModelToSQLiteScheme(out io.Writer, model *Model) error
- type Element
- type Model
- func (model *Model) Check(buf io.Writer) bool
- func (m *Model) GetAttributeIds() []string
- func (m *Model) GetElementById(id string) (*Element, bool)
- func (m *Model) GetElementIds() []string
- func (m *Model) GetModelIdentifier() (*Element, bool)
- func (model *Model) HasChanges() bool
- func (model *Model) HasElement(elementId string) bool
- func (model *Model) HasElementType(elementType string) bool
- func (model *Model) InsertElement(pos int, element *Element) error
- func (model *Model) Register(name string, fn RenderFunc)
- func (model *Model) RemoveElement(elementId string) error
- func (model *Model) Render(out io.Writer, name string) error
- func (model *Model) ToHTML(out io.Writer) error
- func (model *Model) ToSQLiteScheme(out io.Writer) error
- func (model *Model) UpdateElement(elementId string, element *Element) error
- type RenderFunc
Constants ¶
const ( // Version number of release Version = "0.0.1" // ReleaseDate, the date version.go was generated ReleaseDate = "2024-09-20" // ReleaseHash, the Git hash when version.go was generated ReleaseHash = "17df42c" LicenseText = `` /* 1524-byte string literal not displayed */ )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Element ¶
type Element struct {
// Type, The type of element that you want to input. It is required. Valid values are
// checkboxes, dropdown, input, markdown and text area.
//
// The input type corresponds to the native input types defined for HTML 5. E.g. text, textarea,
// email, phone, date, url, checkbox, radio, button, submit, cancel, select
// See MDN developer docs for input, <https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input>
Type string `json:"type,required" yaml:"type,omitempty"`
// Id for the element, except when type is set to markdown. Can only use alpha-numeric characters,
// -, and _. Must be unique in the form definition. If provided, the id is the canonical identifier
// for the field in URL query parameter prefills.
Id string `json:"id,omitempty" yaml:"id,omitempty"`
// Attributes, a set of key-value pairs that define the properties of the element.
// This is a required element as it holds the "value" attribute when expressing
// HTML content. Other commonly use attributes
Attributes map[string]string `json:"attributes,omitempty" yaml:"attributes,omitempty"`
// Pattern holds a validation pattern. When combined with an input type (or input type alias, e.g. orcid)
// produces a form element that sports a specific client side validation exceptation. This intern can be used
// to generate appropriate validation code server side.
Pattern string `json:"pattern,omitempty" yaml:"pattern,omitempty"`
// Options holds a list of values and their labels used for HTML select elements in rendering their option child elements
Options []map[string]string `json:"optoins,omitempty" yaml:"options,omitempty"`
// IsObjectId (i.e. is the identifier of the object) used by for the modeled data.
// It is used in calculating routes and templates where the object identifier is required.
IsObjectId bool `json:"is_primary_id,omitempty" yaml:"is_primary_id,omitempty"`
// Label is used when rendering an HTML form as a label element tied to the input element via the set attribute and
// the element's id.
Label string `json:"label,omitempty" yaml:"label,omitempty"`
// contains filtered or unexported fields
}
Element implementes the GitHub YAML issue template syntax for an input element. The input element YAML is described at <https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema>
While the syntax most closely express how to setup an HTML representation it is equally suitable to expressing, through inference, SQL column type definitions. E.g. a bare `input` type is a `varchar`, a `textarea` is a `text` column type, an `input[type=date]` is a date column type.
func NewElement ¶
NewElement, makes sure element id is valid, populates an element as a basic input type. The new element has the attribute "name" and label set to default values.
type Model ¶
type Model struct {
// Id is a required field for model, it maps to the HTML element id and name
Id string `json:"id,required" yaml:"id"`
// This is a Newt specifc set of attributes to place in the form element of HTML. I.e. it could
// be form "class", "method", "action", "encoding". It is not defined in the GitHub YAML issue template syntax
// (optional)
Attributes map[string]string `json:"attributes,omitempty" yaml:"attributes,omitempty"`
// Description, A description for the issue form template, which appears in the template chooser interface.
// (required)
Description string `json:"description,required" yaml:"description,omitempty"`
// Elements, Definition of the input types in the form.
// (required)
Elements []*Element `json:"elements,required" yaml:"elements,omitempty"`
// Title, A default title that will be pre-populated in the issue submission form.
// (optional)
Title string `json:"title,omitempty" yaml:"title,omitempty"`
// contains filtered or unexported fields
}
Model implements a data structure description inspired by GitHub YAML issue template syntax. See <https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-issue-forms>
The Model structure describes the HTML elements used to form a record. It can be used in code generation and in validating POST and PUT requests in datasetd.
func NewModel ¶
NewModel, makes sure model id is valid, populates a Model with the identifier element providing returns a *Model and error value.
func (*Model) Check ¶
Check analyze the model and make sure at least one element exists and the model has a single identifier (e.g. "identifier")
func (*Model) GetAttributeIds ¶
GetAttributeIds returns a slice of attribute ids found in the model's .Elements
func (*Model) GetElementById ¶
GetElementById returns a Element from the model's .Elements.
func (*Model) GetElementIds ¶
GetElementIds returns a slice of element ids found in the model's .Elements
func (*Model) GetModelIdentifier ¶
GetModelIdentifier() returns the element which describes the model identifier. Returns the element and a boolean set to true if found.
func (*Model) HasChanges ¶
HasChanges checks if the model's elements have changed
func (*Model) HasElement ¶
HasElement checks if the model has a given element id
func (*Model) HasElementType ¶
HasElementType checks if an element type matches given type.
func (*Model) InsertElement ¶
InsertElement will add a new element to model.Elements in the position indicated, It will also set isChanged to true on additional.
func (*Model) Register ¶
func (model *Model) Register(name string, fn RenderFunc)
Register takes a name (string) and a RenderFunc and registers it with the model. Registered names then can be invoke by the register name.
func (*Model) RemoveElement ¶
RemoveElement removes an element by id from the model.Elements
func (*Model) Render ¶
Render takes a register render io.Writer and register name envoking the function with the model.
func (*Model) ToSQLiteScheme ¶
ToSQLiteScheme takes a model and trys to render a SQLite3 SQL create statement.