Sha256: 7119f4b17ff2e0d6a2413175a4a549227027867894ba1dbe30c68f35ace61f0a

Contents?: true

Size: 1.98 KB

Versions: 7

Compression:

Stored size: 1.98 KB

Contents

#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__), '../lib/fdoc')

if ARGV.length < 2
  exec_name = File.basename($0)
  abort "Usage: #{exec_name} [fdoc_directory] [html_directory] (url_base_path)"
end

fdoc_directory, html_directory, url_base_path = ARGV[0..2]
fdoc_directory = File.expand_path(fdoc_directory)
html_directory = File.expand_path(html_directory)

html_options = {
  :html_directory => html_directory,
  :static_html => true,
  :url_base_path => url_base_path
}

def mkdir(dirname)
  `mkdir -p #{dirname}` unless File.directory?(dirname)
end

mkdir(html_directory)

meta_service = Fdoc::MetaService.new(fdoc_directory)
services = if !meta_service.empty?
  meta_service.services
else
  Array(Fdoc::Service.new(fdoc_directory))
end

if !meta_service.empty?
  meta_service_presenter= Fdoc::MetaServicePresenter.new(
    meta_service, html_options
  )

  index_html_path = File.join(html_directory, "index.html")
  File.open(index_html_path, "w") do |file|
    file.write(meta_service_presenter.to_html)

    puts "created #{index_html_path}"
  end
end

css_path = File.join(File.dirname(__FILE__), '../lib/fdoc/templates/styles.css')
`cp "#{css_path}" "#{html_directory}"`
puts "created #{File.expand_path(css_path)}"

services.each do |service|
  service_presenter = Fdoc::ServicePresenter.new(service, html_options)
  html_sub_directory = if meta_service.empty?
    html_directory
  else
    File.join(html_directory, service_presenter.slug_name)
  end
  
  mkdir(html_sub_directory)

  index_html_path = File.join(html_sub_directory, "index.html")
  File.open(index_html_path, "w") do |file|
    file.write(service_presenter.to_html)

    puts "created #{index_html_path}"
  end

  service_presenter.endpoints.flatten.each do |endpoint|
    endpoint_html_path = File.join(html_sub_directory, endpoint.url)
    mkdir(File.dirname(endpoint_html_path))

    File.open(endpoint_html_path, "w") do |file|
      file.write(endpoint.to_html)

      puts "created #{endpoint_html_path}"
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fdoc-0.2.7 bin/fdoc_to_html
fdoc-0.2.6 bin/fdoc_to_html
fdoc-0.2.5 bin/fdoc_to_html
fdoc-0.2.4 bin/fdoc_to_html
fdoc-0.2.3 bin/fdoc_to_html
fdoc-0.2.2 bin/fdoc_to_html
fdoc-0.2.1 bin/fdoc_to_html