Permalink
Browse files

work with a relative root

  • Loading branch information...
1 parent fe67b30 commit 85f01152a979600717b59c81794b30afb2b54804 @kastner kastner committed with Dec 10, 2009
Showing with 24 additions and 7 deletions.
  1. +2 −0 .gitignore
  2. +3 −0 Gemfile
  3. +5 −0 lib/clarity.rb
  4. +6 −1 lib/clarity/cli.rb
  5. +3 −2 lib/clarity/server.rb
  6. +3 −3 views/_header.html.erb
  7. +2 −1 views/_toolbar.html.erb
View
@@ -1,3 +1,5 @@
config/config.yml
.DS_Store
pkg
+vendor/gems
+bin/*_json.rb
View
@@ -0,0 +1,3 @@
+gem "eventmachine"
+gem "eventmachine_httpserver"
+gem "json"
View
@@ -1,5 +1,10 @@
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
+begin
+ require File.join(File.dirname(__FILE__), *%w[.. vendor gems environment])
+rescue LoadError
+end
+
require 'eventmachine'
require 'evma_httpserver'
require 'json'
View
@@ -11,7 +11,8 @@ def self.execute(stdout, arguments=[])
:port => 8080,
:address => "0.0.0.0",
:user => nil,
- :group => nil
+ :group => nil,
+ :relative_root => nil
}
mandatory_options = %w( )
@@ -37,6 +38,10 @@ def self.execute(stdout, arguments=[])
options[:address] = opt
end
+ opts.on( "-r", "--relative=ROOT", String, "Run under a relative root" ) do |opt|
+ options[:relative_root] = opt
+ end
+
opts.on( "--include=MASK", String, "File mask of logs to add (default: **/*.log*)" ) do |opt|
options[:log_files] ||= []
options[:log_files] += opt
@@ -15,7 +15,7 @@ module Server
include Clarity::BasicAuth
include Clarity::ChunkHttp
- attr_accessor :required_username, :required_password
+ attr_accessor :required_username, :required_password, :relative_root
attr_accessor :log_files
def self.run(options)
@@ -26,6 +26,7 @@ def self.run(options)
a.log_files = options[:log_files]
a.required_username = options[:username]
a.required_password = options[:password]
+ a.relative_root = options[:relative_root] || ""
end
STDERR.puts "Clarity #{Clarity::VERSION} starting up."
@@ -73,7 +74,7 @@ def process_http_request
end
when '/test'
- response = init_chunk_response
+ response = respond_with_chunks
EventMachine::add_periodic_timer(1) do
response.chunk "Lorem ipsum dolor sit amet<br/>"
response.send_chunks
@@ -1,5 +1,5 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
-<title>Clarity ~ A Log Search Tool</title>
-<link rel="stylesheet" href="/stylesheets/app.css" type="text/css" media="screen">
+<title>Clarity ~ A Log Search Tool<%= relative_root %></title>
+<link rel="stylesheet" href="<%= relative_root %>/stylesheets/app.css" type="text/css" media="screen">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
-<script src="/javascripts/app.js" type="text/javascript"></script>
+<script src="<%= relative_root %>/javascripts/app.js" type="text/javascript"></script>
@@ -3,7 +3,7 @@
<h1><a href="/">Clarity</a> <span class='small' style='color:#aaa'>Log Search Tool</span></h1>
</div>
- <form id='search' method='get' action='/perform'>
+ <form id='search' method='get' action='<%= relative_root %>/perform'>
<table class='actions'>
<tr>
<th>Action</th>
@@ -55,6 +55,7 @@
</div>
<script>
+ Search.url = "<%= relative_root %>" + Search.url;
Search.init({ 'grep': <%= logfiles.map {|f| f }.to_json %>,
'tail': <%= logfiles.map {|f| f if f =~ /log$/ }.compact.to_json %> },
<%= params.empty? ? 'null' : params.to_json %> );

0 comments on commit 85f0115

Please sign in to comment.