Sha256: 59cfaee5182a740a9c003c1aef579dbc7a318c730780d72cba1c40fbfe401fc2

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

$:.unshift File.join(File.dirname(__FILE__), '../..')
require 'railroad'

namespace :doc do
  namespace :diagrams do
    desc "Draw model diagrams"
    task :models => :environment do
      doc_diagrams_generate(ModelsDiagram, 'models', '-a -m -t -M', 'neato')
    end

    desc "Draw controller diagrams"
    task :controllers do
      doc_diagrams_generate(ControllersDiagram, 'controllers', '-C', 'neato')
    end

    desc "Draw states diagrams"
    task :states do
      doc_diagrams_generate(AasmDiagram, 'states', '-A', 'dot')
    end

    desc "Draw Hobo::Lifecycle diagrams"
    task :lifecycle do
      doc_diagrams_generate(LifecycleDiagram, 'lifecycle', '-L', 'dot')
    end
end

  desc "Draw controllers, models & states diagrams"
  task :diagrams => %w(diagrams:models diagrams:controllers diagrams:states diagrams:lifecycle)
end

def doc_diagrams_generate(generator, type, options, dot_cmd)
  options = OptionsStruct.new
  options.parse "-v -j -l -i #{options}".split
  
  output_dir = "doc/diagrams"

  FileUtils.mkdir(output_dir) unless File.exist?(output_dir)

  diagram = generator.new options
  diagram.generate
  f=open("#{output_dir}/#{type}.dot", "w")
  f.write(diagram.to_s)
  f.close

  sh "#{dot_cmd} -Tpng #{output_dir}/#{type}.dot -o #{output_dir}/#{type}.png"
  sh "#{dot_cmd} -Tsvg #{output_dir}/#{type}.dot | sed 's/font-size:14.00/font-size:11px/g' > #{output_dir}/#{type}.svg"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
allenwei-railroad-0.7.8 lib/railroad/tasks/diagrams.rake