Class: Troy::Cli
- Inherits:
-
Thor
- Object
- Thor
- Troy::Cli
- Defined in:
- lib/troy/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #export ⇒ Object
-
#initialize(args = [], options = {}, config = {}) ⇒ Cli
constructor
A new instance of Cli.
- #new(path) ⇒ Object
- #server ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(args = [], options = {}, config = {}) ⇒ Cli
Returns a new instance of Cli.
11 12 13 14 15 16 17 |
# File 'lib/troy/cli.rb', line 11 def initialize(args = [], = {}, 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
7 8 9 |
# File 'lib/troy/cli.rb', line 7 def self.exit_on_failure? true end |
Instance Method Details
#export ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/troy/cli.rb', line 23 def export runner = lambda do if [:assets] site.export_assets site.export_files end [:file]&.each do |file| site.export_pages(file) end site.export if ![:assets] && ![:file] end if [:benchmark] require "benchmark" elapsed = Benchmark.realtime(&runner) puts "=> Finished in #{elapsed.round(2)}s" else runner.call end end |
#new(path) ⇒ Object
47 48 49 50 51 |
# File 'lib/troy/cli.rb', line 47 def new(path) generator = Generator.new generator.destination_root = path generator.invoke_all end |
#server ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/troy/cli.rb', line 62 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: [:port], Host: [:host] end |