Sha256: a4b334ee2a6047dabf914865ab322de4797828ae5a2c8c3ab09b2e11c35e623d

Contents?: true

Size: 952 Bytes

Versions: 7

Compression:

Stored size: 952 Bytes

Contents

module Locomotive
  module Steam

    class ThemeAssetUrlService < Struct.new(: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 the source url does not 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

7 entries across 7 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.pre.beta.3 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.0.0.pre.alpha.3 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.0.0.pre.alpha.2 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.0.0.pre.alpha.1 lib/locomotive/steam/services/theme_asset_url_service.rb
locomotivecms_steam-1.0.0.pre.alpha lib/locomotive/steam/services/theme_asset_url_service.rb