Class | Webby::Resources::MetaFile |
In: |
lib/webby/resources/meta_file.rb
|
Parent: | Object |
The MetaFile class is used to read meta-data and content from files. The meta-data is in a YAML block located at the top of the file. The content is the remainder of the file (everything after the YAML block).
The meta-data data must be found between two YAML block separators "—", each on their own line.
Example:
--- layout: blog filter: markdown tags: - ruby - web development --- This is a blog entry formatted using MarkDown and tagged as "ruby" and "web development". The layout being used is the "blog" format.
Opens the file identified by filename and returns the meta-data located at the top of the file. If the file contains no meta-data, then nil is returned.
Opens the file identified by filename and returns true if there is a meta-data block at the top of the file, and returns false if there is not a meta-data block at the top of the file.
Opens the file identified by filename and returns the contents of the file as a string. Any meta-data at the top of the file is skipped and is not included in the returned string. If the file contains no meta-data, then this method behaves the same as File#read.
Reads in each meta-data section and yields it to the given block. The first meta-data section is yielded "as is", but subsequent meta-data sections are merged with this first section and then yielded. This allows the user to define common items in the first meta-data section and only include items that are different in the subsequent sections.
Example:
--- title: First Title author: me directory: foo/bar/baz --- title: Second Title author: you --- title: Third Title author: them ---
and parsing the meta-data above yields …
meta_file.each do |hash| pp hash end
the following output
{ 'title' => 'First Title', 'author' => 'me', 'directory' => 'foo/bar/baz' } { 'title' => 'Second Title', 'author' => 'you', 'directory' => 'foo/bar/baz' } { 'title' => 'Third Title', 'author' => 'them', 'directory' => 'foo/bar/baz' }
Even though the "directory" item only appears in the first meta-data block, it is copied to all the subsequent blocks.
Returns the meta-data defined at the top of the file. Returns nil if no meta-data is defined. The meta-data is returned as Ruby objects
Meta-data is stored in YAML format between two YAML separators "—" on their own lines.
Returns true if the IO stream contains meta-data. Returns false if the IO stream does not contain meta-data.
Returns the position in the IO stream where the meta-data ends and the regular data begins. If there is no meta-data in the stream, returns nil.