module ResourcePresentationHelpers

Public Instance Methods

description_for(resource, opts = {}) click to toggle source
# File lib/resource-presentation-helpers.rb, line 65
def description_for(resource, opts = {})
  resource && ( meth = description_method_for(resource, opts) ) && resource.send(meth)
end
description_method_for(resource, opts = {}) click to toggle source
# File lib/resource-presentation-helpers.rb, line 59
def description_method_for(resource, opts = {})
  klass = resource.is_a?(Class) ? resource : resource.class
  any_names = ((klass.respond_to?(:column_names)  ? klass.column_names : []) + klass.public_instance_methods).map {|name| "#{name}"}.uniq.delete_if {|meth| meth =~ /^_/}
  %w(description excerpt meta_descripiton to_description).find {|meth| any_names.include?(meth)}
end
image_for(resource, opts = {}) click to toggle source
# File lib/resource-presentation-helpers.rb, line 33
def image_for(resource, opts = {})
  attachment_or_url = resource && (meth = image_method_for(resource, opts)) && resource.send(meth)
  return nil if attachment_or_url.nil?

  if attachment_or_url.is_a?(Paperclip::Attachment)
    style = opts[:style] && attachment_or_url.styles.keys.include?("#{opts[:style]}") ? opts[:style] : :original 
    attachment_or_url.send(:url, style)
  else
    attachment_or_url        
  end
end
image_method_for(resource, opts = {}) click to toggle source
# File lib/resource-presentation-helpers.rb, line 27
def image_method_for(resource, opts = {})
  klass = resource.is_a?(Class) ? resource : resource.class
  any_names = ((klass.respond_to?(:column_names)  ? klass.column_names : []) + klass.public_instance_methods).map {|name| "#{name}"}.uniq.delete_if {|meth| meth =~ /^_/}
  %w(photo image thumbnail logo).find {|meth| any_names.include?(meth)}
end
label_for(resource, opts = {})
Alias for: name_for
label_method_for(resource, opts = {})
Alias for: name_method_for
name_for(resource, opts = {}) click to toggle source
# File lib/resource-presentation-helpers.rb, line 53
def name_for(resource, opts = {})
  resource && (meth = label_method_for(resource, opts)) && resource.send(meth)
end
Also aliased as: title_for, label_for
name_method_for(resource, opts = {}) click to toggle source
# File lib/resource-presentation-helpers.rb, line 45
def name_method_for(resource, opts = {})
  klass = resource.is_a?(Class) ? resource : resource.class
  any_names = ((klass.respond_to?(:column_names)  ? klass.column_names : []) + klass.public_instance_methods).map {|name| "#{name}"}.uniq.delete_if {|meth| meth =~ /^_/}
  %w(to_label title name label browser_title seo_title seo_name key claim email to_s).find {|meth| any_names.include?(meth)}
end
title_for(resource, opts = {})
Alias for: name_for
title_method_for(resource, opts = {})
Alias for: name_method_for