I think we should extend the configuration to enable per resource or per uploader customization. When you set the initializer, it really only address one type of resource. What if I have a project and user model and they have drastically different carrierwave versions. Rather than having to default to projects and inline my user model, we should allow the gem to pull global configs on a per resource basis.
*Option 1: Class Method
We can allow users to define the configuration in the model as a class method, i..e:
class User < ActiveRecord::Base
def self.responsive_sizes
{ mobile: :avatar_mobile, tablet: :avatar_tablet, desktop: :avatar_desktop }
end
end
We can probably even make this a method called in the model:
class User < ActiveRecord::Base
responsive_images sizes: { mobile: :avatar_mobile, tablet: :avatar_tablet, desktop: :avatar_desktop }
end
Option 2: Custom Object
We can create a custom object for sizes, ResponsiveImages::Config that can define the default config. Custom configs could inherit from the default and define the customizations:
class ResponsiveImages::Config
def self.default
:default
end
def self.sizes
{
mobile: :mobile,
tablet: :tablet,
desktop: :desktop
}
end
end
Any calls to responsive_image_tag or responsive_background_image would use the default config. You would create custom configs by inheriting from the default config:
class ProjectResponsiveImages < ResponsiveImages::Config
def self.default
:banner
end
def self.sizes
{
mobile: :project_mobile,
tablet: :project_tablet,
desktop: :project_desktop
}
end
end
To use the custom config, you would pass it as an argument to the helper method, i.e.:
responsive_image_tag @project.image, config: ProjectResponsiveImages
Let me know if there are any other, or better, options.
I think we should extend the configuration to enable per resource or per uploader customization. When you set the initializer, it really only address one type of resource. What if I have a
projectandusermodel and they have drastically different carrierwave versions. Rather than having to default to projects and inline my user model, we should allow the gem to pull global configs on a per resource basis.*Option 1: Class Method
We can allow users to define the configuration in the model as a class method, i..e:
We can probably even make this a method called in the model:
Option 2: Custom Object
We can create a custom object for sizes,
ResponsiveImages::Configthat can define the default config. Custom configs could inherit from the default and define the customizations:Any calls to
responsive_image_tagorresponsive_background_imagewould use the default config. You would create custom configs by inheriting from the default config:To use the custom config, you would pass it as an argument to the helper method, i.e.:
Let me know if there are any other, or better, options.