-
Notifications
You must be signed in to change notification settings - Fork 247
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
Assets (Sprockets 4.1.1 and Sprockets-rails 3.4.2) not work correctly with images within engine with third party libraries #507
Comments
I found in sprockets-rails 3.2.2 → 3.3.0 changes that make it. It is from version in file data/lib/sprockets/rails/asset_url_processor.rb ADDED module Sprockets
module Rails
# Rewrites urls in CSS files with the digested paths
class AssetUrlProcessor
REGEX = /url\(\s*["']?(?!(?:\#|data|http))([^"'\s)]+)\s*["']?\)/
def self.call(input)
context = input[:environment].context_class.new(input)
data = input[:data].gsub(REGEX) { |_match| "url(#{context.asset_path($1)})" }
{ data: data }
end
end
end
end This section of code does the conversion:from But why do this for stylesheets of third-party?... Problem not in REGEX, but in substitution path in context.asset_path($1)code module Sprockets
module Rails
# Resolve assets referenced in CSS `url()` calls and replace them with the digested paths
class AssetUrlProcessor
REGEX = /url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>\.\/)?(?<path>[^"'\s)]+)\s*["']?\)/
def self.call(input)
context = input[:environment].context_class.new(input)
data = input[:data].gsub(REGEX) do |_match|
path = Regexp.last_match[:path]
"url(#{context.asset_path(path)})"
end
context.metadata.merge(data: data)
end
end
end
end again in this code |
In REGEX = /url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>\.\/)?(?<path>[^"'\s)]+)\s*["']?\)/ BUT! relative path may be without any leading slashes and dots, like this one Even if we assume that a path without initial slashes is found, then it would be most correct to add
|
The patch that fixed the bugFor experiment I a little patch file module Sprockets
module Rails
# Resolve assets referenced in CSS `url()` calls and replace them with the digested paths
class AssetUrlProcessor
REGEX = /url\(\s*["']?(?!(?:\#|data|http))(?<relativeToCurrentDir>\.\/)?(?<path>[^"'\s)]+)\s*["']?\)/
def self.call(input)
context = input[:environment].context_class.new(input)
data = input[:data].gsub(REGEX) do |_match|
path = Regexp.last_match[:path]
# original: "url(#{context.asset_path(path)})"
# my patch
orig_path = path
path = context.asset_path(path)
path = (path == "/#{orig_path}") ? ".#{path}" : path
"url(#{path})"
end
context.metadata.merge(data: data)
end
end
end
end ... and all works correctly in development and production environments! This patch works correctly with relative paths in both assets and third-paty css-styles. Of course, these are not full-fledged corrections and the method
|
Please feel free to submit a pull request. Thank you! |
Read Contributing to Sprockets Rails and I try:
Answer:
|
Here git clone https://github.com/contributor/sprockets-rails.git Once you have cloned https://github.com/rails/sprockets-rails/ to your account the correct address should be git clone https://github.com/Sega100500/sprockets-rails.git I have opened a pull request #508 to update it. |
Both
|
Did you fork the project before cloning? |
No, I don't know much about Git workflows. Especially when it comes to making changes to other people's projects. I just followed the instructions Contributing to Sprockets Rails and I thought that at the same time I would learn how to do it, but I stumbled on the first step. Although I have 2FA and token in my profile Github.
But this happen (above):
I didn't get any files from the repository. |
But in one test is fail... Somesing wrong with P.S. It's strange that I was only able to do this using |
System configuration
Problem
I use my own engine "Admin", in which I connect the jQuery-UI library.
With sprockets 3.7.2 and sprockets-rails 3.2.2 all work fine! ... but later versions not working correctly
(config.assets.compile = true)
Directory of engine is 'admin'.
Config manifest file for admin: admin/app/assets/config/admin.js:
(replace with require_tree also not work)
connect library jQuery-UI with stylesheet_link_tag and javascript_include_tag
jQuery-UI files placed in:
admin/app/assets/javascripts/admin/lib/jquery-ui
admin/app/assets/stylesheets/admin/lib/jquery-ui
in initializer I also add:
jQuery-UI library is loaded, but background images of elements are not displayed
Inspection of example jQuery-UI element show this style:
Also I use gem ckeditor, in this case not showing icons images and images placed in page.
Images loaded in ckeditor with mini_magic and ActiveStorage and link to image is like this:
With sprockets 3.7.2 and sprockets-rails 3.2.2 all work fine! ... but later versions not working correctly
What could be wrong? I tried many options for specifying paths, direct specifying files, but it does not work as it should.
Please, help!...
gems for non-digest assets are not helped to me:
non-digest-assets gem.
sprockets-redirect gem.
smart_assets gem.
The text was updated successfully, but these errors were encountered: