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. See /app/helpers/README.md for more.
TODO: rename ObjectDisplay
Instance Method Summary collapse
- #kind(object) ⇒ Object
-
#label_for(object) ⇒ Object
General wrapper around individual <model_name>_tag methods label_for(@otu).
- #label_for_method(object) ⇒ Object
- #model_name_title ⇒ Object
- #object_attributes_partial_path(object) ⇒ Object
- #object_card_partial_path(object) ⇒ Object
- #object_class_name(object) ⇒ Object
-
#object_tag(object) ⇒ Object
General wrapper around individual <model_name>_tag methods object_tag(@otu).
- #object_tag_method(object) ⇒ Object
-
#regex_mark_tag(text, term) ⇒ String?
Use ‘mark` tags to highlight the position of the term in the text.
Instance Method Details
#kind(object) ⇒ Object
67 68 69 |
# File 'app/helpers/workbench/display_helper.rb', line 67 def kind(object) object.class.name.humanize end |
#label_for(object) ⇒ Object
General wrapper around individual <model_name>_tag methods
label_for(@otu)
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/workbench/display_helper.rb', line 39 def label_for(object) return nil if object.nil? method = label_for_method(object) if self.respond_to?(method) string = send(method, object) return string if string else nil end end |
#label_for_method(object) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/workbench/display_helper.rb', line 51 def label_for_method(object) return nil if object.nil? klass_name = object.class.name method = "label_for_#{klass_name.underscore.gsub('/', '_')}" if ApplicationController.helpers.respond_to?(method) method else klass_name = (object).class.name "label_for_#{klass_name.underscore}" end end |
#model_name_title ⇒ Object
63 64 65 |
# File 'app/helpers/workbench/display_helper.rb', line 63 def model_name_title controller_name.humanize end |
#object_attributes_partial_path(object) ⇒ Object
71 72 73 |
# File 'app/helpers/workbench/display_helper.rb', line 71 def object_attributes_partial_path(object) "/#{(object).class.base_class.name.tableize}/attributes" end |
#object_card_partial_path(object) ⇒ Object
75 76 77 |
# File 'app/helpers/workbench/display_helper.rb', line 75 def object_card_partial_path(object) '/' + object_class_name(object) + '/card' end |
#object_class_name(object) ⇒ Object
79 80 81 |
# File 'app/helpers/workbench/display_helper.rb', line 79 def object_class_name(object) object.class.base_class.name.tableize.to_s end |
#object_tag(object) ⇒ Object
General wrapper around individual <model_name>_tag methods
object_tag(@otu)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/helpers/workbench/display_helper.rb', line 9 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_tag_method(object) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/helpers/workbench/display_helper.rb', line 25 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 = (object).class.name "#{klass_name.underscore}_tag" end end |
#regex_mark_tag(text, term) ⇒ String?
Returns use ‘mark` tags to highlight the position of the term in the text.
85 86 87 88 89 90 91 92 |
# File 'app/helpers/workbench/display_helper.rb', line 85 def regex_mark_tag(text, term) return text if term.nil? if t = text[/#{Regexp.escape(term)}/i] # probably some look-ahead (behind) magic could be used here text.gsub(/#{Regexp.escape(term)}/i, "<mark>#{t}</mark>") else text end end |