Class: Nanoc3::DataSources::FilesystemCompact
- Nanoc3::Plugin
- Nanoc3::DataSource
- Nanoc3::DataSources::FilesystemCompact
Included Modules
The filesystem_combined 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
Items are stored as pairs of two files: a content file, containing the actual item content, and a meta file, containing the item’s attributes, formatted as YAML. The content file and the corresponding meta file have the same filename but not the same extension; the meta file’s extension is .yaml.
Items are stored in the "content" directory of the nanoc site.
The home page item, located at /, is represented by an index.yaml meta file, along with its corresponding content file.
Subitems of other pages can be achieved in two ways: they can either be nested in directories and named "index" such as the home page item, or they can simply be given a non-"index" name.
For example, this directory structure:
content/ index.html index.yaml about.html about.yaml journal.html journal.yaml journal/ 2005.html 2005.yaml 2005/ a-very-old-post.html a-very-old-post.yaml another-very-old-post.html another-very-old-post.yaml myst/ index.html index.yaml
… corresponds with the following items:
/ /about/ /journal/ /journal/2005/ /journal/2005/a-very-old-post/ /journal/2005/another-very-old-post/ /myst/
Layouts
Layouts are stored the same way as items, except that they are stored in the "layouts" directory instead of the "content" directory.
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. |
| #items |
Loading data ##########. |
| #layouts | |
| #setup |
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.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/nanoc3/data_sources/filesystem_compact.rb', line 142 def create_item(content, attributes, identifier) # Get filenames base_path = 'content' + (identifier == '/' ? '/index' : identifier[0..-2]) = base_path + '.yaml' content_filename = base_path + '.html' # Notify Nanoc3::NotificationCenter.post(:file_created, ) Nanoc3::NotificationCenter.post(:file_created, content_filename) # Create files FileUtils.mkdir_p(File.dirname()) 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.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/nanoc3/data_sources/filesystem_compact.rb', line 159 def create_layout(content, attributes, identifier) # Get filenames base_path = 'layouts' + identifier[0..-2] = base_path + '.yaml' content_filename = base_path + '.html' # Notify Nanoc3::NotificationCenter.post(:file_created, ) Nanoc3::NotificationCenter.post(:file_created, content_filename) # Create files FileUtils.mkdir_p(File.dirname()) File.open(, 'w') { |io| io.write(YAML.dump(attributes.stringify_keys)) } File.open(content_filename, 'w') { |io| io.write(content) } end |
items
Loading data ##########
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/nanoc3/data_sources/filesystem_compact.rb', line 92 def items ('content').map do || # Read metadata = YAML.load_file() || {} # Get content content_filename = () content = File.read(content_filename) # Get attributes attributes = .merge(:file => Nanoc3::Extra::FileProxy.new(content_filename)) # Get identifier identifier = (.sub(/^content/, '')) # 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
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/nanoc3/data_sources/filesystem_compact.rb', line 117 def layouts ('layouts').map do || # Get content content_filename = () content = File.read(content_filename) # Get attributes attributes = YAML.load_file() || {} # Get identifier identifier = (.sub(/^layouts\//, '')) # 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
Preparation ##########
82 83 84 85 86 87 88 |
# File 'lib/nanoc3/data_sources/filesystem_compact.rb', line 82 def setup # Create directories %w( content layouts lib ).each do |dir| FileUtils.mkdir_p(dir) vcs.add(dir) end end |
vcs
VCSes ##########
74 75 76 |
# File 'lib/nanoc3/data_sources/filesystem_compact.rb', line 74 def vcs @vcs ||= Nanoc3::Extra::VCSes::Dummy.new end |