Sha256: 9d504c8f8693acca921e9202267f27b2b8b0c0778f86982311cf9b7ae0ab23ec

Contents?: true

Size: 940 Bytes

Versions: 3

Compression:

Stored size: 940 Bytes

Contents

module Locomotive::Wagon
  class Server

    class DynamicAssets < Middleware

      attr_reader :app, :sprockets, :regexp

      def initialize(app, root)
        super(app)

        @regexp = /^\/(javascripts|stylesheets)\/(.*)$/

        # make sure Compass is correctly configured
        Locomotive::Mounter::Extensions::Compass.configure(root)

        @sprockets = Sprockets::Environment.new
        @sprockets.append_path File.join(root, 'public/stylesheets')
        @sprockets.append_path File.join(root, 'public/javascripts')
      end

      def call(env)
        if env['PATH_INFO'] =~ self.regexp
          env['PATH_INFO'] = $2

          begin
            self.sprockets.call(env)
          rescue Exception => e
            raise Locomotive::Wagon::DefaultException.new "Unable to serve a dynamic asset. Please check the logs.", e
          end
        else
          app.call(env)
        end
      end

    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.2.2 lib/locomotive/wagon/server/dynamic_assets.rb
locomotivecms_wagon-1.2.1 lib/locomotive/wagon/server/dynamic_assets.rb
locomotivecms_wagon-1.2.0 lib/locomotive/wagon/server/dynamic_assets.rb