If using different image sizes, you will probably need to change
show.html, its partials, or some of the related style files - but this
is something that you will need to do to customize your site...
Paul
Are you still thinking about writing this up in the guides/blog post?
Ideally both. Documentation with snippets summary in blog post.
Sean
+1
> Paul
Sean
in other words:
11:54:35:shop >> script/console
Loading development environment (Rails 2.3.2)
>> Spree::Config.set(:image_styles => { :mini => '5x5%', :small => '10x10%', :product => '24x24%', :large => '60x60%' })
=> nil
>> Spree::Config[:image_styles]
=> "--- \n:mini: 5x5%\n:large: 60x60%\n:small: 10x10%\n:product: 24x24%\n"
>> YAML::Load(Spree::Config[:image_styles])
NoMethodError: undefined method `Load' for YAML:Module
from (irb):3
>> YAML::load(Spree::Config[:image_styles])
=> {:mini=>"5x5%", :large=>"60x60%", :small=>"10x10%", :product=>"24x24%"}
>> quit
Which means....
class Image < Asset
has_attached_file :attachment,
:styles => YAML::load(Spree::Config[:image_styles]),
:default_style => :product,
:url => "/assets/products/:id/:style/:basename.:extension",
:path => ":rails_root/public/assets/products/:id/:style/:basename.:extension"
end
If we extend this and store default_style, url, and path in
Spree::Config, then setting the values in an initializer file or
migration file is all that's needed for complete customization by
anyone.
Spree::Config.set(:image_styles => { :mini => '5x5%', :small =>
'10x10%', :product => '24x24%', :large => '60x60%' })
Spree::Config.set(:image_default_style => :product)
Spree::Config.set(:image_url =>
"/assets/products/:id/:style/:basename.:extension")
Spree::Config.set(:image_path =>
":rails_root/public/assets/products/:id/:style/:basename.:extension")
and the Image model then becomes:
class Image < Asset
has_attached_file :attachment,
:styles => YAML::load(Spree::Config[:image_styles]),
:default_style => Spree:Config[:image_default_style],
:url => Spree.Config[:image_url],
:path => Spree.Config[:image_path]
end
Michael
--
http://codeconnoisseur.org
Image sizes are fairly fundamental to a site's design/layout, and I
don't think it's productive to allow too much flexibility to change
them. Plus, what happens when the admininstrator (not necessarily the
developer) chooses to change a size? or opts to choose a different
asset location? should all of the images be resized/recomputed?
IMHO, paperclip gives sufficient hooks to allow developers to change
what they need to change.
Note that we can now put initializers in extensions, so we can
probably put the styles changes there rather than in activate.
Paul
Every time I set up a new spree store, I'm going to have to tweak the
sizes...and its usually done at the outset when doing the site design
and layout. Seems to me the easier we make it to configure Spree w/o
having to resort to writing code, the better.
> IMHO, paperclip gives sufficient hooks to allow developers to change
> what they need to change.
>
Right. That's not the problem being solved, though. ;-) The problem
is what are those image sizes gonna be? It just seems to me that
writing an extension to change image sizes is overly complex compared
to a simple migration script (or initializer to specify the sizes),
not to mention easier to document.
Michael
--
http://codeconnoisseur.org