Sha256: 6c92807ada7694621903dc3f89568b69fe63c4d9a39b2fe4b4f222dd959e0afa

Contents?: true

Size: 1.5 KB

Versions: 2

Compression:

Stored size: 1.5 KB

Contents

# encoding: utf-8

require 'sinatra/base'
require 'rack/classy_assets'
require 'sinatra/sprockets-helpers'

module Sinatra
  module ClassyAssets
    def self.registered(app)
      app.set :asset_host, nil
      app.set :assets_prefix, 'assets'
      app.set :digest_assets, false
      app.set :css_compressor, nil
      app.set :js_compressor, nil
      app.set :root, ::File.expand_path('../', __FILE__)
      app.set :public_folder, ::File.join(app.settings.root, 'public')
      app.set :sprockets, ::Sprockets::Environment.new(app.settings.root)

      app.use Rack::ClassyAssets, assets_prefix: app.settings.assets_prefix,
                                  css_compressor: app.settings.css_compressor,
                                  js_compressor: app.settings.js_compressor,
                                  root: app.settings.root,
                                  sprockets: app.settings.sprockets
      
      app.register ::Sinatra::Sprockets::Helpers
      app.configure_sprockets_helpers do |config|
        manifest_file = ::File.join(app.settings.root, 'public', app.settings.assets_prefix, 'manifset.json')

        config.asset_host   = app.settings.asset_host
        config.manifest     = ::Sprockets::Manifest.new(app.settings.sprockets, manifest_file) if ::File.exists? manifest_file
        config.prefix       = app.settings.assets_prefix
        config.public_path  = app.settings.public_folder
        config.debug        = true if app.development?
      end 
    end
  end
  register ClassyAssets
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
classy_assets-0.0.2 lib/sinatra/classy_assets.rb
classy_assets-0.0.1 lib/sinatra/classy_assets.rb