Sha256: 105312771e799a692e57d27a57044bd1aac28026ebc255c814353e24b31577ba

Contents?: true

Size: 1.31 KB

Versions: 20

Compression:

Stored size: 1.31 KB

Contents

namespace :doc do
  desc "Generate documentation for the web services"
  task :services do
    ENV['DONT_CONNECT'] = 'true'
    ENV['DONT_PRINT_ROUTES'] = 'true'
    require 'wd_sinatra/app_loader'
    root = File.expand_path("../..", File.dirname(__FILE__))
    WDSinatra::AppLoader.server(root)
    LOGGER.level = Logger::FATAL

    require 'fileutils'
    destination = File.join(root, 'doc')
    FileUtils.mkdir_p(destination) unless File.exist?(destination)
    copy_assets(destination)
    File.open("#{destination}/index.html", "w"){|f| f << template.result(binding)}
    puts "Documentation available there: #{destination}/index.html"
    `open #{destination}/index.html` if RUBY_PLATFORM =~ /darwin/ && !ENV['DONT_OPEN']
  end

  def template
    file = resources.join 'template.erb'
    ERB.new File.read(file)
  end

  def resources
    require 'pathname'
    @resources ||= Pathname.new(File.join(File.dirname(__FILE__), 'doc_generator'))
  end

  def copy_assets(destination)
    %W{css js images}.each do |asset_type|
      FileUtils.mkdir_p(File.join(destination, asset_type))
    end
    Dir.glob(resources.join("bootstrap", "js", "*.js")).each do |file| 
      FileUtils.cp(file, File.join(destination, 'js'))
    end
    FileUtils.cp(resources.join('bootstrap', 'bootstrap.css'), File.join(destination, 'css'))
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
wd_sinatra-1.0.6 templates/lib/tasks/doc.rake
wd_sinatra-1.0.5 templates/lib/tasks/doc.rake
wd_sinatra-1.0.4 templates/lib/tasks/doc.rake
wd_sinatra-1.0.3 templates/lib/tasks/doc.rake
wd_sinatra-1.0.2 templates/lib/tasks/doc.rake
wd_sinatra-1.0.1 templates/lib/tasks/doc.rake
wd_sinatra-1.0.0 templates/lib/tasks/doc.rake
wd_sinatra-0.3.2 templates/lib/tasks/doc.rake
wd_sinatra-0.3.1 templates/lib/tasks/doc.rake
wd_sinatra-0.3.0 templates/lib/tasks/doc.rake
wd_sinatra-0.2.6 templates/lib/tasks/doc.rake
wd_sinatra-0.2.5 templates/lib/tasks/doc.rake
wd_sinatra-0.2.4 templates/lib/tasks/doc.rake
wd_sinatra-0.2.3 templates/lib/tasks/doc.rake
wd_sinatra-0.2.2 templates/lib/tasks/doc.rake
wd_sinatra-0.2.1 templates/lib/tasks/doc.rake
wd_sinatra-0.2.0 templates/lib/tasks/doc.rake
wd_sinatra-0.1.0 templates/lib/tasks/doc.rake
wd_sinatra-0.0.2 templates/lib/tasks/doc.rake
wd_sinatra-0.0.1 templates/lib/tasks/doc.rake