module Sinatra::FanforceHelpers require 'fanforce/api' def organization_id @organization_id = params[:organization_id] || ff.params[:organization_id] end def ff return @ff if @ff.present? @ff = Fanforce::API.new(params) #return @ff if !@ff.valid_fanforce_request? and !@ff.valid_fanforce_js_request? @ff.auth Sinatra::FanforceHelpers.find_api_key(ff.params[:organization_id]) @ff end def self.find_api_key(organization_id, addon_type=:app, addon_id=FanforceApp._id) $Redis.get("installed:#{addon_type}-#{addon_id}:#{organization_id}") end # Creates a string representation of a javascript object for ractive.js def compile_ractive_templates(options={}, &block) context = Object.new class << context include Haml::Helpers end context.init_haml_helpers format = options[:format] == 'html' ? :html : :json return context.capture_haml(&block) if format == :html single_line_html = context.capture_haml(&block).split(/\r?\n/).inject('') {|sl, l| sl += l.strip + ' ' } matches = single_line_html.scan(/