require 'sinatra/content_for' require 'bugsnag' #################################################################################### class FanforceApp::Sinatra < Sinatra::Base require_relative 'config/_error_handling' require_relative 'config/helpers/assets' require_relative 'config/helpers/ractive' require_relative 'config/helpers/json' require_relative 'config/helpers/fanforce' use Rack::JSONR, :method_override => :all use Bugsnag::Rack helpers Sinatra::AssetHelpers helpers Sinatra::RactiveHelpers helpers Sinatra::JSONHelpers helpers Sinatra::FanforceHelpers helpers Sinatra::ContentFor def self.any(url,&block) get(url, &block) put(url, &block) post(url, &block) delete(url, &block) end def self.default_javascript_package(package_name) end def self.require_controllers require "#{FanforceApp.config.factory_root_dir}/controllers/base_controller" Dir["#{FanforceApp.config.root_dir}/controllers/*_controller.rb"].each {|f| require f } end @@static_files = {} def self.static(url, *args, &block) @@static_files[url] = {args: args, block: block} get(url, &block) end def page(page, options={}) gem_dir = Pathname.new(File.expand_path('../', __FILE__)) app_dir = Pathname.new(File.expand_path('../', settings.views)) app_views_dir = Pathname.new(settings.views) gem_rel_dir = gem_dir.relative_path_from(app_views_dir).to_s gem_abs_dir = File.expand_path(gem_rel_dir, app_views_dir) if !File.exists?("#{app_dir}/views/#{page}.haml") if File.exists?("#{app_dir}/views/#{options[:com_dir]}/#{page}.haml") page_path = :"#{options[:com_dir]}/#{page}" else page_path = :"#{gem_rel_dir}/views/#{page}" if File.exists?("#{gem_abs_dir}/views/#{page}.haml") end end page_path ||= page if options[:layout] and FanforceApp.config.has_layout_for(page) if File.exists?("#{app_dir}/layouts/#{options[:layout]}.haml") options[:layout] = :"../layouts/#{options[:layout]}" else options[:layout] = :"#{gem_rel_dir}/layouts/#{options[:layout]}" end else options[:layout] = false end haml page_path, options end configure do FanforceApp.load_config set :haml, {:escape_attrs => false} set :static, true set :protection, :except => [:frame_options, :json_csrf] end end