Sha256: ec67b8d0fae072b7db17871484368383b0df080a51cc505448209f79f6b19e3b

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

require 'base64'
require 'rack/utils'
require 'sprockets'

module MongodbLogger
  
  module AssetHelpers
    def asset_path(source)
      "/assets/#{Assets.instance.find_asset(source).digest_path}" unless Assets.instance.find_asset(source).nil?
    end
    def asset_data_uri(source)
      unless Assets.instance.find_asset(source).nil?
        asset  = Assets.instance.find_asset(source)
        base64 = Base64.encode64(asset.to_s).gsub(/\s+/, "")
        "data:#{asset.content_type};base64,#{Rack::Utils.escape(base64)}"
      end
    end
  end
  
  class Assets < Sprockets::Environment
    class << self
      def instance(root = nil)
        assets_path = File.expand_path('../../../../app/assets', __FILE__)
        @instance ||= new(assets_path)
      end
    end

    def initialize(assets_path)
      super
      append_path(File.join(assets_path, 'stylesheets'))
      append_path(File.join(assets_path, 'javascripts'))
      append_path(File.join(assets_path, 'images'))

      context_class.instance_eval do
        include AssetHelpers
      end
    end
  end
  
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mongodb_logger-0.3.2-jruby lib/mongodb_logger/server/sprokets.rb
mongodb_logger-0.3.2 lib/mongodb_logger/server/sprokets.rb
mongodb_logger-0.3.1-jruby lib/mongodb_logger/server/sprokets.rb
mongodb_logger-0.3.1 lib/mongodb_logger/server/sprokets.rb
mongodb_logger-0.3.0-jruby lib/mongodb_logger/server/sprokets.rb
mongodb_logger-0.3.0 lib/mongodb_logger/server/sprokets.rb