Module: Workbench::DisplayHelper

Defined in:
app/helpers/workbench/display_helper.rb

Overview

Generic wrappers around AR instances, these should not include link generation, but may call out to other helpers that do generate links.

Instance Method Summary (collapse)

Instance Method Details

- (Object) kind(object)



38
39
40
# File 'app/helpers/workbench/display_helper.rb', line 38

def kind(object)
  object.class.name.humanize
end

- (Object) model_name_title



34
35
36
# File 'app/helpers/workbench/display_helper.rb', line 34

def model_name_title
  controller_name.humanize
end

- (Object) object_attributes_partial_path(object)



42
43
44
# File 'app/helpers/workbench/display_helper.rb', line 42

def object_attributes_partial_path(object)
  "/#{metamorphosize_if(object).class.base_class.name.tableize}/attributes"
end

- (Object) object_card_partial_path(object)



46
47
48
# File 'app/helpers/workbench/display_helper.rb', line 46

def object_card_partial_path(object)
  '/' + object_class_name(object) + '/card'
end

- (Object) object_class_name(object)



50
51
52
# File 'app/helpers/workbench/display_helper.rb', line 50

def object_class_name(object)
  object.class.base_class.name.tableize.to_s
end

- (Object) object_tag(object)

General wrapper around individual <model_name>_tag methods

object_tag(@otu)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/workbench/display_helper.rb', line 6

def object_tag(object)
  return nil if object.nil?
  method = object_tag_method(object)

  # meh, exceptions  
  return send("taxon_works_content_tag", object).html_safe if method == 'content_tag' 
  return image_tag(object.image_file.url(:thumb)) if method == 'image_tag' 

  if self.respond_to?(method)
    html = send(method, object)
    html ? html.html_safe : nil
  else
    nil #  content_tag(:span,"#{object.class} has no helper method '#{method}'", class: :warning)
  end
end

- (Object) object_tag_method(object)



22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/workbench/display_helper.rb', line 22

def object_tag_method(object)
  return nil if object.nil?
  klass_name = object.class.name
  method = "#{klass_name.underscore.gsub('/', '_')}_tag"
  if ApplicationController.helpers.respond_to?(method)
    method
  else
    klass_name = metamorphosize_if(object).class.name
    "#{klass_name.underscore}_tag"
  end
end