#!/usr/bin/env ruby require 'rbbt/util/simpleopt' require 'rbbt/workflow' 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*" template = ARGV.first template = template.sub('.haml','') ENV["RBBT_FINDER"] = "true" if options.include?(:finder) ENV["RServe-session"] = options[:RServe_session] raise rbbt_usage unless template $title = File.basename(template) load Rbbt.etc['app.d/init.rb'].find app = class SingleTemplate < Sinatra::Base; self end if options[:workflows] app.register Sinatra::RbbtRESTWorkflow options[:workflows].split(/[\s,]+/).each do |name| wf = Workflow.require_workflow name app.add_workflow wf, :all end end app.register Sinatra::RbbtRESTKnowledgeBase app.helpers Sinatra::RbbtMiscHelpers app.helpers Sinatra::RbbtToolHelper app.get '/' do template_render(template, @clean_params) 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 Sinatra::RbbtRESTMain.add_resource_path(Path.setup('/home/mvazquezg/'), true) SingleTemplate.port = options[:port] || 4567 SingleTemplate.bind = options[:bind] || "0.0.0.0" SingleTemplate.environment = options[:environment] || "development" SingleTemplate.server = options[:server] if options[:server] SingleTemplate.run!