Sha256: 9f926e33e5c69506c4dd9141d9fc18c14b47fe351c108cbf0d81ab892eb1a9e2
Contents?: true
Size: 1.45 KB
Versions: 2
Compression:
Stored size: 1.45 KB
Contents
# frozen_string_literal: true require 'securerandom' module Sprockets # Public: Manifest utilities. module ManifestUtils extend self MANIFEST_RE = /^\.sprockets-manifest-[0-9a-f]{32}.json$/ LEGACY_MANIFEST_RE = /^manifest(-[0-9a-f]{32})?.json$/ # Public: Generate a new random manifest path. # # Manifests are not intended to be accessed publicly, but typically live # alongside public assets for convenience. To avoid being served, the # filename is prefixed with a "." which is usually hidden by web servers # like Apache. To help in other environments that may not control this, # a random hex string is appended to the filename to prevent people from # guessing the location. If directory indexes are enabled on the server, # all bets are off. # # Return String path. def generate_manifest_path ".sprockets-manifest-#{SecureRandom.hex(16)}.json" end # Public: Find or pick a new manifest filename for target build directory. # # dirname - String dirname # # Examples # # find_directory_manifest("/app/public/assets") # # => "/app/public/assets/.sprockets-manifest-abc123.json" # # Returns String filename. def find_directory_manifest(dirname) entries = File.directory?(dirname) ? Dir.entries(dirname) : [] entry = entries.find { |e| e =~ MANIFEST_RE } || generate_manifest_path File.join(dirname, entry) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sprockets-4.0.0.beta4 | lib/sprockets/manifest_utils.rb |
sprockets-4.0.0.beta3 | lib/sprockets/manifest_utils.rb |