Module: ResourcePresentationHelpers

Defined in:
lib/resource-presentation-helpers.rb

Instance Method Summary collapse

Instance Method Details

#description_for(resource, opts = {}) ⇒ Object



65
66
67
# 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 = {}) ⇒ Object



59
60
61
62
63
# 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 = {}) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# 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 = {}) ⇒ Object



27
28
29
30
31
# 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

#name_for(resource, opts = {}) ⇒ Object Also known as: title_for, label_for



53
54
55
# File 'lib/resource-presentation-helpers.rb', line 53

def name_for(resource, opts = {})
  resource && (meth = label_method_for(resource, opts)) && resource.send(meth)
end

#name_method_for(resource, opts = {}) ⇒ Object Also known as: title_method_for, label_method_for



45
46
47
48
49
# 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