NAME

App::Dapper::Utils - Common utility functions used throughout Dapper.

read_file

Read a file and return a scalar with the file's contents, decoded as UTF-8.

write_file

Takes a file name and a string, creates any missing parent directories, and writes the string to the file encoded as UTF-8.

has_frontmatter

Takes a file name and returns true if the file begins with a YAML front matter delimiter (---). Only the first few bytes are read, so this is safe to call on binary files.

split_frontmatter

Takes a string (and a name used in error messages) and splits it into its YAML front matter and its body. The front matter must start on the first line and be closed by a line containing only ---. Returns a list of the parsed front matter (a hash reference) and the body, or an empty list if the string does not start with front matter.

parse_date

Takes a date string and returns a DateTime object. Accepts ISO 8601 / XML Schema date-times (2014-05-02T10:30:00, optionally with a time zone), the pre-0.19 format with a space instead of a T (2014-05-02 10:30:00), and plain dates (2014-05-02). Dies with a helpful message otherwise.

get_modified_time

Takes a file and returns the last modified time of the file.

slugify

Takes an input string (e.g. the title of a blog post) and "slugifies" it: accented letters are reduced to their plain form, other non-ASCII characters are removed, punctuation is removed (letters, digits, underscores, hyphens and spaces are kept), leading and trailing whitespace is trimmed, the result is lowercased, and runs of spaces and hyphens become a single hyphen. For example, "Café: A Story" becomes "cafe-a-story".

filter_extension

Takes a string (filename) and returns the extension.

filter_stem

Takes a filename and returns the stem of the file name (without the extension).

create_file

Takes a file name and a string of the content and writes it to disk. Dies if the file already exists.

create_dir

Takes a directory name and creates it (and any missing parents) on disk.

name_chars

Takes a file name as read from the file system (bytes) and returns it as characters, decoding UTF-8. Names that are not valid UTF-8 are returned as they are. Every name read from a directory goes through this, so that joining it to other text (such as a directory name from _config.yml) doesn't mangle accented letters.

name_bytes

Takes a file name and returns it as UTF-8 bytes, for code (like File::Find) that joins it to names it reads itself.

read_dir

Takes a directory and returns the names in it (without . and ..), as characters, sorted. Dies if the directory can't be read.

copy_recursive

Takes a source path (a file or directory), a destination path, and an optional list of absolute paths to skip. Copies the source to the destination, recursing into directories and creating them as needed. No shell is involved, so file names with spaces or special characters are safe. Returns the list of files written.

App::Dapper::Date

Dates in Dapper (page.date, site.time) are DateTime objects with one extra method, xmlschema, which returns the date in XML Schema format with its time zone. Template filters only apply to plain strings, so use the method form for dates:

<updated>[% page.date.xmlschema %]</updated>