Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/chrisboulton/clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Stevens authored and Jon Stevens committed Mar 17, 2011
2 parents 7dcbdf4 + 7ec3c51 commit 45af278
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions lib/clarity.rb
Expand Up @@ -18,6 +18,6 @@
module Clarity
VERSION = '0.9.8'

Templates = File.dirname(__FILE__) + '/../views'
Public = File.dirname(__FILE__) + '/../public'
Templates = File.expand_path(File.dirname(__FILE__) + '/../views')
Public = File.expand_path(File.dirname(__FILE__) + '/../public')
end
33 changes: 20 additions & 13 deletions lib/clarity/server/chunk_http.rb
@@ -1,11 +1,11 @@
require 'erb'

module Clarity

module ChunkHttp
LeadIn = ' ' * 1024

LeadIn = ' ' * 1024

def respond_with_chunks
response = EventMachine::DelegatedHttpResponse.new( self )
response.status = 200
Expand All @@ -23,7 +23,7 @@ def respond_with(status, content, options = {})
response.status = status
response.content = content
response.send_response
end
end

def render(view)
@toolbar = template("_toolbar.html.erb")
Expand All @@ -32,28 +32,35 @@ def render(view)
end

def template(filename)
content = File.read( File.join(Clarity::Templates, filename) )
content = File.read( File.join(Clarity::Templates, filename) )
ERB.new(content).result(binding)
end

def public_file(filename)
File.read( File.join(Clarity::Public, filename) )
rescue Errno::ENOENT
raise NotFoundError
path = File.expand_path(File.join(Clarity::Public, filename))
raise NotFoundError unless path[0, Clarity::Public.length] == Clarity::Public
raise NotFoundError unless File.file?(path)
File.read(path)
end

def logfiles
log_files.map {|f| Dir[f] }.flatten.compact.uniq.select{|f| File.file?(f) }.sort
end

def params
ENV['QUERY_STRING'].split('&').inject({}) {|p,s| k,v = s.split('=');p[k.to_s] = CGI.unescape(v.to_s);p}
end
end

def path
ENV["PATH_INFO"]
end


def json_encode(obj)
obj.to_json.
gsub('>', '\u003E').
gsub('<', '\u003C')
end

end

end
4 changes: 2 additions & 2 deletions views/_toolbar.html.erb
Expand Up @@ -53,12 +53,12 @@
<li><input type='checkbox' name='enable_scrolling' id='auto-scroll'/><span> Auto scroll?</span></li>
</ul>
</div>

<script>
Search.url = "<%= relative_root %>" + Search.url;
Search.init({ 'grep': <%= logfiles.map {|f| f }.to_json %>,
'tail': <%= logfiles.map {|f| f }.to_json %> },
<%= params.empty? ? 'null' : params.to_json %> );
<%= params.empty? ? 'null' : json_encode(params) %> );


</script>

0 comments on commit 45af278

Please sign in to comment.