Sha256: 75476d31be0afb7052586e4b8a09cbd723cb9f795688bdb0607fb8591a6984fa

Contents?: true

Size: 860 Bytes

Versions: 2

Compression:

Stored size: 860 Bytes

Contents

require 'coffee_script'

module Locomotive::Steam
  module Middlewares

    class DynamicAssets < Base

      attr_reader :app, :regexp

      def initialize(app)
        super(app)

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

      def call(env)
        dup._call(env) # thread-safe purpose
      end

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

          base_path = env['steam.mounting_point'].path

          begin
            sprockets = Locomotive::Mounter::Extensions::Sprockets.environment(base_path)
            sprockets.call(env)
          rescue Exception => e
            raise Locomotive::Steam::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

2 entries across 2 versions & 1 rubygems

Version Path
locomotivecms_steam-0.1.2.pre.beta lib/locomotive/steam/middlewares/dynamic_assets.rb
locomotivecms_steam-0.1.1 lib/locomotive/steam/middlewares/dynamic_assets.rb