Sha256: 4a921f739c84a2b36ca840a4589f53821505023a0dc44c2c2ee74dd292680ebf

Contents?: true

Size: 690 Bytes

Versions: 8

Compression:

Stored size: 690 Bytes

Contents

module Locomotive::Builder
  class Server

    class DynamicAssets < Middleware

      def call(env)
        self.set_accessors(env)

        path = env['PATH_INFO']

        if path =~ /^\/(stylesheets|javascripts)\//

          mime_type = MIME::Types.type_for(path).first.try(:to_s) || 'text/plain'
          asset     = self.mounting_point.theme_assets.detect do |_asset|
            _asset.path == path
          end

          if asset
            [200, { 'Content-Type' => mime_type }, [asset.content!]]
          else
            [404, { 'Content-Type' => mime_type }, ['Asset not found']]
          end
        else
          app.call(env)
        end
      end

    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
locomotivecms_builder-1.0.0.alpha8 lib/locomotive/builder/server/dynamic_assets.rb
locomotivecms_builder-1.0.0.alpha7 lib/locomotive/builder/server/dynamic_assets.rb
locomotivecms_builder-1.0.0.alpha6 lib/locomotive/builder/server/dynamic_assets.rb
locomotivecms_builder-1.0.0.alpha5 lib/locomotive/builder/server/dynamic_assets.rb
locomotivecms_builder-1.0.0.alpha4 lib/locomotive/builder/server/dynamic_assets.rb
locomotivecms_builder-1.0.0.alpha3 lib/locomotive/builder/server/dynamic_assets.rb
locomotivecms_builder-1.0.0.alpha2 lib/locomotive/builder/server/dynamic_assets.rb
locomotivecms_builder-1.0.0.alpha1 lib/locomotive/builder/server/dynamic_assets.rb