Browse files

Adds ability to configure web port for front-end

  • Loading branch information...
1 parent 3cd7ac7 commit 25722154a377372bdffaa80c1761563dbbbb1f58 @nesquena committed Dec 30, 2011
View
8 lib/gitdocs.rb
@@ -18,10 +18,12 @@ module Gitdocs
DEBUG = ENV['DEBUG']
- def self.start(config_root = nil, debug = DEBUG, &blk)
+ # Gitdocs.start(:config_root => "...", :debug => true)
+ def self.start(options={}, &blk)
+ options = { :debug => DEBUG, :config_root => nil }.merge(options)
@manager.stop if @manager
- @manager = Manager.new(config_root, debug, &blk)
- @manager.start
+ @manager = Manager.new(options[:config_root], options[:debug], &blk)
+ @manager.start(options[:port])
end
def self.restart
View
5 lib/gitdocs/cli.rb
@@ -8,13 +8,14 @@ def self.source_root; File.expand_path('../../', __FILE__); end
desc "start", "Starts a daemonized gitdocs process"
method_option :debug, :type => :boolean, :aliases => "-D"
+ method_option :port, :type => :string, :aliases => "-p"
def start
if self.stopped? && !options[:debug]
- self.runner.execute { Gitdocs.start }
+ self.runner.execute { Gitdocs.start(:port => options[:port]) }
self.running? ? say("Started gitdocs", :green) : say("Failed to start gitdocs", :red)
elsif self.stopped? && options[:debug]
say "Starting in debug mode", :yellow
- Gitdocs.start(nil, true)
+ Gitdocs.start(:debug => true, :port => options[:port])
else # already running
say "Gitdocs is already running, please use restart", :red
end
View
2 lib/gitdocs/configuration.rb
@@ -35,7 +35,7 @@ def available_branches
end
class Config < ActiveRecord::Base
- attr_accessible :load_browser_on_startup, :start_web_frontend
+ attr_accessible :load_browser_on_startup, :start_web_frontend, :web_frontend_port
end
def add_path(path, opts = nil)
View
9 lib/gitdocs/manager.rb
@@ -23,7 +23,7 @@ def search(term)
results
end
- def start
+ def start(web_port=nil)
self.log "Starting Gitdocs v#{VERSION}..."
self.log "Using configuration root: '#{self.config.config_root}'"
self.log "Shares: #{config.shares.map(&:inspect).join(", ")}"
@@ -41,20 +41,21 @@ def start
@runners.each(&:run)
# Start the web front-end
if self.config.global.start_web_frontend
- Server.new(self, *@runners).start
+ web_port ||= self.config.global.web_frontend_port
+ Server.new(self, *@runners).start(web_port.to_i)
EM.defer( proc {
i = 0
web_started = false
begin
- TCPSocket.open('127.0.0.1', 8888).close
+ TCPSocket.open('127.0.0.1', web_port.to_i).close
web_started = true
rescue Errno::ECONNREFUSED
self.log "Retrying server loop..."
sleep 0.2
i += 1
retry if i <= 20
end
- system("open http://localhost:8888/") if !retrying && self.config.global.load_browser_on_startup && web_started
+ system("open http://localhost:#{web_port}/") if !retrying && self.config.global.load_browser_on_startup && web_started
}, proc {
self.log "Web server running!"
})
View
9 lib/gitdocs/migration/006_add_web_port_to_config.rb
@@ -0,0 +1,9 @@
+class AddWebPortToConfig < ActiveRecord::Migration
+ def self.up
+ add_column :configs, :web_frontend_port, :integer, :default => 8888
+ end
+
+ def self.down
+ raise
+ end
+end
View
11 lib/gitdocs/views/settings.haml
@@ -3,9 +3,14 @@
%form#settings{:method => 'POST', :action => '/settings'}
%h2 Gitdocs
#config.field.config
- %input{:type =>'hidden', :value => '0', :name=>"config[load_browser_on_startup]"}
- %input{:type =>'checkbox', :value => '1', :name=>"config[load_browser_on_startup]", :checked => conf.global.load_browser_on_startup ? 'checked' : nil}
- %span Open browser on startup?
+ %dl
+ %dt Web Frontend Port
+ %dd
+ %input{:type =>'input', :name=>"config[web_frontend_port]", :value => conf.global.web_frontend_port }
+ %p
+ %input{:type =>'hidden', :value => '0', :name=>"config[load_browser_on_startup]"}
+ %input{:type =>'checkbox', :value => '1', :name=>"config[load_browser_on_startup]", :checked => conf.global.load_browser_on_startup ? 'checked' : nil}
+ %span Open browser on startup?
%h2 Shares
- conf.shares.each_with_index do |share, idx|
View
2 test/test_helper.rb
@@ -31,7 +31,7 @@ def with_clones(count = 3)
end
begin
puts "RUNNING!"
- Gitdocs.start(conf_path) do |conf|
+ Gitdocs.start(:config_path => conf_path) do |conf|
conf.global.update_attributes(:load_browser_on_startup => false, :start_web_frontend => false)
conf.add_path(path, :polling_interval => 0.1, :notification => false)
end

0 comments on commit 2572215

Please sign in to comment.