/named_variant

Make ActiveStorage's variant named and configurable

Primary LanguageRubyMIT LicenseMIT

NamedVariant [DEPRECATED]

This gem is deprecated due to rails/rails#39135

Gem Version Build Status

Make ActiveStorage's variant named and configurable.

Usual process is

class User < ActiveRecord::Base
  has_one_attached :avatar
end

and view.

= image_tag(user.avatar.variant(resize: "100x100", monochrome: true, flip: "-90").processed)

It's annoying, and sometimes not DRY. NamedVarient gives a solution.

class User < ActiveRecord::Base
  has_one_attached :avatar

  variant_name :monochrome, resize: "100x100", monochrome: true, flip: "-90"
end
= image_tag(user.avatar.variant(:monochrome).processed)
# only user's attachment can call `monochrome` variant.

Installation

gem 'named_variant'

And then execute:

$ bundle

Todo

  • scoped variant name support
  • config file support

License

The gem is available as open source under the terms of the MIT License.