# # File 'basic.rb' created on 01 mag 2008 at 15:37:33. # # See 'dokkit.rb' or +LICENSE+ for licence information. # # (C)2006-2008 Andrea Fazzi (and contributors). # require 'ostruct' require 'rake' require 'dokkit' require 'dokkit/environment' require 'dokkit/logging' require 'dokkit/factory' require 'dokkit/resource' require 'dokkit/tasklib' require 'dokkit/filters' require 'dokkit/cache' module Dokkit module Environment module Basic # When included in a container, initialize it. def initialize add_lib_to_load_path yield self if block_given? define_tasks end # Add lib folder to the load path. def add_lib_to_load_path $: << 'lib' end # Define rake tasks for the environment. def define_tasks render clean end # Setup a console logger. def logger @logger ||= Logging::Observer::Console.logger end # Setup cache. def cache @cache ||= Cache.new end # Return an OpenStruct object to setup documentation # directories. Instantiate the object only once. # # configuration.document_dir :: set/get documents folder. # configuration.config_dir :: set/get configs folder. # configuration.layout_dir :: set/get layouts folder. # configuration.data_dir :: set/get data folder. # configuration.output_dir :: set/get output folder. # configuration.cache_dir :: set/get cache folder. # def configuration @configuration ||= OpenStruct.new({ :document_dir => 'doc/pages', :config_dir => 'doc/configs', :layout_dir => 'doc/layouts', :data_dir => 'doc/data', :output_dir => 'output', :cache_dir => '.cache' }) end # Return a Dokkit::Environment::Helper::FileSelection object # with the list of documents in configuration.document_dir # folder and its subdir. The object is instantiated only # once. By default all files in configuration.document_dir and # subdirs are included. def documents @documents ||= Environment::Helper::FileSelection.new(configuration.document_dir) do |fs| fs.include('**/*') fs.exclude('**/*.yaml') end end # Return a Dokkit::Environment::Helper::FileSelection object # with the list of data files in configuration.data_dir folder # and its subdir. The object is instantiated only once. def data @data ||= Environment::Helper::FileSelection.new(configuration.data_dir).include('**/*') end # Return a Dokkit::Environment::Helper::ExtMap object that map # an extension code block to document files using glob patterns. def extmap @extmap ||= Helper::ExtMap.new(configuration.document_dir) end # Construct a filter factory and register filters. def filter_factory @filter_factory ||= Dokkit::Factory.new do |factory| factory.add('maruku-html' => lambda { Dokkit::Filter::MarukuHTML.new } ) factory.add('deplate-latex' => lambda { Dokkit::Filter::DeplateLatex.new } ) factory.add('deplate-html' => lambda { Dokkit::Filter::DeplateHTML.new } ) factory.add('deplate-text' => lambda { Dokkit::Filter::DeplateText.new } ) end end # Construct a resource factory to get resource instances # (i.e. document and data). The object is instantiated only # once. def resource_factory @resource_factory ||= Factory.new do |factory| factory.add(:document => document_factory_block) factory.add(:data => data_factory_block) end end # Return a block that is able to construct a Document instance. def document_factory_block lambda do |source_fn| Resource::Document.new(source_fn, configuration.marshal_dump, logger, cache, resource_factory, filter_factory, &extmap[source_fn]) end end # Return a block that is able to construct a Data instance. def data_factory_block lambda do |source_fn| Resource::Data.new(source_fn, configuration.marshal_dump) end end # Define render tasklib. def render TaskLib::Render.new(logger, resource_factory, documents.files, data.files) end # Define clean tasklib. def clean TaskLib::Clean.new(logger, configuration.marshal_dump) end end end end module Dokkit module Environment module Basic # Define a setup container. class Container include Dokkit::Environment::Basic end end end end