Sha256: 55e502bbe4da2668e4306810ee9a1c368795c05e86de81fcf7cb0088d20f7097

Contents?: true

Size: 642 Bytes

Versions: 2

Compression:

Stored size: 642 Bytes

Contents

module GhostInThePost
  module JSLoaders
    module AssetPipelineLoader
      extend self

      def load(url)
        if asset_pipeline_present?
          file = file_name(url)
          asset = ::Rails.application.assets.find_asset(file)
          asset.to_s if asset
        end
      end

      def asset_pipeline_present?
        defined?(::Rails) &&
          ::Rails.application.respond_to?(:assets) &&
          ::Rails.application.assets
      end

      def file_name(url)
        URI(url).path
          .sub("#{::Rails.configuration.assets.prefix}/", '')
          .sub(/-(\h{32}|\h{64})\.js$/, '.js')
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ghost_in_the_post-0.1.3 lib/ghost_in_the_post/js_loaders/asset_pipeline_loader.rb
ghost_in_the_post-0.1.2 lib/ghost_in_the_post/js_loaders/asset_pipeline_loader.rb