App = Fanforce::App AppWorker = Fanforce::AppWorker ######################################################################################################################## class Fanforce::App::Sinatra < Sinatra::Base require 'sinatra/content_for' require 'bugsnag' require_relative 'error_handling' require_relative 'helpers/assets' require_relative 'helpers/ractive' require_relative 'helpers/json' require_relative 'helpers/fanforce' require_relative 'helpers/css_frameworks' use Rack::JSONR, :method_override => :all use Bugsnag::Rack helpers AssetHelpers helpers FanforceHelpers helpers JSONHelpers helpers RactiveHelpers helpers Sinatra::ContentFor @@static_files = {} def self.any(url,&block) get(url, &block) put(url, &block) post(url, &block) delete(url, &block) end def self.require_controllers require "#{Fanforce::App.config.factory_dir}/controllers/base_controller" Dir["#{Fanforce::App.config.base_dir}/controllers/*_controller.rb"].each {|file| require file } end def self.create_basic_routes_from(path) path = ('views/' + path.to_s.gsub(/^views\/?/, '')).gsub(/\/$/, '') Dir["#{Fanforce::App.config.base_dir}/#{path}/*/*.haml"].each do |file| create_basic_route($1) if file =~ /\/views\/(.+).haml/ end end def self.create_basic_routes_from_views create_basic_routes_from(:views) end def self.create_basic_route(path) get "/#{path}" do page(path) end end def self.static(url, *args, &block) @@static_files[url] = {args: args, block: block} get(url, &block) end def factory_directive(page) factory_dir = Pathname.new(Fanforce::App.config.factory_dir) app_views_dir = Pathname.new(settings.views) haml :"#{factory_dir.relative_path_from(app_views_dir).to_s}/directive_views/#{page}" end def page(page, options={}) app_views_dir = Pathname.new(settings.views) page = :"#{options[:com_dir]}/#{page}" if File.exists?("#{app_views_dir}/#{options[:com_dir]}/#{page}.haml") options[:layout] = options[:layout] ? :"../layouts/#{options[:layout]}" : false locals = {page_classes: page.to_s.split('/')} haml page.to_sym, options, locals end configure do Fanforce::App.config.load_bugsnag Fanforce::App.config.load_routes set :root, Fanforce::App.config.base_dir set :haml, {escape_attrs: false} set :static, true set :protection, :except => [:frame_options, :json_csrf] end get '/' do "#{Fanforce::App._id} is ready to go! All you need are a few routes." end end