Class: Troy::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/troy/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}, config = {}) ⇒ Cli

Returns a new instance of Cli.



9
10
11
12
13
14
15
# File 'lib/troy/cli.rb', line 9

def initialize(args = [], options = {}, config = {})
  if (config[:current_task] || config[:current_command]).name == "new" && args.empty?
    raise Error, "The site path is required. For details run: troy help new"
  end

  super
end

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/troy/cli.rb', line 5

def self.exit_on_failure?
  true
end

Instance Method Details

#exportObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/troy/cli.rb', line 19

def export
  if options[:assets]
    site.export_assets
    site.export_files
  end

  if options[:file]
    options[:file].each do |file|
      site.export_pages(file)
    end
  end

  if !options[:assets] && !options[:file]
    site.export
  end
end

#new(path) ⇒ Object



37
38
39
40
41
# File 'lib/troy/cli.rb', line 37

def new(path)
  generator = Generator.new
  generator.destination_root = path
  generator.invoke_all
end

#serverObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/troy/cli.rb', line 52

def server
  begin
    handler = Rack::Handler::Thin
    Thin::Logging.level = Logger::DEBUG
  rescue Exception
    handler = Rack::Handler::WEBrick
  end

  handler.run Troy::Server.new(File.join(Dir.pwd, "public")), :Port => options[:port], :Host => options[:host]
end

#versionObject



45
46
47
# File 'lib/troy/cli.rb', line 45

def version
  say "Troy #{Troy::VERSION}"
end