lib/lurker/cli.rb in lurker-0.5.3 vs lib/lurker/cli.rb in lurker-0.5.4
- old
+ new
@@ -1,9 +1,8 @@
require 'thor'
require 'digest/sha1'
require 'lurker/service'
-require 'lurker/meta_service'
module Lurker
# A Thor::Error to be thrown when an lurker directory is not found
class NotFound < Thor::Error; end
@@ -22,17 +21,17 @@
def self.precompiled_static_root
File.expand_path("../templates/public", __FILE__)
end
- desc "convert [LURKER_PATH]", "Convert lurker to HTML or Markdowns"
+ desc "convert [LURKER_PATH]", "Convert lurker to HTML"
method_option :rails, :type => :boolean, :desc => "Includes Rails environment"
method_option :exclude, :aliases => "-e", :desc => "Select endpoints by given regexp, if NOT matching prefix"
method_option :select, :aliases => "-s", :desc => "Select endpoints by given regexp, matching prefix"
method_option :output, :aliases => "-o", :desc => "Output path"
method_option :url_base_path, :aliases => "-u", :desc => "URL base path"
- method_option :format, :aliases => "-f", :desc => "Format in html or markdown, defaults to html", :default => "html"
+ method_option :format, :aliases => "-f", :desc => "Format in html or pdf, defaults to html", :default => "html"
method_option :templates, :aliases => "-t", :desc => "Template overrides path"
method_option :content, :aliases => "-c", :desc => "Content to be rendered into html-docs main page"
def convert(lurker_path=Lurker::DEFAULT_SERVICE_PATH)
say_status nil, "Converting lurker to #{options[:format]}"
@@ -47,18 +46,22 @@
if options[:rails]
require "#{Dir.pwd}/config/environment"
end
- if options[:format] == 'markdown'
- convert_to_markdown
+ if options[:format] == 'pdf'
+ convert_to_pdf
else
convert_to_html
end
end
no_tasks do
+ def convert_to_pdf
+ # TODO
+ end
+
def convert_to_html
in_root do
# js, css, fonts
Dir["#{self.class.precompiled_static_root}/*"].each do |fname|
if match = fname.match(/application\.(js|css)$/)
@@ -69,16 +72,14 @@
spawn "cat #{to} | gzip -9 > #{to}.gz"
else
FileUtils.cp_r fname, destination.to_s
end
end
-
- 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
+ in_root do
create_file("index.html", service_presenter.to_html, force: true)
service_presenter.endpoints.each do |endpoint_prefix_group|
endpoint_prefix_group.each do |endpoint_presenter|
create_file(endpoint_presenter.relative_path, endpoint_presenter.to_html, force: true)
@@ -86,36 +87,10 @@
end
end
end
end
- 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
-
- def inside_service_presenter(service, &block)
- if has_meta_service?
- inside(service.slug_name, {:verbose => true}, &block)
- else
- in_root(&block)
- end
- end
-
def output_path
@output_path ||=
if options[:output]
File.expand_path(options[:output])
else
@@ -138,14 +113,10 @@
def has_valid_destination?
!destination.exist? || destination.directory?
end
- def has_meta_service?
- !meta_service.empty?
- end
-
def service_presenters
@service_presenters ||= services.map do |service|
Lurker::ServicePresenter.new(service, html_options, &filtering_block)
end
end
@@ -192,26 +163,10 @@
''
end
end
def services
- @services ||=
- if has_meta_service?
- meta_service.services
- else
- [Lurker::Service.new(origin_path)]
- end
- end
-
- def meta_presenter
- @meta_presenter ||= Lurker::MetaServicePresenter.new(
- meta_service,
- html_options
- )
- end
-
- def meta_service
- @meta_service ||= Lurker::MetaService.new(origin_path)
+ @services ||= [Lurker::Service.new(origin_path)]
end
def origin
Pathname.new(origin_path)
end