Class: Nanoc3::DataSources::FilesystemCompact

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

MAP

Constructor Summary

This class inherits a constructor from Nanoc3::DataSource.

Public Visibility

Public Class Methods Inherited from Nanoc3::DataSource

identifier, identifiers, register

Public Class Methods Inherited from Nanoc3::Plugin

all, named

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

code_snippets, down, loading, unuse, up, update, use

Public Instance Methods Included from Nanoc3::DataSources::FilesystemCommon

code_snippets

Public Instance Method Details

create_item

public create_item(content, attributes, identifier)

Creating data ########## Creates a new item with the given content, attributes and identifier.

[View source]


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])
  meta_filename    = base_path + '.yaml'
  content_filename = base_path + '.html'

  # Notify
  Nanoc3::NotificationCenter.post(:file_created, meta_filename)
  Nanoc3::NotificationCenter.post(:file_created, content_filename)

  # Create files
  FileUtils.mkdir_p(File.dirname(meta_filename))
  File.open(meta_filename,    'w') { |io| io.write(YAML.dump(attributes.stringify_keys)) }
  File.open(content_filename, 'w') { |io| io.write(content) }
end

create_layout

public create_layout(content, attributes, identifier)

Creates a new layout with the given content, attributes and identifier.

[View source]


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]
  meta_filename    = base_path + '.yaml'
  content_filename = base_path + '.html'

  # Notify
  Nanoc3::NotificationCenter.post(:file_created, meta_filename)
  Nanoc3::NotificationCenter.post(:file_created, content_filename)

  # Create files
  FileUtils.mkdir_p(File.dirname(meta_filename))
  File.open(meta_filename,    'w') { |io| io.write(YAML.dump(attributes.stringify_keys)) }
  File.open(content_filename, 'w') { |io| io.write(content) }
end

items

public items

Loading data ##########

[View source]


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
  meta_filenames('content').map do |meta_filename|
    # Read metadata
    meta = YAML.load_file(meta_filename) || {}

    # Get content
    content_filename = content_filename_for_meta_filename(meta_filename)
    content = File.read(content_filename)

    # Get attributes
    attributes = meta.merge(:file => Nanoc3::Extra::FileProxy.new(content_filename))

    # Get identifier
    identifier = identifier_for_meta_filename(meta_filename.sub(/^content/, ''))

    # Get modification times
    meta_mtime    = File.stat(meta_filename).mtime
    content_mtime = File.stat(content_filename).mtime
    mtime         = meta_mtime > content_mtime ? meta_mtime : content_mtime

    # Create item object
    Nanoc3::Item.new(content, attributes, identifier, mtime)
  end
end

layouts

public layouts
[View source]


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
  meta_filenames('layouts').map do |meta_filename|
    # Get content
    content_filename  = content_filename_for_meta_filename(meta_filename)
    content           = File.read(content_filename)

    # Get attributes
    attributes = YAML.load_file(meta_filename) || {}

    # Get identifier
    identifier = identifier_for_meta_filename(meta_filename.sub(/^layouts\//, ''))

    # Get modification times
    meta_mtime    = File.stat(meta_filename).mtime
    content_mtime = File.stat(content_filename).mtime
    mtime         = meta_mtime > content_mtime ? meta_mtime : content_mtime

    # Create layout object
    Nanoc3::Layout.new(content, attributes, identifier, mtime)
  end
end

setup

public setup

Preparation ##########

[View source]


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

public vcs

VCSes ##########

[View source]


74
75
76
# File 'lib/nanoc3/data_sources/filesystem_compact.rb', line 74

def vcs
  @vcs ||= Nanoc3::Extra::VCSes::Dummy.new
end
Generated on Sunday, August 09 2009 at 01:43:14 PM by YARD 0.2.3.2 (ruby-1.8.7).