require 'application.rb' require 'http/http_provider.rb' require 'http/http_controller.rb' require 'lib/settings.rb' class HTTPAppSettingscontroller) if controller if controller.nil? controller||=mainController func,*dummy=req.path_info.sub(/^\//,'').split("/") end raise "NoController defined" if controller.nil? func||="index" path_rest=dummy l=controller.klass.new(self,instance) l.run(instance,res,func,args,path_rest,currentUrl) rescue Object=>e # maybe a file ? path=req.path_info log "PATH:",path #path=File.join(getAppDir,"static",path) log "PATH:",path unless render_static(res,path) path=path.gsub(/[^\/]*\//,'') unless render_static(res,path) raise e end end end end def findFile(fileName) f=File.join(getAppDir,fileName) return f if File.exists?(f) #f=File.join(getAppDir,"..",fileName) #return f if File.exists?(f) return nil end def render_static(res,filename) paths=[File.join(getAppDir,"static/"),File.expand_path('../static',__FILE__)] paths.each{|path| cp=File.join(path,filename) #cp=findFile(File.join("static",filename)) if cp and File.file?(cp) f=File.open(cp,"r") c=f.read f.close res.body=c res["Content-Type"]=case filename.gsub(/.*\./,"") when "css" "text/css" when "svg" "image/svg+xml" when "ico" "image/icon" else "text/plain" end return true end } false end def run # do nothing for mow end def instancesFor(provider,appName) instances=retrieveConfig[:instances].content if instances else if @instances instances=@instances.map{|i|[i,i]} else instances=[["defaultInstance",""]] end end instances.map{|instance| instanceName,url=instance [instanceName,"/"+appName+"/"+url] } end def url base="" base= @p.url if @p mc=mainController log "ControllerName #{mc} #{mc.urlPart}" log "BASE #{base}" return base+"/"+mc.urlPart if mc "/" end def serviceAddress(instance,path="") raise "Instance not found!" unless @instances.member?(instance) [getAppName,instance,path] end # FIXME def machine "localhost" end def stop @p.stop if @p.is_a?(HTTPProvider) end def halt @p.stop if @p.is_a?(HTTPProvider) end def getControllerPaths path=File.join(getAppDir,"controllers","*.rb") log "Controllers #{Dir[path]}" Dir[path] end def controllerName(controller) controller.gsub(/.*\//,"").gsub(".rb","").camelCase end def mainController cntrl=@controllers.select{|c|c.name.downcase==getAppName.downcase}[0] cntrl||@controllers[0] #FIXME: take controller with same name end def getController(hash) info=@controllers.select{|c| ok=true hash.each{|k,v| ok&=(c.send(k)==v) } ok }[0] return nil unless info info=loadController(info.filePath) if $DEBUGGING info end def loadController(controllerPath) log "Loading Controller #{controllerPath}" controllerName=controllerName(controllerPath) log controllerName controllerPrg=File.load(controllerPath) return unless controllerPrg log "OK loaded" self.class.send(:class_eval,controllerPrg) #create class klass=self.class.class_eval(controllerName) info=ControllerInfo.new(controllerName,klass,controllerPath,controllerName.underscored) @controllers<0 info end private def saveRunningInstances config=retrieveConfig config["instances"]=@instances end def runStoredInstances config=retrieveConfig inst=config["instances"].content if inst.is_a?(Array) inst.each{|i| @instances<