Sha256: c102a6d1ffc3f0f0c31430e8a84dd962975f21460f38d883ebd426bf3e3529b2

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

# encoding: utf-8

require 'sinatra/base'
require 'sprockets'
require "sprockets-sass"
require "sass"
require 'coffee_script'
require 'uglifier'
require 'yui/compressor'

module Rack
  class ClassyAssets < Sinatra::Base
    def initialize(app, options)
      options[:assets_prefix] ||= 'assets'
      options[:css_compressor] ||= ::YUI::CssCompressor.new
      options[:js_compressor] ||= ::Uglifier.new
      options[:root] ||= ::File.expand_path('../../', __FILE__)
      options[:sprockets] ||= ::Sprockets::Environment.new(options[:root])

      @sprockets = options[:sprockets]
      @sprockets.append_path ::File.join(options[:root], "assets", "stylesheets")
      @sprockets.append_path ::File.join(options[:root], "assets", "javascripts")
      @sprockets.append_path ::File.join(options[:root], "assets", "images")
      @sprockets.js_compressor = options[:js_compressor]
      @sprockets.css_compressor = options[:css_compressor]
    end

    get "/assets/:script.js" do |script|
      content_type("application/javascript")
      @sprockets["#{script}.js"]
    end

    get "/assets/:stylesheet.css" do |stylesheet|
      content_type("text/css")
      @sprockets["#{stylesheet}.css"]
    end

    %w{jpg png gif}.each do |format|
      get "/assets/:image.#{format}" do |image|
        content_type("image/#{format}")
        @sprockets["#{image}.#{format}"]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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