Module: ResourcePresentationHelpers
- Defined in:
- lib/resource-presentation-helpers.rb
Instance Method Summary collapse
- #description_for(resource, opts = {}) ⇒ Object
- #description_method_for(resource, opts = {}) ⇒ Object
- #image_for(resource, opts = {}) ⇒ Object
- #image_method_for(resource, opts = {}) ⇒ Object
- #name_for(resource, opts = {}) ⇒ Object (also: #title_for, #label_for)
- #name_method_for(resource, opts = {}) ⇒ Object (also: #title_method_for, #label_method_for)
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 = {}) = resource && (meth = image_method_for(resource, opts)) && resource.send(meth) return nil if .nil? if .is_a?(Paperclip::Attachment) style = opts[:style] && .styles.keys.include?("#{opts[:style]}") ? opts[:style] : :original .send(:url, style) else 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 |