Class: Nanoc3::DataSources::FilesystemCombined
- Nanoc3::Plugin
- Nanoc3::DataSource
- Nanoc3::DataSources::FilesystemCombined
Included Modules
Items
The filesystem data source stores its items in nested directories. A item is represented by a single file. The root directory is the ‘content’ directory.
The metadata for a item is embedded into the file itself. It is stored at the top of the file, between ’--’ (three dashes) separators. For example:
--- title: "Moo!" --- h1. Hello!
The identifier of a item is determined as follows. A file with an ‘index.*’ filename, such as ‘index.txt’, will have the filesystem path with the ‘index.*’ part stripped as a identifier. For example, ‘foo/bar/index.html’ will have ’/foo/bar/’ as identifier.
A file with a filename not starting with ‘index.’, such as ‘foo.html’, will have an identifier ending in ‘foo/’. For example, ‘foo/bar.html’ will have ’/foo/bar/’ as identifier.
Note that it is possible for two different, separate files to have the same identifier. It is therefore recommended to avoid such situations.
Some more examples:
content/index.html --> / content/foo.html --> /foo/ content/foo/index.html --> /foo/ content/foo/.html --> /foo// content/foo//index.html --> /foo//
File extensions are ignored by nanoc. The file extension does not determine the filters to run on it; the metadata in the file defines the list of filters.
Layouts
Layouts are stored as files in the ‘layouts’ directory. Similar to items, each layout consists of a metadata part and a content part, separated by ’--’ (three dashes).
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 148 |
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 129 def create_item(content, attributes, identifier) # Determine path if identifier == '/' path = 'content/index.html' else path = 'content' + identifier[0..-2] + '.html' end parent_path = File.dirname(path) # Notify Nanoc3::NotificationCenter.post(:file_created, path) # Write item FileUtils.mkdir_p(parent_path) File.open(path, 'w') do |io| io.write(YAML.dump(attributes.stringify_keys) + "\n") io.write("---\n") io.write(content) end end |
create_layout
Creates a new layout with the given content, attributes and identifier.
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 151 def create_layout(content, attributes, identifier) # Determine path path = 'layouts' + identifier[0..-2] + '.html' parent_path = File.dirname(path) # Notify Nanoc3::NotificationCenter.post(:file_created, path) # Write layout FileUtils.mkdir_p(parent_path) File.open(path, 'w') do |io| io.write(YAML.dump(attributes.stringify_keys) + "\n") io.write("---\n") io.write(content) end end |
down
70 71 |
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 70 def down end |
items
Loading data ##########
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 83 def items files('content', true).map do |filename| # Read and parse data , content = *parse_file(filename, 'item') # Get attributes attributes = .merge(:file => Nanoc3::Extra::FileProxy.new(filename)) # Get actual identifier if filename =~ /\/index\.[^\/]+$/ identifier = filename.sub(/^content/, '').sub(/index\.[^\/]+$/, '') + '/' else identifier = filename.sub(/^content/, '').sub(/\.[^\/]+$/, '') + '/' end # Get mtime mtime = File.stat(filename).mtime # Build item Nanoc3::Item.new(content, attributes, identifier, mtime) end end |
layouts
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_combined.rb', line 106 def layouts files('layouts', true).map do |filename| # Read and parse data , content = *parse_file(filename, 'layout') # Get actual identifier if filename =~ /\/index\.[^\/]+$/ identifier = filename.sub(/^layouts/, '').sub(/index\.[^\/]+$/, '') + '/' else identifier = filename.sub(/^layouts/, '').sub(/\.[^\/]+$/, '') + '/' end # Get mtime mtime = File.stat(filename).mtime # Build layout Nanoc3::Layout.new(content, , identifier, mtime) end.compact end |
setup
73 74 75 76 77 78 79 |
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 73 def setup # Create directories %w( content layouts lib ).each do |dir| FileUtils.mkdir_p(dir) vcs.add(dir) end end |
up
Preparation ##########
67 68 |
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 67 def up end |
vcs
VCSes ##########
59 60 61 |
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 59 def vcs @vcs ||= Nanoc3::Extra::VCSes::Dummy.new end |