Class: Nanoc3::DataSources::FilesystemCombined

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/bar.html        --> /foo/bar/
  content/foo/bar/index.html  --> /foo/bar/

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

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.

#down
#items

Loading data ##########.

#layouts
#setup
#up

Preparation ##########.

#vcs

VCSes ##########.

Public Instance Methods Inherited from Nanoc3::DataSource

code_snippets, loading, unuse, 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]


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

public create_layout(content, attributes, identifier)

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

[View source]


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

public down
[View source]


70
71
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 70

def down
end

items

public items

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

[View source]


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
    meta, content = *parse_file(filename, 'item')

    # Get attributes
    attributes = meta.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

public layouts
[View source]


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
    meta, 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, meta, identifier, mtime)
  end.compact
end

setup

public setup
[View source]


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

public up

Preparation ##########

[View source]


67
68
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 67

def up
end

vcs

public vcs

VCSes ##########

[View source]


59
60
61
# File 'lib/nanoc3/data_sources/filesystem_combined.rb', line 59

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