Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add info for Rails 5 / Sprockets 3 #48

Open
jmarceli opened this issue Feb 15, 2017 · 5 comments
Open

Add info for Rails 5 / Sprockets 3 #48

jmarceli opened this issue Feb 15, 2017 · 5 comments

Comments

@jmarceli
Copy link

Hi, is this gem still required for Rails 5? I didn't find any info if it is possible to compile both assets versions in Rails 5 without this gem, so I assume it is still required. It would be nice to add some info to the README.md.

@georgepalmer
Copy link

This fork has some Rails 5 fixes. No idea about complete compatibility but it's working how we use it

@timoschilling
Copy link

The changes in that fork are made by me, they are not to fix Rails 5 problems, they are just for some server setup problems.

@randomizor
Copy link

module NonStupidDigestAssets
  mattr_accessor :whitelist
  @@whitelist = []

  class << self
    def files(files)
      return files if whitelist.empty?
      whitelisted_files(files)
    end

    private

    def whitelisted_files(files)
      files.select do |file, info|
        whitelist.any? do |item|
          case item
          when Regexp
            info['logical_path'] =~ item
          else
            info['logical_path'] == item
          end
        end
      end
    end
  end
end

module NonDigest
  def compile *args
    super *args
    
    NonStupidDigestAssets.files(files).each do |(digest_path, info)|
      full_digest_path = File.join dir, digest_path
      full_digest_gz_path = "#{full_digest_path}.gz"
      full_non_digest_path = File.join dir, info['logical_path']
      full_non_digest_gz_path = "#{full_non_digest_path}.gz"

      if File.exists? full_digest_path
        # logger.info "Writing #{full_non_digest_path}"
        FileUtils.rm full_non_digest_path if File.exists? full_non_digest_path
        FileUtils.cp full_digest_path, full_non_digest_path
      else
        logger.warn "Could not find: #{full_digest_path}"
      end
      if File.exists? full_digest_gz_path
        # logger.info "Writing #{full_non_digest_gz_path}"
        FileUtils.rm full_non_digest_gz_path if File.exists? full_non_digest_gz_path
        FileUtils.cp full_digest_gz_path, full_non_digest_gz_path
      else
        logger.warn "Could not find: #{full_digest_gz_path}"
      end
    end
  end
end

module Sprockets
  class Manifest
    prepend NonDigest
  end
end

@dmolesUC
Copy link
Contributor

Basic functionality seems fine to me in Rails 6, FWIW. What issues have other folks been seeing?

@dmolesUC
Copy link
Contributor

dmolesUC commented Oct 31, 2019

OK, here's one: it looks like JS in public/packs/js doesn't get copied to the non-stupid path. Not a big deal for me as I'm only using this gem to statically link CSS and images in my 404.html and 500.html, but might be an issue for some.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants