lib/cabbage_doc/task.rb in cabbage_doc-0.0.7 vs lib/cabbage_doc/task.rb in cabbage_doc-0.0.8

- old
+ new

@@ -1,11 +1,11 @@ require 'rake' require 'rake/tasklib' module CabbageDoc class Task < Rake::TaskLib - attr_accessor :processors, :name + attr_accessor :generators, :tags, :name, :customize def self.define new.tap do |instance| yield instance if block_given? instance.validate! @@ -13,48 +13,80 @@ instance.define! end end def initialize - @processors = [:documentation] - @name = :cabbagedoc + self.generators = config.generators.dup + self.tags = config.tags.dup + self.name = :cabbagedoc + self.customize = true end + def config + @_config ||= Configuration.instance + end + def sort! - processors.sort! { |processor| Processor::PRIORITIES.index(Processor.all[processor].priority) } + generators.sort! { |generator| Generator::PRIORITIES.index(Generator.all[generator].priority) } end def define! namespace name do - processors.each do |processor| - desc "Process #{processor}" - namespace :process do - task processor.to_s => :environment do - Processor.all[processor].new.perform - end - end - end - - desc "Customize Web UI" - task :customize => :environment do - Customizer.new.perform - end + define_generators! + define_customizer! end - desc "Run all processors" + desc "Run all generators" task name => :environment do - processors.each do |name| - Processor.all[name].new.perform + generators.each do |type| + Generator.perform(type) end end end def validate! fail "Invalid 'name'" unless name.is_a?(Symbol) - fail "No 'processors' configured" unless processors.any? + fail "No 'generators' configured" unless generators.any? - processors.each do |processor| - fail "Invalid 'processor' #{processor}" unless Processor.all.has_key?(processor) + generators.each do |generator| + fail "Invalid 'generator' #{generator}" unless Generator.exists?(generator) + end + end + + private + + def define_generators! + generators.each do |type| + desc "Generate #{type}" + task type => :environment do + Generator.perform(type) + end + + define_generators_by_tag!(type) + define_customizer! + end + end + + def define_generators_by_tag!(type) + return unless Generator.supports?(type, :tags) + return unless tags.size > 1 + + namespace type do + tags.each do |tag| + desc "Generate #{type} for #{tag}" + task tag => :environment do + Generator.perform(type, tag) + end + end + end + end + + def define_customizer! + return unless customize + + desc "Customize Web UI" + task :customize => :environment do + Customizer.new.perform end end end end