Sha256: b12dc5ac9ed30844d88a257239b8081e3952fc9148c80f9fdcbfa7088ce3d5c4

Contents?: true

Size: 1.74 KB

Versions: 4

Compression:

Stored size: 1.74 KB

Contents

module Images
  module Tags
    class Helpers
    
      class TagError < StandardError; end
      
      class << self
        
        def all_images_with_options(tag)
          Image.all image_options(tag)
        end
        
        def current_images(tag)
          result = nil
          
          if tag.locals.images.present?
            result = tag.locals.images
          elsif tag.attr['key'] and tag.attr['value']
            result = Image.find(:all, :conditions => { tag.attr['key'].to_sym => tag.attr['value'].to_s }) rescue nil
          else
            result = Image.all
          end
          
          result
        end
        
        def current_image(tag)
          result = nil
          
          if tag.locals.image.present?
            result = tag.locals.image
          elsif tag.attr['id']
            result = Image.find(tag.attr['id'])
          elsif tag.attr['title']
            result = Image.find_by_title(tag.attr['title'])
          elsif tag.attr['position']
            begin
              result = tag.locals.images[(tag.attr['position']-1).to_i]
            rescue
              result = Image.find_by_position(tag.attr['position'].to_i)
            end
          end
          
          result
        end
        
        def image_options(tag)
          attr = tag.attr.symbolize_keys
          by = attr[:by] || 'position'
          order = attr[:order] || 'asc'
          
          options = {
            :order => "#{by} #{order}",
            :limit => attr[:limit] || nil,
            :offset => attr[:offset] || nil
          }
        end
        
        def image_and_options(tag)
          options = tag.attr.dup
          [find_image(tag, options), options]
        end
        
      end
      
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
radiant-images-extension-0.5.0 lib/images/tags/helpers.rb
radiant-images-extension-0.4.4 lib/images/tags/helpers.rb
radiant-images-extension-0.4.1 lib/images/tags/helpers.rb
radiant-images-extension-0.4.0 lib/images/tags/helpers.rb