Class: Webgen::CLI::WebguiCommand

Inherits:
CmdParse::Command
  • Object
show all
Defined in:
lib/webgen/cli/webgui_command.rb

Overview

The CLI command for starting the webgen webgui.

Instance Method Summary collapse

Constructor Details

#initializeWebguiCommand

:nodoc:



11
12
13
14
# File 'lib/webgen/cli/webgui_command.rb', line 11

def initialize # :nodoc:
  super('webgui', false)
  self.short_desc = 'Starts the webgen webgui'
end

Instance Method Details

#execute(args) ⇒ Object

Render the website.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/webgen/cli/webgui_command.rb', line 17

def execute(args)
  # some fixes for ramaze-2009.04
  # - fix for Windows when win32console is not installed
  # - fix for message displayed on shutdown
  # - fix for warning message
  $:.unshift File.join(Webgen.data_dir, 'webgui', 'overrides')
  require 'win32console'
  $:.shift
  silence_warnings do
    begin
      require 'ramaze/snippets/object/__dir__'
      Object.__send__(:include, Ramaze::CoreExtensions::Object)
      require 'ramaze'
    rescue LoadError
      puts "The Ramaze web framework which is needed for the webgui was not found."
      puts "You can install it via 'gem install ramaze --version 2009.04'"
      return
    end
  end
  def Ramaze.shutdown; # :nodoc:
  end

  require File.join(Webgen.data_dir, 'webgui', 'app.rb')
  Ramaze::Log.loggers = []
  Ramaze.options[:middleware_compiler]::COMPILED[:dev].middlewares.delete_if do |app, args, block|
    app == Rack::CommonLogger
  end

  puts 'Starting webgui on http://localhost:7000, press Control-C to stop'

  Thread.new do
    begin
      require 'launchy'
      sleep 1
      puts 'Launching web browser'
      Launchy.open('http://localhost:7000')
    rescue LoadError
      puts "Can't open browser because the launchy library was not found."
      puts "You can install it via 'gem install launchy'"
      puts "Please open a browser window and enter 'http://localhost:7000' into the address bar!"
    end
  end

  Ramaze.start(:adapter => :webrick, :port => 7000, :file => File.join(Webgen.data_dir, 'webgui', 'app.rb'))
  puts 'webgui finished'
end