# This is the module where the trivial data source will live in. It's not # really _necessary_ to create a separate module/namespace for each data # source, but it can be useful, especially when the data source needs extra # classes (for example, the database data source defines uses ActiveRecord, so # it needs classes for each table). module Nanoc::DataSource::Trivial # This is the implementation of a trivial data source. It doesn't do much # except return bogus data. It is meant to be a very simple example of a # data source, and it should be quite useful for those who want to write # their own data sources. class TrivialDataSource < Nanoc::DataSource ########## Attributes ########## # DataSource.identifier defines the name for this data source. The first # and only argument is the data source name as a symbol. identifier :trivial ########## Preparation ########## # DataSource#up is run before compiling. This is the place where you # should initialize the data source, if necessary. You don't need to # implement it; you can leave it out if you don't need initialization. # This is the ideal place to connect to the database, for example. # If your data source requires any special libraries, require them here # using 'nanoc_require'. def up end # DataSource#down is run after compiling. This is where you should clean # up any resources you used during the site compilation. You don't need to # implement it; you can leave it out if there's nothing to clean up. For # example, this is a good place to close the connection to the database, # if you have one. def down end # DataSource#setup is run when the site is created. This is the place # where you should create the data source for the first time. You don't # need to implement it; you can leave it out if there's nothing to set up. # For example, if you're using a database, this is where you should create # the necessary tables for the data source to function properly. def setup error "Sorry. The trivial data source isn't competent enough." end ########## Loading data ########## # DataSource#pages returns an array of hashes that represent pages. Each # hash must have at least the :uncompiled_content and :path keys. You can # include other metadata in this hash, though. def pages [ { :uncompiled_content => 'Hi!', :path => '/' }, { :uncompiled_content => 'Hello there.', :path => '/about/' } ] end # Datasource#page_defaults returns a hash with default values for page # metadata. This hash can be anything, even an empty hash if you wish. def page_defaults { :layout => 'quux' } end # DataSource#layouts returns an array of hashes that represent layouts. # Each hash must have the :name, :content and :extension keys. The # :extension key determines the layout processor that will be used (they # are defined in layout_processors/*.rb). def layouts [ { :name => 'quux', :content => "\n" + "
\n" + "