Images
Loads all image urls in your Rails project into a global JavaScript constant.
Installation
Add this line to your application's Gemfile:
gem 'images'
And then execute:
$ bundle
Or install it yourself as:
$ gem install images
Usage
Add //= require images
line to your application.js
. It will create an
Images
global JavaScript variable with urls for all images in your
app/assets/images
folder.
For example, given that you have an image folder structure such as this:
.
└── app
└── assets
└── images
└── nested
| ├── Image3.bmp
| ├── Image4.bmp
| └── deeply_nested
| └── Image5.svg
├── image1.jpg
└── image2.svg
Will create:
// window.Images
{
nested: {
Image3_bmp_path: "/assets/Image3-...",
Image4_bmp_path: "/assets/Image4-...",
deeply_nested: {
Image5_svg_path: "/assets/Image5-..."
}
},
image1_jpg_path: "/assets/image1-...",
image2_svg_path: "/assets/image2-..."
}
Configuration
By default this gem uses all of the image types included in Mime::EXTENSION_LOOKUP
plus svg
.
To add other file types to this list, simply append the file extension to config.images.whitelist
in your application.rb
. For example,
module MyApp
class Application < Rails::Application
# ...
config.images.whitelist += ['exe']
end
end
Contributing
- Fork it ( https://github.com/BrewhouseTeam/images/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request