Sha256: 21f5ee0399e2bffb3c8b0e69ebf1931771c7f029313da3015b6b00d5772240b5

Contents?: true

Size: 972 Bytes

Versions: 43

Compression:

Stored size: 972 Bytes

Contents

module Locomotive
  module Steam

    class ThemeAssetUrlService

      attr_accessor_initialize :repository, :asset_host, :checksum

      def build(path)
        # keep the query string safe
        path.gsub!(/(\?+.+)$/, '')
        query_string = $1

        # build the url of the theme asset based on the persistence layer
        _url = repository.url_for(path)

        # get a timestamp only if the source url doesn't include a query string
        timestamp = query_string.blank? ? checksums[path] : nil

        # prefix by a asset host if given
        url = asset_host ? asset_host.compute(_url, timestamp) : _url

        query_string ? "#{url}#{query_string}" : url
      end

      def checksums
        if checksum?
          @checksums ||= fetch_checksums
        else
          {}
        end
      end

      def checksum?
        !!checksum
      end

      private

      def fetch_checksums
        repository.checksums
      end

    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
locomotivecms_steam-1.8.0.alpha2 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.8.0.alpha1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.7.1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.7.0 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.6.1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.6.0 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.6.0.rc1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.6.0.beta1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.3 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.2 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.0 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.0.rc1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.0.rc0 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.0.beta3 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.0.beta2 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.5.0.beta1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.4.1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.4.0 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/services/theme_asset_url_service.rb