Sha256: 9d8fe7b7ce2bdc9dd3154632e8165a2eee9a9531e711757f3725e15b8750741b

Contents?: true

Size: 1.66 KB

Versions: 48

Compression:

Stored size: 1.66 KB

Contents

require 'sinatra/content_for'
require 'rack/jsonr'
require 'bugsnag'
####################################################################################

class FanforcePlugin::Sinatra < Sinatra::Base
  require_relative 'config/_error_handling'
  require_relative 'config/helpers/assets'
  require_relative 'config/helpers/json'
  require_relative 'config/helpers/fanforce'

  use Rack::JSONR, :method_override => :all
  use Bugsnag::Rack

  helpers Sinatra::AssetHelpers
  helpers Sinatra::JSONHelpers
  helpers Sinatra::FanforceHelpers
  helpers Sinatra::ContentFor

  def self.any(url,&block)
    get(url,&block)
    post(url,&block)
    put(url,&block)
    delete(url,&block)
  end

  def page(page, options={})
    current_dir = File.expand_path('../', __FILE__)
    if !File.exists?("#{settings.views}/#{page}.haml")
      rel_path = Pathname.new(current_dir).relative_path_from(Pathname.new(settings.views))
      page = :"#{rel_path}/views/#{page}"
    end

    if options[:layout] and (!FanforcePlugin.config.respond_to?(:"layout_for_#{page}") or FanforcePlugin.config.method(:"layout_for_#{page}").call)
      if File.exists?("#{settings.views}/../layouts/#{options[:layout]}.haml")
        options[:layout] = :"../layouts/#{options[:layout]}"
      else
        rel_path = Pathname.new(current_dir).relative_path_from(Pathname.new(settings.views))
        options[:layout] = :"#{rel_path}/layouts/#{options[:layout]}"
      end
    else
      options[:layout] = false
    end
    haml page, options
  end

  configure do
    FanforcePlugin.load_config
    set :haml, {:escape_attrs => false}
    set :static, true
    set :protection, :except => [:frame_options, :json_csrf]
  end

end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
fanforce-plugin-factory-0.23.1 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.23.0 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.22.1 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.22.0 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.21.0 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.20.2 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.20.1 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.20.0 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.19.3 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.19.1 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.19.0 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.18.0 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.17.2 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.17.1 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.17.0 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.16.1 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.16.0 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.15.1 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.14.1 lib/fanforce/plugin_factory/_init_sinatra.rb
fanforce-plugin-factory-0.14.0 lib/fanforce/plugin_factory/_init_sinatra.rb