Skip to content

Commit

Permalink
Added thumbnail method to image to encapsulate what was happening in …
Browse files Browse the repository at this point in the history
…image_fu that is useful for other features too.
  • Loading branch information
parndt committed Aug 31, 2010
1 parent 6112f95 commit 1f4bbeb
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Expand Up @@ -8,7 +8,7 @@ GIT
PATH
remote: .
specs:
refinerycms (0.9.8.0.rc2.pre)
refinerycms (0.9.8.0.rc3.pre)
acts_as_indexed (~> 0.6.5)
authlogic (~> 2.1.6)
bundler (~> 1.0.0)
Expand Down
2 changes: 1 addition & 1 deletion refinerycms.gemspec
Expand Up @@ -2,7 +2,7 @@

Gem::Specification.new do |s|
s.name = %q{refinerycms}
s.version = %q{0.9.8.0.rc2.pre}
s.version = %q{0.9.8.0.rc3.pre}
s.description = %q{A Ruby on Rails CMS that supports Rails 3. It's easy to extend and sticks to 'the Rails way' where possible.}
s.date = %q{2010-08-31}
s.summary = %q{A Ruby on Rails CMS that supports Rails 3}
Expand Down
14 changes: 1 addition & 13 deletions vendor/refinerycms/core/lib/refinery/application_helper.rb
Expand Up @@ -57,21 +57,9 @@ def descendant_page_selected?(page)
# <%= image_fu @model.image, '200x200' %> or with no thumbnail: <%= image_fu @model.image %>
def image_fu(image, geometry = nil, options={})
if image.present?
if geometry.is_a?(Symbol)
if (sizes = RefinerySetting.find_or_set(:image_thumbnails, {})) and sizes.keys.include?(geometry)
geometry = sizes[geometry].presence
end
end

thumbnail = if geometry.present? && !geometry.is_a?(Symbol)
image.image.thumb(geometry)
else
image.image
end

# call rails' image tag function with default alt, width and height options.
# if any other options were supplied these are merged in and can replace the defaults.
image_tag(thumbnail.url, {
image_tag((thumbnail = image.thumbnail(geometry)).url, {
:alt => image.respond_to?(:title) ? image.title : image.image_name,
:width => thumbnail.width,
:height => thumbnail.height
Expand Down
31 changes: 24 additions & 7 deletions vendor/refinerycms/images/app/models/image.rb
Expand Up @@ -27,16 +27,33 @@ class Image < ActiveRecord::Base

delegate :size, :mime_type, :url, :width, :height, :to => :image

# How many images per page should be displayed?
def self.per_page(dialog = false, has_size_options = false)
if dialog
unless has_size_options
PAGES_PER_DIALOG
class << self
# How many images per page should be displayed?
def per_page(dialog = false, has_size_options = false)
if dialog
unless has_size_options
PAGES_PER_DIALOG
else
PAGES_PER_DIALOG_THAT_HAS_SIZE_OPTIONS
end
else
PAGES_PER_DIALOG_THAT_HAS_SIZE_OPTIONS
PAGES_PER_ADMIN_INDEX
end
end
end

# Get a thumbnail job object given a geometry.
def thumbnail(geometry = nil)
if geometry.is_a?(Symbol)
if (sizes = RefinerySetting.find_or_set(:image_thumbnails, {})) and sizes.keys.include?(geometry)
geometry = sizes[geometry].presence
end
end

if geometry.present? && !geometry.is_a?(Symbol)
self.image.thumb(geometry)
else
PAGES_PER_ADMIN_INDEX
self.image
end
end

Expand Down
Expand Up @@ -22,7 +22,7 @@
<label><%= t('.maximum_image_size', :megabytes => Image::MAX_SIZE_IN_MB) %></label>
</div>

<div<%= (" style='margin-top: #{@image.thumbnails.detect{|t| t.thumbnail == 'medium'}.height - 63}px'" rescue nil) if action_name =~ /(edit)|(update)/ and !@app_dialog%>>
<div<%= (" style='margin-top: #{@image.thumbnail(:medium).height - 63}px'" rescue nil) if action_name =~ /(edit)|(update)/ and !@app_dialog%>>
<%= render :partial => "/shared/admin/form_actions",
:locals => {
:f => f,
Expand Down
2 changes: 1 addition & 1 deletion vendor/refinerycms/refinery.rb
Expand Up @@ -27,7 +27,7 @@ class Version
@major = 0
@minor = 9
@tiny = 8
@build = '0.rc2.pre'
@build = '0.rc3.pre'

class << self
attr_reader :major, :minor, :tiny, :build
Expand Down

0 comments on commit 1f4bbeb

Please sign in to comment.