class Gulp::Pipeline::Rails::Assets

Public Class Methods

base_path() click to toggle source

Yield a digest path with respect to debug turned on or off

# File lib/gulp/pipeline/rails/assets.rb, line 32
def base_path
  if debug
    "#{debug_prefix}/"
  else
    "#{digest_prefix}/"
  end
end
compute_asset_path(source, options = {}) click to toggle source

Computes asset path to public directory. We override this in the Helper to resolve either debug or digest assets.

source: favicon.ico options: {type: :image}

# File lib/gulp/pipeline/rails/assets.rb, line 12
def compute_asset_path(source, options = {})
  dir = type_directory_map[options[:type]] || ''

  # get the relative file path without a leading slash (empty dir join adds leading slash)
  file = if dir.eql? '' then
           source
         else
           File.join(dir, source)
         end
  if (debug)
    path = File.join('/', base_path, file)
  else
    manifested = manifest[file]
    raise "#{source} not found in the manifest.  Perhaps you need to recreate it by running `gulp digest` or `gulp rev`" if manifested.nil?
    path = File.join('/', base_path, manifested)
  end
  path
end
mount_path(prefix) click to toggle source
# File lib/gulp/pipeline/rails/assets.rb, line 40
def mount_path(prefix)
  "/#{base_path}#{prefix}"
end
path_matches?(path) click to toggle source
# File lib/gulp/pipeline/rails/assets.rb, line 44
def path_matches?(path)
  (path =~ matches_regex) == 0
end
path_starts_with?(path) click to toggle source
# File lib/gulp/pipeline/rails/assets.rb, line 48
def path_starts_with?(path)
  (path =~ starts_with_regex) == 0
end

Private Class Methods

debug() click to toggle source
# File lib/gulp/pipeline/rails/assets.rb, line 78
def debug
  @_debug ||= ::Rails.application.config.assets.debug
end
debug_prefix() click to toggle source
# File lib/gulp/pipeline/rails/assets.rb, line 86
def debug_prefix
  @_debug_prefix ||= ::Rails.application.config.assets.debug_prefix
end
digest_prefix() click to toggle source
# File lib/gulp/pipeline/rails/assets.rb, line 82
def digest_prefix
  @_digest_prefix ||= ::Rails.application.config.assets.digest_prefix
end
manifest() click to toggle source
# File lib/gulp/pipeline/rails/assets.rb, line 54
def manifest
  return @_manifest unless @_manifest.nil?

  # read manifest and cache it
  path = ::Rails.application.root.join('public', digest_prefix, 'rev-manifest.json')
  # if not debug, require manifest
  raise "#{path} not found.  Run `gulp digest` or `gulp rev`." unless File.exists?(path)
  @_manifest = JSON.parse(File.read(path))
end
matches_regex() click to toggle source

lazy load/cache regex

# File lib/gulp/pipeline/rails/assets.rb, line 65
def matches_regex
  @_matches_regex ||= %r{\A/#{base_path}\z}
end
starts_with_regex() click to toggle source

lazy load/cache regex

# File lib/gulp/pipeline/rails/assets.rb, line 70
def starts_with_regex
  @_starts_with_regex ||= %r{\A/#{base_path}}
end
type_directory_map() click to toggle source
# File lib/gulp/pipeline/rails/assets.rb, line 74
def type_directory_map
  @_type_directory_map ||= ::Rails.application.config.assets.type_directory_map
end