📜 ⬆️ ⬇️

Distribute pictures by rails after disabling Google’s svn repositories

Apparently, Google disconnected the svn repository code.google.com in the week.
If you did not connect the scripts distributed from these repositories, you could not notice this, as I did.
I was surprised by the increased traffic to the google-maps-utility-library-v3 repository, but at first I did not understand why this might be. Later, I saw that the images of the cluster icons on the map had disappeared. The fact is that the path to the icons is hardcoded in MarkerClusterer and points to code.google.com.


How to configure sprockets to distribute these pictures, read under the cut.


First, set up the rails, meaning that we already have a copy of google-maps-utility-library-v3 in the repository. If you do not have it, how it can be done, it will be written below.


Add the path to google-maps-utility-library-v3 to the pipeline (most likely, you have already done this):


# config/initializer/assets.rb Rails.application.config.assets.paths += %W( #{Rails.root}/vendor/assets/google-maps-utility-library-v3 ) 

Now let's say sprockets that we want it to collect images from the library:


 # config/initializer/assets.rb Rails.application.config.assets.precompile += %w( markerclustererplus/images/*.png ) 

Let's set the MarkerClusterer to use our images. You need to change the file extension from .js.coffe to .js.coffee.erb . We will not hardcode the hostname, so local images will be used in the development, and you will not need to download them from the production site. ( UPD. Thanks to DeKaNszn for the idea)


 #= require markerclustererplus/src/markerclusterer_packed.js #= require infobox/src/infobox_packed.js # ... require anything you want MarkerClusterer.IMAGE_PATH = '/assets/markerclustererplus/images/m' #        # MarkerClusterer.IMAGE_PATH = <%= (Rails.application.routes.url_helpers.root_url + # 'assets/markerclustererplus/images/m').to_json %> 

That's all. Next on how to add google-maps-utility-library to your repository.


I use git submodules:


 git submodule add \ https://github.com/printercu/google-maps-utility-library-v3-read-only.git \ vendor/assets/google-maps-utility-library-v3 

Do not forget to customize the warmup. Add after checkout:


 git submodule init git submodule sync git submodule update — init 

Now everything is ready for rolling out.


You can also search for bower packages or add the library to the repository as a whole if you do not want to use submodules.


')

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


All Articles