NAME

App::Dapper::Schema - Check front matter against a _schema.yml file.

DESCRIPTION

A _schema.yml file in a source directory describes the front matter that pages in that directory (and the directories below it, unless they have a schema of their own) must have. For example:

required: [title, date]
fields:
  title:
    type: string
    max_length: 70
  date:
    type: date
  categories:
    type: list
    values: [blog, notes]
  description:
    type: string
    max_length: 160
  draft:
    type: boolean
additional: true

required lists the fields every page must set. fields describes each field:

type        string, number, integer, boolean, date, list, map or any
values      the allowed values (for a list: the allowed items)
pattern     a regular expression a string must match
min_length, max_length   limits on the length of a string
min, max    limits on a number

additional: false makes any field not listed in fields an error.

load

Takes the path of a schema file, reads it, checks that it is a valid schema, and returns it. Dies with a message naming the file if it is not.

for_file

Takes the source directory and a file in it, and returns the schema that applies to the file (from the nearest _schema.yml at or above its directory), or nothing.

validate

Takes a schema (from "load") and a hash of front matter, and returns a list of messages describing every way the front matter does not match the schema. An empty list means it matches.

check_value

Takes a field name, its value and its rules, and returns a list of messages for each rule the value breaks.

is_boolean

Returns true if a value is a YAML or JSON boolean, or one of 1, 0, the empty string, "true" or "false".