Make Asset Pipeline Work With Chrome DevTools Autosave

Chrome DevTools Autosave does not work with Rails Asset Pipeline . The essence of the problem lies in the URLs of the assets - I cannot decrypt the actual path to the file by its URL. For example, /assets/application.css can refer to either app / assets / stylesheets / application.css, lib / assets / stylesheets / application.css, or vendor / assets / stylesheets / application.css.

I wonder how to change the resource URL to one of the following:

  • /app/assets/stylesheets/application.css( matches exactly the actual file path, perfect solution)
  • /assets/application.css?source_url=app/assets/stylesheets/application.css(enables the source_url request parameter)

I would appreciate any help in writing a Rails plugin for this.


Update: I filled in a problem for stars .

+6
source share
2 answers

I will try to get the ball to roll, but I will need to do much more to test or give a better answer, so I will mark this answer with the wiki community. . others may reply below and / or edit this post.

I needed to create asset pipelining for Sinatra and, generally speaking, in the latest versions of Sprockets (which are used to convey assets in Rails), the Sprockets::Asset class has methods for getting the path and the logical path .

I believe that Rails uses the asset_path helper to create a public return URL from the Sprockets class. This, in turn, uses the AssetPaths#compute_public_path instance method. A good first step would be to modify these parts of the code to add the source_url parameter based on the parsing of source.pathname . It is assumed that the source is an instance of Sprockets::Asset in one form or another.

+3
source

I'm not quite sure how you expect the source to arrive, but ActionView::Helpers::AssetTagHelper already provided

http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html

 image_tag("rails.png") # => <img alt="Rails" src="http://assets.example.com/images/rails.png?1230601161" /> stylesheet_link_tag("application") # => <link href="http://assets.example.com/stylesheets/application.css?1232285206" media="screen" rel="stylesheet" type="text/css" /> 
0
source

Source: https://habr.com/ru/post/910870/


All Articles