Class: RequestHandler

Inherits:
Object
  • Object
show all
Includes:
CRUDRequest
Defined in:
lib/rack/app/request_handler.rb

Instance Method Summary collapse

Methods included from CRUDRequest

#create_for, #delete_for, #edit_for, #get_for, #new_for, #put_for, #show_for

Constructor Details

#initialize(env, params, url_params) ⇒ RequestHandler

Returns a new instance of RequestHandler.



4
5
6
7
8
# File 'lib/rack/app/request_handler.rb', line 4

def initialize env, params, url_params
  @env = env
  @params = params
  @url_params = url_params
end

Instance Method Details

#get_rack_crud_jsObject



16
17
18
19
# File 'lib/rack/app/request_handler.rb', line 16

def get_rack_crud_js
  ap Dir.pwd
  Response.ok_for File.read( "public/js/#{ @url_params[ :file ]}" )
end

#get_rack_crud_js_vendorObject



21
22
23
# File 'lib/rack/app/request_handler.rb', line 21

def get_rack_crud_js_vendor
  Response.ok_for File.read( "public/js/vendor/#{ @url_params[ :file ]}" )
end

#not_foundObject



10
11
12
13
14
# File 'lib/rack/app/request_handler.rb', line 10

def not_found
  raise "Not found: #{ @env[ 'REQUEST_PATH' ]}"

  Response.not_found_for '404: There is no route for your request.'
end

#render(model, page, data) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rack/app/request_handler.rb', line 25

def render model, page, data
  content_template = File.read "templates/#{ model }/#{ page }.mustache"
  content = Mustache.render( content_template, { data:data })

  page_template = File.read( 'templates/layout.mustache' )
  Mustache.render page_template, { content:content }
end