#!/usr/bin/env ruby require File.expand_path( File.join(File.dirname(__FILE__), %w[.. lib germinate])) require 'main' Main do description <<-END Germinate - A tool for writing about code. With Germinate, your source code is also your article text. Special directives tell Germinate which parts to format as article text and where to insert source code excerpts and program output. To get started, execute: germ generate > my_article.rb to have Germinate generate a basic example article. For more information, see the project homepage at http://github.com/devver/germinate/ Development of Germinate is graciously sponsored by Devver, purveyor of fine cloud-based services to busy Ruby developers. If you like this tool please check them out at http://devver.net. END author "Avdi Grimm " version Germinate::VERSION def self.source_argument argument :source do arity 1 validate{|source| Pathname(source).readable?} description "Source file" end end mode :format do description "Format an article for publishing" source_argument def run Germinate.logger = self with_source_file do |source, path| application = Germinate::Application.new application.format(source, path, $stdout, $stderr) end end end mode :list do description "List various article components" source_argument COLLECTIONS = [:sections, :samples, :processes] COLLECTIONS.each do |collection| option collection do description "List all #{collection}" cast :bool end end def run things_to_list = [] COLLECTIONS.each do |collection| things_to_list << collection if params[collection].value end with_source_file do |source, path| application = Germinate::Application.new application.list(source, path, things_to_list, $stdout) end end end mode :show do description "Show details about various article components" source_argument TYPES = [:section, :sample, :process] TYPES.each do |type| option type do description "Show details about a #{type}" argument_required end end def run selection = TYPES.inject({}) {|sel, type| sel[type] = params[type].values sel } with_source_file do |source, path| application = Germinate::Application.new application.show(source, path, selection, $stdout) end end end mode :select do description "Test out a selector" source_argument option(:selector, :s) do arity 1 required argument_required description "The selector to search for" end def run with_source_file do |source, path| application = Germinate::Application.new application.select(source, path, params[:selector].value, $stdout) end end end mode :generate do description "Generate a sample article" def run example = File.expand_path("../doc/examples/basic.rb", File.dirname(__FILE__)) stdout.write(File.read(example)) end end def with_source_file path = params['source'].value File.open(path) do |file| yield file, path end end end # EOF