Class: Lurker::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/lurker/cli.rb

Overview

A Thor definition for an lurker to HTML conversion operation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



18
19
20
# File 'lib/lurker/cli.rb', line 18

def content
  @content
end

Class Method Details

.assets_rootObject



24
25
26
# File 'lib/lurker/cli.rb', line 24

def self.assets_root
  options[:assets].present? ? Pathname.new(options[:assets]).expand_path : Lurker::BUNDLED_ASSETS_PATH
end

.templates_rootObject



20
21
22
# File 'lib/lurker/cli.rb', line 20

def self.templates_root
  options[:template].present? ? Pathname.new(options[:templates]).expand_path : Lurker::BUNDLED_TEMPLATES_PATH
end

Instance Method Details

#convert(lurker_path = Lurker::DEFAULT_SERVICE_PATH) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/lurker/cli.rb', line 55

def convert(lurker_path=Lurker::DEFAULT_SERVICE_PATH)
  say_status nil, "Converting lurker to #{options[:format]}"

  setup_schema_root! lurker_path
  require "#{Dir.pwd}/config/environment" if options[:rails]

  # for backward compatibility
  if options[:content]
    Lurker.service.documentation = open(File.expand_path(options[:content])).read
  end

  setup_rendering_engine!

  inside(output_path) do
    say_status :inside, output_path
    prepare_assets!
    if options[:format] == 'pdf'
      convert_to_pdf
    else
      convert_to_html
    end
    cleanup_assets!
  end
end

#init_docs(lurker_path = Lurker::DEFAULT_SERVICE_PATH) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lurker/cli.rb', line 32

def init_docs(lurker_path=Lurker::DEFAULT_SERVICE_PATH)
  say_status nil, 'Creating documentation stubs'

  setup_schema_root! lurker_path

  schemas = Lurker.service.endpoints.map(&:schema) << Lurker.service.schema
  schemas.each do |schema|
    rel_path = Pathname.new(schema.documentation_uri).relative_path_from(Pathname.getwd)
    template 'documentation.md.tt', schema.documentation_uri, skip: true, path: rel_path
  end
end