Sha256: faca0a90403cf173369f088100a3f403e812929f280e58355ecbc23b584f6aa3

Contents?: true

Size: 1.64 KB

Versions: 3

Compression:

Stored size: 1.64 KB

Contents

module Images
  module Tags
    class Helpers
    
      class TagError < StandardError; end
      
      class << self
        
        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

3 entries across 3 versions & 1 rubygems

Version Path
radiant-images-extension-0.3.4 lib/images/tags/helpers.rb
radiant-images-extension-0.3.3 lib/images/tags/helpers.rb
radiant-images-extension-0.3.2 lib/images/tags/helpers.rb