Module: Clarity::ChunkHttp

Included in:
Server
Defined in:
lib/clarity/server/chunk_http.rb

Constant Summary collapse

LeadIn =
' ' * 1024

Instance Method Summary collapse

Instance Method Details

#logfilesObject



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

#paramsObject



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

#pathObject



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, options = {})
  response = EventMachine::DelegatedHttpResponse.new( self )
  response.headers['Content-Type'] = options.fetch(:content_type, 'text/html')
  response.headers['Cache-Control'] = 'private, max-age=0'
  headers = options.fetch(:headers, {})
  headers.each_pair {|h, v| response.headers[h] = v }
  response.status  = status
  response.content = content
  response.send_response
end

#respond_with_chunksObject



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

#template(filename) ⇒ Object



34
35
36
37
# File 'lib/clarity/server/chunk_http.rb', line 34

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