class Surfer::Application
Public Class Methods
check_route(cont)
click to toggle source
# File lib/surfer/routing.rb, line 37 def self.check_route (cont) puts "Inside" route = @@routes_controller.select{|f| f[:controller] == "#{cont}"} puts route cn = route[0] puts cn[:path] puts cn[:controller] puts cn[:action] end
display(arg)
click to toggle source
# File lib/surfer.rb, line 82 def self.display arg "Hello #{arg}" end
get(args)
click to toggle source
# File lib/surfer/routing.rb, line 33 def self.get args @@routes_controller<<args end
root(pth)
click to toggle source
# File lib/surfer.rb, line 54 def self.root(pth) @@default_path="" @@default_path=pth.split('#') puts @@default_path end
routing_config() { |self| ... }
click to toggle source
# File lib/surfer.rb, line 49 def self.routing_config puts "Inside routing_config" yield(self) end
Public Instance Methods
call(env)
click to toggle source
# File lib/surfer.rb, line 16 def call(env) if env['REQUEST_METHOD']=="GET" if env['PATH_INFO']=='/favicon.ico' page_not_found end if env['PATH_INFO']=='/' if(@@default_path=="default_home_page") # If no routes are mentioned in the routes.rb file default_home_page else klass, act , resource=custom_home_page controller = klass.new(env: env, controller: klass, action: act , resource: resource) d = controller.send(act) text = controller.render [200,{'Content-Type'=>'text/html'},[text]] end else klass, act , resource = get_controller_and_action(env) if(klass=="no_such_path"|| act == "no_such_action") page_not_found else controller = klass.new(env: env, controller: klass, action: act , resource: resource) d = controller.send(act) text = controller.render [200,{'Content-Type'=>'text/html'},[text]] end end else return[200,{'Content-Type'=>'text/html'},["POST not Yet Supported"]] end end
custom_home_page()
click to toggle source
# File lib/surfer.rb, line 60 def custom_home_page cont=@@default_path[0] action =@@default_path[1] autoload="#{cont}_controller" puts autoload # require "#{autoload}" cont = cont.capitalize [Object.const_get(cont+"Controller"), action, cont] end
default_home_page()
click to toggle source
# File lib/surfer.rb, line 76 def default_home_page pth=ROOT_PATH+"/public/index.html" content = File.read(pth) return[200,{'Content-Type'=>'text/html'},[content]] end
get_controller_and_action(env)
click to toggle source
# File lib/surfer/routing.rb, line 4 def get_controller_and_action(env) unwanted, cont, action, after = env["PATH_INFO"].split('/', 4) puts "Inside" puts cont route = @@routes_controller.select{|f| f[:path] == "#{cont}"} puts route.empty? if(route.empty?) return ["no_such_path","0","0"] else cn = route[0] puts "Requested Path = #{cn[:path]}" puts "Controller Called #{cn[:controller]}" puts "Action called #{cn[:action]}" # autoload="#{cn[:controller]}_controller" # puts "Controller FIle #{autoload}" # require "#{autoload}" cont = cn[:controller].capitalize # Capitalize Controller eg : Webonise if(action.nil?) action=cn[:action] end if(action!=cn[:action]) return ["0","no_such_action","0"] end # Append Controller eg : WeboniseController [Object.const_get(cont+"Controller"), action, cont] end end
page_not_found()
click to toggle source
# File lib/surfer.rb, line 70 def page_not_found pth=ROOT_PATH+"/public/page_not_found.html" content = File.read(pth) return [404,{'Content-Type'=>'text/html'},[content]] end