Plugin = Fanforce::Plugin PluginWorker = Fanforce::PluginWorker ######################################################################################################################## class Fanforce::Plugin::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::Plugin.config.factory_dir}/controllers/base_controller" Dir["#{Fanforce::Plugin.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::Plugin.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::Plugin.config.factory_dir) plugin_views_dir = Pathname.new(settings.views) haml :"#{factory_dir.relative_path_from(plugin_views_dir).to_s}/directive_views/#{page}" end def page(page, options={}) plugin_views_dir = Pathname.new(settings.views) page = :"#{options[:com_dir]}/#{page}" if File.exists?("#{plugin_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::Plugin.config.load_bugsnag Fanforce::Plugin.config.load_routes set :root, Fanforce::Plugin.config.base_dir set :haml, {escape_attrs: false} set :static, true set :protection, :except => [:frame_options, :json_csrf] end get '/' do "#{Fanforce::Plugin._id} is ready to go! All you need are a few routes." end end