class

Hwaro::Models::ContentSchemaField

Inherits Reference < Object

One [content.schema.fields.<name>] entry. name is either a top-level key (a known front-matter field, or an unknown key, which the parser stores in extra) or extra.<key>.

Constants

DEFAULTABLE_KNOWN = ["description", "image", "template", "render", "toc", "insert_anchor_links", "in_sitemap", "in_search_index", "weight", "series", "series_weight", "tags", "authors", "updated"] of ::String

Known front-matter fields a default may fill: the ones read after parsing (cascade's set plus a few listing fields). URL-, date- and publication-window fields are resolved during parsing, so a default on them could not take effect. draft is left out on purpose: the tools' publish state (ContentLister) reads front matter and [cascade] only, and a default it cannot see would split the page set.

KEYS = ["type", "required", "enum", "default", "min", "max"] of ::String
KNOWN_TYPES = {"title" => "string", "description" => "string", "image" => "string", "template" => "string", "slug" => "string", "path" => "string", "sort_by" => "string", "page_template" => "string", "paginate_path" => "string", "redirect_to" => "string", "series" => "string", "translation_key" => "string", "draft" => "bool", "in_sitemap" => "bool", "toc" => "bool", "render" => "bool", "transparent" => "bool", "generate_feeds" => "bool", "pagination_enabled" => "bool", "reverse" => "bool", "in_search_index" => "bool", "insert_anchor_links" => "bool", "paginate" => "int", "paginate_by" => "int", "weight" => "int", "series_weight" => "int", "date" => "date", "updated" => "date", "expires" => "date", "aliases" => "array", "tags" => "array", "authors" => "array", "categories" => "array", "taxonomies" => "table", "cascade" => "table"}

The type each known front-matter field has to the parser. A schema may only declare that type for it (menus/menu take several shapes and are not listed).

TYPES = ["string", "int", "float", "bool", "date", "array", "table"] of ::String

Constructors

new(name : String, type : String, required : Bool = false, enum_values : Nil | Array(Array(Hwaro::Models::ExtraValue) | Array(String) | Bool | Float64 | Hash(String, Hwaro::Models::ExtraValue) | Int64 | String | Time) = nil, default : Array(Hwaro::Models::ExtraValue) | Array(String) | Bool | Float64 | Hash(String, Hwaro::Models::ExtraValue) | Int64 | String | Time | Nil = nil, min : Float64 | Nil = nil, max : Float64 | Nil = nil)
Source

Class methods

number(value : Float64) : String

A bound for messages: whole values print as integers ("5"), except those too large for Int64 (to_i64 would raise OverflowError).

Source
show(value : SchemaValue) : String

value.inspect, cut to about 80 characters for messages.

Source
type_name(value : SchemaValue) : String
Source

Instance methods

default
Source
enum_values
Source
extra_key

extra.rating → "rating"; a top-level name → nil.

Source
name
Source
problem(value : SchemaValue) : String | Nil

The first problem with value (type, enum, bounds), or nil.

Source
required
Source
type
Source