class Fdoc::Cli
A Thor definition for an fdoc to HTML conversion operation
Attributes
origin_path[RW]
Public Class Methods
source_root()
click to toggle source
# File lib/fdoc/cli.rb, line 18 def self.source_root File.expand_path("../templates", __FILE__) end
Public Instance Methods
convert(fdoc_path)
click to toggle source
# File lib/fdoc/cli.rb, line 27 def convert(fdoc_path) say_status nil, "Converting fdoc to #{options[:format]}" self.origin_path = File.expand_path(fdoc_path) raise Fdoc::NotFound.new(origin_path) unless has_valid_origin? say_status :using, fdoc_path self.destination_root = output_path raise Fdoc::NotADirectory.new(output_path) unless has_valid_destination? say_status :inside, output_path if options[:format] == 'markdown' convert_to_markdown else convert_to_html end end
convert_to_html()
click to toggle source
# File lib/fdoc/cli.rb, line 46 def convert_to_html in_root do copy_file("styles.css") create_file("index.html", meta_presenter.to_html) if has_meta_service? end service_presenters.each do |service_presenter| inside_service_presenter(service_presenter) do create_file("index.html", service_presenter.to_html) service_presenter.endpoints.each do |endpoint_prefix_group| endpoint_prefix_group.each do |endpoint| create_file(endpoint.url, endpoint.to_html) end end end end end
convert_to_markdown()
click to toggle source
# File lib/fdoc/cli.rb, line 65 def convert_to_markdown in_root do create_file("index.md", meta_presenter.to_markdown) if has_meta_service? end service_presenters.each do |service_presenter| inside_service_presenter(service_presenter) do create_file("index.md", service_presenter.to_markdown) service_presenter.endpoints.each do |endpoint_prefix_group| endpoint_prefix_group.each do |endpoint| create_file(endpoint.url('.md'), endpoint.to_markdown) end end end end end
has_meta_service?()
click to toggle source
# File lib/fdoc/cli.rb, line 117 def has_meta_service? !meta_service.empty? end
has_valid_destination?()
click to toggle source
# File lib/fdoc/cli.rb, line 113 def has_valid_destination? !destination.exist? || destination.directory? end
has_valid_origin?()
click to toggle source
# File lib/fdoc/cli.rb, line 109 def has_valid_origin? origin.directory? end
html_options()
click to toggle source
# File lib/fdoc/cli.rb, line 127 def html_options { :static_html => true, :url_base_path => options[:url_base_path], :template_directory => template_path, :html_directory => destination_root } end
inside_service_presenter(service, &block)
click to toggle source
# File lib/fdoc/cli.rb, line 83 def inside_service_presenter(service, &block) if has_meta_service? inside(service.slug_name, {:verbose => true}, &block) else in_root(&block) end end
output_path()
click to toggle source
# File lib/fdoc/cli.rb, line 91 def output_path @output_path ||= if options[:output] File.expand_path(options[:output]) else File.expand_path("../#{options[:format]}", origin_path) end end
service_presenters()
click to toggle source
# File lib/fdoc/cli.rb, line 121 def service_presenters @service_presenters ||= services.map do |service| Fdoc::ServicePresenter.new(service, html_options) end end
template_path()
click to toggle source
# File lib/fdoc/cli.rb, line 100 def template_path @template_path ||= if options[:templates] File.expand_path(options[:templates]) else File.expand_path("../templates", origin_path) end end
Private Instance Methods
destination()
click to toggle source
# File lib/fdoc/cli.rb, line 163 def destination Pathname.new(destination_root) end
meta_presenter()
click to toggle source
# File lib/fdoc/cli.rb, line 148 def meta_presenter @meta_presenter ||= Fdoc::MetaServicePresenter.new( meta_service, html_options ) end
meta_service()
click to toggle source
# File lib/fdoc/cli.rb, line 155 def meta_service @meta_service ||= Fdoc::MetaService.new(origin_path) end
origin()
click to toggle source
# File lib/fdoc/cli.rb, line 159 def origin Pathname.new(origin_path) end
services()
click to toggle source
# File lib/fdoc/cli.rb, line 139 def services @services ||= if has_meta_service? meta_service.services else [Fdoc::Service.new(origin_path)] end end