Class: Nanoc::DataSources::Filesystem Private

Inherits:
Nanoc::DataSource show all
Defined in:
lib/nanoc/data_sources/filesystem.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The filesystem data source stores its items and layouts in nested directories. Items and layouts are represented by one or two files; if it is represented using one file, the metadata can be contained in this file.

The default root directory for items is the ‘content` directory; for layouts, this is the `layouts` directory. This can be overridden in the data source configuration:

data_sources:
  - type:         filesystem
    content_dir:  items
    layouts_dir:  layouts

The metadata for items and layouts can be stored in a separate file with the same base name but with the ‘.yaml` extension. If such a file is found, metadata is read from that file. Alternatively, the content file itself can start with a metadata section: it can be stored at the top of the file, between `—` (three dashes) separators. For example:

---
title: "Moo!"
---
h1. Hello!

The metadata section can be omitted. If the file does not start with three or five dashes, the entire file will be considered as content.

The identifier of items and layouts is the filename itself, without the root directory (as determined by the ‘content_dir` or `layouts_dir` configuration attribute, for items resp. layouts). For example:

foo/bar/index.html → /foo/bar/index.html
foo/bar.html       → /foo/bar.html

Note that each item must have an unique identifier. Nanoc will display an error if two items with the same identifier are found.

The file extension does not determine the filters to run on items; the Rules file is used to specify processing instructors for each item.

It is possible to set an explicit encoding that should be used when reading files. In the data source configuration, set ‘encoding` to an encoding understood by Ruby’s `Encoding`. If no encoding is set in the configuration, one will be inferred from the environment.

Defined Under Namespace

Classes: InvalidMetadataError, ParseResult, ProtoDocument

Instance Attribute Summary

Attributes inherited from Nanoc::DataSource

#config, #items_root, #layouts_root

Instance Method Summary collapse

Methods inherited from Nanoc::DataSource

#initialize, #loading, #new_item, #new_layout, #unuse, #use

Methods included from Int::PluginRegistry::PluginMethods

#all, #identifier, #identifiers, #named, #register

Constructor Details

This class inherits a constructor from Nanoc::DataSource

Instance Method Details

#content_dir_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



57
58
59
# File 'lib/nanoc/data_sources/filesystem.rb', line 57

def content_dir_name
  config.fetch(:content_dir, 'content')
end

#downObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Nanoc::DataSource#down.



54
55
# File 'lib/nanoc/data_sources/filesystem.rb', line 54

def down
end

#itemsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Nanoc::DataSource#items.



66
67
68
# File 'lib/nanoc/data_sources/filesystem.rb', line 66

def items
  load_objects(content_dir_name, Nanoc::Int::Item)
end

#layoutsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Nanoc::DataSource#layouts.



71
72
73
# File 'lib/nanoc/data_sources/filesystem.rb', line 71

def layouts
  load_objects(layouts_dir_name, Nanoc::Int::Layout)
end

#layouts_dir_nameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



61
62
63
# File 'lib/nanoc/data_sources/filesystem.rb', line 61

def layouts_dir_name
  config.fetch(:layouts_dir, 'layouts')
end

#upObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

See Nanoc::DataSource#up.



50
51
# File 'lib/nanoc/data_sources/filesystem.rb', line 50

def up
end