Sha256: c61ddc0404019a2a5a13bcd3fb451e9f54e697ec08975b9af4fd81ad40b161da

Contents?: true

Size: 879 Bytes

Versions: 9

Compression:

Stored size: 879 Bytes

Contents

require 'sprockets'

module Spontaneous::Rack::Back
  class ApplicationAssets < Base
    def initialize(app, charset = "UTF-8")
      css, js = %w(css js).map { |d| build_asset_handler(d, charset) }
      assets = Spontaneous::Rack::CacheableFile.new(Spontaneous.root / "public/@spontaneous/assets")
      @app = ::Rack::Builder.app do
        use Spontaneous::Rack::Static, :root => Spontaneous.application_dir, :urls => %W(/static)
        map("/assets") { run assets }
        map("/css")    { run css }
        map("/js")     { run js }
        run app
      end
    end

    def call(env)
      @app.call(env)
    end

    def build_asset_handler(dir, charset)
      environment = ::Sprockets::Environment.new(Spontaneous.application_dir ) do |env|
        env.append_path("#{dir}")
      end
      Spontaneous::Rack::AssetServer.new(environment, charset)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta10 lib/spontaneous/rack/back/application_assets.rb
spontaneous-0.2.0.beta9 lib/spontaneous/rack/back/application_assets.rb
spontaneous-0.2.0.beta8 lib/spontaneous/rack/back/application_assets.rb
spontaneous-0.2.0.beta7 lib/spontaneous/rack/back/application_assets.rb
spontaneous-0.2.0.beta6 lib/spontaneous/rack/back/application_assets.rb
spontaneous-0.2.0.beta5 lib/spontaneous/rack/back/application_assets.rb
spontaneous-0.2.0.beta4 lib/spontaneous/rack/back/application_assets.rb
spontaneous-0.2.0.beta3 lib/spontaneous/rack/back/application_assets.rb
spontaneous-0.2.0.beta2 lib/spontaneous/rack/back/application_assets.rb