Class: Nanoc3::DataSources::Filesystem
- Nanoc3::Plugin
- Nanoc3::DataSource
- Nanoc3::DataSources::Filesystem
Included Modules
The filesystem data source is the default data source for a new nanoc site. It stores all data as files on the hard disk.
None of the methods are documented in this file. See Nanoc3::DataSource for documentation on the overridden methods instead.
Items
The filesystem data source stores its items in nested directories. Each directory represents a single item. The root directory is the ‘content’ directory.
Every directory has a content file and a meta file. The content file contains the actual item content, while the meta file contains the item’s metadata, formatted as YAML.
Both content files and meta files are named after its parent directory (i.e. item). For example, a item named ‘foo’ will have a directory named ‘foo’, with e.g. a ‘foo.markdown’ content file and a ‘foo.yaml’ meta file.
Content file extensions are not used for determining the filter that should be run; the meta file defines the list of filters. The meta file extension must always be ‘yaml’, though.
Content files can also have the ‘index’ basename. Similarly, meta files can have the ‘meta’ basename. For example, a parent directory named ‘foo’ can have an ‘index.txt’ content file and a ‘meta.yaml’ meta file. This is to preserve backward compatibility.
Layouts
Layouts are stored as directories in the ‘layouts’ directory. Each layout contains a content file and a meta file. The content file contain the actual layout, and the meta file describes how the item should be handled (contains the filter that should be used).
For backward compatibility, a layout can also be a single file in the ‘layouts’ directory. Such a layout cannot have any metadata; the filter used for this layout is determined from the file extension.
Code Snippets
Code snippets are stored in ’.rb’ files in the ‘lib’ directory. Code snippets can reside in sub-directories.
Attributes
Instance Attributes
| vcs | [RW] | public |
VCSes ##########. |
|---|
Constants Inherited from Nanoc3::Plugin
Constructor Summary
This class inherits a constructor from Nanoc3::DataSource.
Public Visibility
Public Class Methods Inherited from Nanoc3::DataSource
Public Class Methods Inherited from Nanoc3::Plugin
Public Instance Method Summary
| #create_item(content, attributes, identifier) |
Creating data ########## Creates a new item with the given content, attributes and identifier. |
|---|---|
| #create_layout(content, attributes, identifier) |
Creates a new layout with the given content, attributes and identifier. |
| #down | |
| #items |
Loading data ##########. |
| #layouts | |
| #setup | |
| #up |
Preparation ##########. |
| #vcs |
VCSes ##########. |
Public Instance Methods Inherited from Nanoc3::DataSource
Public Instance Methods Included from Nanoc3::DataSources::FilesystemCommon
Public Instance Method Details
create_item
Creating data ########## Creates a new item with the given content, attributes and identifier.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/nanoc3/data_sources/filesystem.rb', line 129 def create_item(content, attributes, identifier) # Determine base path last_component = identifier.split('/')[-1] || 'content' base_path = 'content' + identifier + last_component # Get filenames dir_path = 'content' + identifier = 'content' + identifier + last_component + '.yaml' content_filename = 'content' + identifier + last_component + '.html' # Notify Nanoc3::NotificationCenter.post(:file_created, ) Nanoc3::NotificationCenter.post(:file_created, content_filename) # Create files FileUtils.mkdir_p(dir_path) File.open(, 'w') { |io| io.write(YAML.dump(attributes.stringify_keys)) } File.open(content_filename, 'w') { |io| io.write(content) } end |
create_layout
Creates a new layout with the given content, attributes and identifier.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/nanoc3/data_sources/filesystem.rb', line 150 def create_layout(content, attributes, identifier) # Determine base path last_component = identifier.split('/')[-1] base_path = 'layouts' + identifier + last_component # Get filenames dir_path = 'layouts' + identifier = 'layouts' + identifier + last_component + '.yaml' content_filename = 'layouts' + identifier + last_component + '.html' # Notify Nanoc3::NotificationCenter.post(:file_created, ) Nanoc3::NotificationCenter.post(:file_created, content_filename) # Create files FileUtils.mkdir_p(dir_path) File.open(, 'w') { |io| io.write(YAML.dump(attributes.stringify_keys)) } File.open(content_filename, 'w') { |io| io.write(content) } end |
down
66 67 |
# File 'lib/nanoc3/data_sources/filesystem.rb', line 66 def down end |
items
Loading data ##########
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/nanoc3/data_sources/filesystem.rb', line 79 def items ('content').map do || # Read metadata = YAML.load_file() || {} # Get content content_filename = content_filename_for_dir(File.dirname()) content = File.read(content_filename) # Get attributes attributes = .merge(:file => Nanoc3::Extra::FileProxy.new(content_filename)) # Get identifier identifier = .sub(/^content/, '').sub(/[^\/]+\.yaml$/, '') # Get modification times = File.stat().mtime content_mtime = File.stat(content_filename).mtime mtime = > content_mtime ? : content_mtime # Create item object Nanoc3::Item.new(content, attributes, identifier, mtime) end end |
layouts
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/nanoc3/data_sources/filesystem.rb', line 104 def layouts ('layouts').map do || # Get content content_filename = content_filename_for_dir(File.dirname()) content = File.read(content_filename) # Get attributes attributes = YAML.load_file() || {} # Get identifier identifier = .sub(/^layouts\//, '').sub(/\/[^\/]+\.yaml$/, '') # Get modification times = File.stat().mtime content_mtime = File.stat(content_filename).mtime mtime = > content_mtime ? : content_mtime # Create layout object Nanoc3::Layout.new(content, attributes, identifier, mtime) end end |
setup
69 70 71 72 73 74 75 |
# File 'lib/nanoc3/data_sources/filesystem.rb', line 69 def setup # Create directories %w( content layouts lib ).each do |dir| FileUtils.mkdir_p(dir) vcs.add(dir) end end |
up
Preparation ##########
63 64 |
# File 'lib/nanoc3/data_sources/filesystem.rb', line 63 def up end |
vcs
VCSes ##########
55 56 57 |
# File 'lib/nanoc3/data_sources/filesystem.rb', line 55 def vcs @vcs ||= Nanoc3::Extra::VCSes::Dummy.new end |