Class: Nanoc::DataSources::Static
- Inherits:
-
Nanoc::DataSource
- Object
- Nanoc::DataSource
- Nanoc::DataSources::Static
- Defined in:
- lib/nanoc/data_sources/static.rb
Overview
The static data source provides items from a single directory. Unlike the filesystem data sources, static provides no additional item metadata. In addition, all items are treated as ‘binary’, regardless of their extension or content. As such, it is most useful for simple assets, not for normal content.
The identifier for static items is the full item path. For example, if your
static data source item_root is static
, an item named foo.css
would have
the identifier /static/foo.css/
. Note that, unlike the filesystem data
sources, foo/index.html
and foo.yaml
receive no special treatment. They
are simple static items, just like foo.css
.
The default data source directory is static/
, but this can be overridden
in the data source configuration:
data_sources:
- type: static
prefix: assets
Unless the hide_items
configuration attribute is false, items from static
data sources will have the :is_hidden attribute set by default, which will
exclude them from the Blogging helper’s atom feed generator, among other
things.
Instance Attribute Summary
Attributes inherited from Nanoc::DataSource
#config, #items_root, #layouts_root
Instance Method Summary (collapse)
Methods inherited from Nanoc::DataSource
#create_item, #create_layout, #down, #initialize, #layouts, #loading, #setup, #sync, #unuse, #up, #update, #use
Methods included from PluginRegistry::PluginMethods
#all, #identifier, #identifiers, #named, #register
Constructor Details
This class inherits a constructor from Nanoc::DataSource
Instance Method Details
- (Object) items
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/nanoc/data_sources/static.rb', line 32 def items # Get prefix prefix = config[:prefix] || 'static' # Convert filenames to items all_files_in(prefix).map do |filename| attributes = { :extension => File.extname(filename)[1..-1], :filename => filename, } attributes[:is_hidden] = true unless config[:hide_items] == false identifier = filename[(prefix.length + 1)..-1] + '/' mtime = File.mtime(filename) checksum = Pathname.new(filename).checksum Nanoc::Item.new( filename, attributes, identifier, :binary => true, :mtime => mtime, :checksum => checksum ) end end |