Module: Clarity::ChunkHttp
- Included in:
- Server
- Defined in:
- lib/clarity/server/chunk_http.rb
Constant Summary collapse
- LeadIn =
' ' * 1024
Instance Method Summary collapse
- #logfiles ⇒ Object
- #params ⇒ Object
- #path ⇒ Object
- #public_file(filename) ⇒ Object
- #render(view) ⇒ Object
- #respond_with(status, content, options = {}) ⇒ Object
- #respond_with_chunks ⇒ Object
- #template(filename) ⇒ Object
Instance Method Details
#logfiles ⇒ Object
45 46 47 |
# File 'lib/clarity/server/chunk_http.rb', line 45 def logfiles log_files.map {|f| Dir[f] }.flatten.compact.uniq.select{|f| File.file?(f) }.sort end |
#params ⇒ Object
49 50 51 |
# File 'lib/clarity/server/chunk_http.rb', line 49 def params ENV['QUERY_STRING'].split('&').inject({}) {|p,s| k,v = s.split('=');p[k.to_s] = CGI.unescape(v.to_s);p} end |
#path ⇒ Object
53 54 55 |
# File 'lib/clarity/server/chunk_http.rb', line 53 def path ENV["PATH_INFO"] end |
#public_file(filename) ⇒ Object
39 40 41 42 43 |
# File 'lib/clarity/server/chunk_http.rb', line 39 def public_file(filename) File.read( File.join(Clarity::Public, filename) ) rescue Errno::ENOENT raise NotFoundError end |
#render(view) ⇒ Object
28 29 30 31 32 |
# File 'lib/clarity/server/chunk_http.rb', line 28 def render(view) @toolbar = template("_toolbar.html.erb") @content_for_header = template("_header.html.erb") template(view) end |
#respond_with(status, content, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/clarity/server/chunk_http.rb', line 17 def respond_with(status, content, = {}) response = EventMachine::DelegatedHttpResponse.new( self ) response.headers['Content-Type'] = .fetch(:content_type, 'text/html') response.headers['Cache-Control'] = 'private, max-age=0' headers = .fetch(:headers, {}) headers.each_pair {|h, v| response.headers[h] = v } response.status = status response.content = content response.send_response end |
#respond_with_chunks ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/clarity/server/chunk_http.rb', line 9 def respond_with_chunks response = EventMachine::DelegatedHttpResponse.new( self ) response.status = 200 response.headers['Content-Type'] = 'text/html' response.chunk LeadIn response end |