Class: Egalite::Controller

Inherits:
Object show all
Defined in:
lib/egalite.rb

Constant Summary collapse

MIME_TYPES =

From WEBrick.

{
  "ai"    => "application/postscript",
  "asc"   => "text/plain",
  "avi"   => "video/x-msvideo",
  "bin"   => "application/octet-stream",
  "bmp"   => "image/bmp",
  "class" => "application/octet-stream",
  "cer"   => "application/pkix-cert",
  "crl"   => "application/pkix-crl",
  "crt"   => "application/x-x509-ca-cert",
 #"crl"   => "application/x-pkcs7-crl",
  "css"   => "text/css",
  "dms"   => "application/octet-stream",
  "doc"   => "application/msword",
  "dvi"   => "application/x-dvi",
  "eps"   => "application/postscript",
  "etx"   => "text/x-setext",
  "exe"   => "application/octet-stream",
  "gif"   => "image/gif",
  "htm"   => "text/html",
  "html"  => "text/html",
  "jpe"   => "image/jpeg",
  "jpeg"  => "image/jpeg",
  "jpg"   => "image/jpeg",
  "js"    => "text/javascript",
  "lha"   => "application/octet-stream",
  "lzh"   => "application/octet-stream",
  "mov"   => "video/quicktime",
  "mpe"   => "video/mpeg",
  "mpeg"  => "video/mpeg",
  "mpg"   => "video/mpeg",
  "pbm"   => "image/x-portable-bitmap",
  "pdf"   => "application/pdf",
  "pgm"   => "image/x-portable-graymap",
  "png"   => "image/png",
  "pnm"   => "image/x-portable-anymap",
  "ppm"   => "image/x-portable-pixmap",
  "ppt"   => "application/vnd.ms-powerpoint",
  "ps"    => "application/postscript",
  "qt"    => "video/quicktime",
  "ras"   => "image/x-cmu-raster",
  "rb"    => "text/plain",
  "rd"    => "text/plain",
  "rtf"   => "application/rtf",
  "sgm"   => "text/sgml",
  "sgml"  => "text/sgml",
  "tif"   => "image/tiff",
  "tiff"  => "image/tiff",
  "txt"   => "text/plain",
  "xbm"   => "image/x-xbitmap",
  "xls"   => "application/vnd.ms-excel",
  "xml"   => "text/xml",
  "xpm"   => "image/x-xpixmap",
  "xwd"   => "image/x-xwindowdump",
  "zip"   => "application/zip",
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#envObject

Returns the value of attribute env.



150
151
152
# File 'lib/egalite.rb', line 150

def env
  @env
end

#log_valuesObject

Returns the value of attribute log_values.



150
151
152
# File 'lib/egalite.rb', line 150

def log_values
  @log_values
end

#paramsObject

Returns the value of attribute params.



150
151
152
# File 'lib/egalite.rb', line 150

def params
  @params
end

#reqObject

Returns the value of attribute req.



150
151
152
# File 'lib/egalite.rb', line 150

def req
  @req
end

#template_fileObject

Returns the value of attribute template_file.



150
151
152
# File 'lib/egalite.rb', line 150

def template_file
  @template_file
end

Instance Method Details

#after_filter(response) ⇒ Object

after filter for final http output



163
164
165
# File 'lib/egalite.rb', line 163

def after_filter(response) # after filter for final http output
  response
end

#after_filter_html(response) ⇒ Object

html after template filter



160
161
162
# File 'lib/egalite.rb', line 160

def after_filter_html(response) # html after template filter
  response
end

#after_filter_return_value(response) ⇒ Object

right after controller



157
158
159
# File 'lib/egalite.rb', line 157

def after_filter_return_value(response) # right after controller
  response
end

#before_filterObject

filters



154
155
156
# File 'lib/egalite.rb', line 154

def before_filter
  true
end

#cookiesObject



174
175
176
# File 'lib/egalite.rb', line 174

def cookies
  @req.cookies
end

#dbObject

accessors



171
172
173
# File 'lib/egalite.rb', line 171

def db
  @env.db
end

#delegate(params) ⇒ Object



199
200
201
# File 'lib/egalite.rb', line 199

def delegate(params)
  EgaliteResponse.new(:delegate, params)
end

#errorlog(severity, text) ⇒ Object



252
253
254
255
# File 'lib/egalite.rb', line 252

def errorlog(severity, text)
  logid = Egalite::ErrorLogger.write(:severity => severity, :ipaddress => @req.ipaddr, :text => text, :url => @req.url)
  logid
end

#escape_html(s) ⇒ Object



237
238
239
# File 'lib/egalite.rb', line 237

def escape_html(s)
  tags.escape_html(s)
end

#file_form(data = {}, param_name = nil, opts = {}) ⇒ Object



249
250
251
# File 'lib/egalite.rb', line 249

def file_form(data={},param_name = nil, opts = {})
  FormHelper.new(data,param_name,opts.merge(:enctype => 'multipart/form-data'))
end

#filter_on_html_load(html, htmlfile) ⇒ Object



166
167
168
# File 'lib/egalite.rb', line 166

def filter_on_html_load(html, htmlfile)
  html
end

#form(data = {}, param_name = nil, opts = {}) ⇒ Object



246
247
248
# File 'lib/egalite.rb', line 246

def form(data={},param_name = nil, opts = {})
  FormHelper.new(data,param_name,opts)
end

#idObject



180
181
182
# File 'lib/egalite.rb', line 180

def id
  @params[:id]
end

#include(params) ⇒ Object



202
203
204
# File 'lib/egalite.rb', line 202

def include(params)
  raw(req.handler.inner_dispatch(req, params)[2].join)
end


230
231
232
233
# File 'lib/egalite.rb', line 230

def link_to(title,prms)
  return tags.a(prms,title) if prms.is_a?(String)
  raw(@req.route.link_to(title,prms, req.host, req.port, req.scheme))
end

#notfoundObject

results



185
186
187
# File 'lib/egalite.rb', line 185

def notfound
  EgaliteResponse.new(:notfound)
end

#raw(text) ⇒ Object



234
235
236
# File 'lib/egalite.rb', line 234

def raw(text)
  NonEscapeString.new(text)
end

#redirect(url) ⇒ Object Also known as: redirect_to



188
189
190
191
# File 'lib/egalite.rb', line 188

def redirect(url)
  url = url_for(url) if url.is_a?(Hash)
  EgaliteResponse.new(:redirect, url)
end

#redirect_permanent(url) ⇒ Object



194
195
196
197
# File 'lib/egalite.rb', line 194

def redirect_permanent(url)
  url = url_for(url) if url.is_a?(Hash)
  [301,{'Location' => url}, [url]]
end

#send_data(data, content_type) ⇒ Object



222
223
224
# File 'lib/egalite.rb', line 222

def send_data(data, content_type)
  [200,{"Content-Type" => content_type},[data]]
end

#send_file(path, content_type = nil) ⇒ Object



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/egalite.rb', line 205

def send_file(path, content_type = nil)
  ext = File.extname(path)[1..-1]

  if File.file?(path) && File.readable?(path)
    s = nil
    open(path, "rb") { |file|
      s = file.read
    }
    return [200, {
       "Last-Modified"  => File.mtime(path).rfc822,
       "Content-Type"   => content_type || MIME_TYPES[ext] || "text/plain",
       "Content-Length" => File.size(path).to_s
     }, [s]]
  else
    return [404, {"Content-Type" => "text/plain"}, ["File not found\n"]]
  end
end

#sessionObject



177
178
179
# File 'lib/egalite.rb', line 177

def session
  @req.session
end

#table_by_array(header, content, opts = {}) ⇒ Object



243
244
245
# File 'lib/egalite.rb', line 243

def table_by_array(header,content,opts={})
  TableHelper.table_by_array(header,content,opts)
end

#tagsObject



240
241
242
# File 'lib/egalite.rb', line 240

def tags
  HTMLTagBuilder
end

#url_for(prms) ⇒ Object

helpers



227
228
229
# File 'lib/egalite.rb', line 227

def url_for(prms)
  @req.route.url_for(prms, req.host, req.port, req.scheme)
end