Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurations per resource or per uploader #6

Open
johnkoht opened this issue Nov 19, 2014 · 0 comments
Open

Configurations per resource or per uploader #6

johnkoht opened this issue Nov 19, 2014 · 0 comments

Comments

@johnkoht
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant