#!/usr/bin/env ruby require 'rbbt/util/simpleopt' require 'rbbt/workflow' #require 'zurb-foundation' #require 'modular-scale' require 'rbbt/rest/main' require 'rbbt/rest/entity' require 'rbbt/rest/workflow' require 'rbbt/rest/file_server' require 'rbbt/rest/knowledge_base' require 'rbbt/rest/helpers' require 'rbbt/rest/web_tool' #options = SOPT.get "-e--environment*:-p--port*:-s--server*:-b--bind*:-e--environment*:-R--RServe_session*:--finder:--views*:-w--workflows*" options = SOPT.setup < -h--help Print this help -e--environment* Execution environment: production or development -b--bind* Bind to a particular IP (net interface) -p--port* TCP port -s--server* Server type: thin, webrick, unicorn, etc -f--finder Start server with finder functionality -R--Rserve_session* Rserve session to use, otherwise start new one -w--workflows* List of additional workflows to load --views* Directory with view templates EOF if options[:help] if defined? rbbt_usage rbbt_usage else puts SOPT.usage end exit 0 end workflow = ARGV.first ENV["RBBT_FINDER"] = "true" if options.include?(:finder) ENV["RServe-session"] = options[:RServe_session] || workflow raise rbbt_usage unless workflow wf = Workflow.require_workflow workflow $title = wf.to_s load Rbbt.etc['app.d/init.rb'].find app = class WorkflowRest < Sinatra::Base; self end app.register Sinatra::RbbtRESTWorkflow app.register Sinatra::MultiRoute app.register Sinatra::RbbtRESTKnowledgeBase app.helpers Sinatra::RbbtToolHelper app.get '/' do redirect to(File.join('/', wf.to_s)) end app.instance_eval Rbbt.etc['app.d/base.rb'].read app.use Rack::Deflater load Rbbt.etc['app.d/resources.rb'].find app.class_eval do eval Rbbt.etc['app.d/finder.rb'].read end WorkflowRest.add_workflow wf, :priority if options[:workflows] options[:workflows].split(/[\s,]+/).each do |name| _wf = Workflow.require_workflow name WorkflowRest.add_workflow _wf, true end end if options[:views] and not options[:views].empty? Sinatra::RbbtRESTMain.add_resource_path(Path.setup(options[:views]), true) end WorkflowRest.port = options[:port] || 4567 WorkflowRest.bind = options[:bind] || "0.0.0.0" WorkflowRest.environment = options[:environment] || "development" WorkflowRest.server = options[:server] if options[:server] WorkflowRest.run!