Module: CurateHelper
- Defined in:
- app/helpers/curate_helper.rb
Instance Method Summary collapse
- #auto_link_without_protocols(url) ⇒ Object
- #classify_for_display(curation_concern) ⇒ Object
-
#collection_title_from_pid(value) ⇒ Object
Loads the object and returns its title.
- #construct_page_title(*elements) ⇒ Object
-
#creator_name_from_pid(value) ⇒ Object
Loads the person object and returns their name In this case, the value is in the format: info:fedora/<PID> So used split.
- #curation_concern_attribute_to_html(curation_concern, method_name, label = nil, options = {}) ⇒ Object
- #curation_concern_organization_path(document) ⇒ Object
- #curation_concern_page_title(curation_concern) ⇒ Object
- #default_page_title ⇒ Object
- #edit_polymorphic_path_for_asset(asset) ⇒ Object
- #link_to_edit_permissions(curation_concern, solr_document = nil) ⇒ Object
- #permission_badge_for(curation_concern, solr_document = nil) ⇒ Object
- #polymorphic_path_args(asset) ⇒ Object
- #polymorphic_path_for_asset(asset) ⇒ Object
Instance Method Details
#auto_link_without_protocols(url) ⇒ Object
122 123 124 125 |
# File 'app/helpers/curate_helper.rb', line 122 def auto_link_without_protocols(url) link = (url =~ /\A(?i)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?\z/) ? 'http://' + url : url auto_link(link, :all) end |
#classify_for_display(curation_concern) ⇒ Object
68 69 70 |
# File 'app/helpers/curate_helper.rb', line 68 def classify_for_display(curation_concern) curation_concern.human_readable_type.downcase end |
#collection_title_from_pid(value) ⇒ Object
Loads the object and returns its title
8 9 10 11 12 13 14 15 |
# File 'app/helpers/curate_helper.rb', line 8 def collection_title_from_pid value begin c = Collection.load_instance_from_solr(value) rescue => e logger.warn("WARN: Helper method collection_title_from_pid raised an error when loading #{value}. Error was #{e}") end return c.nil? ? value : c.title end |
#construct_page_title(*elements) ⇒ Object
29 30 31 |
# File 'app/helpers/curate_helper.rb', line 29 def construct_page_title(*elements) (elements.flatten.compact + [application_name]).join(" // ") end |
#creator_name_from_pid(value) ⇒ Object
Loads the person object and returns their name In this case, the value is in the format: info:fedora/<PID> So used split
20 21 22 23 24 25 26 27 |
# File 'app/helpers/curate_helper.rb', line 20 def creator_name_from_pid value begin p = Person.load_instance_from_solr(value.split("/").last) rescue => e logger.warn("WARN: Helper method create_name_from_pid raised an error when loading #{value}. Error was #{e}") end return p.nil? ? value : p.name end |
#curation_concern_attribute_to_html(curation_concern, method_name, label = nil, options = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/helpers/curate_helper.rb', line 50 def curation_concern_attribute_to_html(curation_concern, method_name, label = nil, = {}) markup = "" label ||= derived_label_for(curation_concern, method_name) subject = curation_concern.send(method_name) return markup if !subject.present? && ![:include_empty] markup << %(<tr><th>#{label}</th>\n<td><ul class='tabular'>) [subject].flatten.compact.each do |value| markup << %(<li class="attribute #{method_name}">#{h(value)}</li>\n) end markup << %(</ul></td></tr>) markup.html_safe end |
#curation_concern_organization_path(document) ⇒ Object
3 4 5 |
# File 'app/helpers/curate_helper.rb', line 3 def curation_concern_organization_path(document) organization_path(document) end |
#curation_concern_page_title(curation_concern) ⇒ Object
33 34 35 36 37 38 39 |
# File 'app/helpers/curate_helper.rb', line 33 def curation_concern_page_title(curation_concern) if curation_concern.persisted? construct_page_title(curation_concern.title, "#{curation_concern.human_readable_type} [#{curation_concern.to_param}]") else construct_page_title("New #{curation_concern.human_readable_type}") end end |
#default_page_title ⇒ Object
41 42 43 44 45 46 47 |
# File 'app/helpers/curate_helper.rb', line 41 def default_page_title text = controller_name.singularize.titleize if action_name text = "#{action_name.titleize} " + text end construct_page_title(text) end |
#edit_polymorphic_path_for_asset(asset) ⇒ Object
99 100 101 |
# File 'app/helpers/curate_helper.rb', line 99 def edit_polymorphic_path_for_asset(asset) return edit_polymorphic_path(polymorphic_path_args(asset)) end |
#link_to_edit_permissions(curation_concern, solr_document = nil) ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'app/helpers/curate_helper.rb', line 72 def (curation_concern, solr_document = nil) markup = <<-HTML <a href="#{edit_polymorphic_path_for_asset(curation_concern)}" id="permission_#{curation_concern.to_param}"> #{(curation_concern, solr_document)} </a> HTML markup.html_safe end |
#permission_badge_for(curation_concern, solr_document = nil) ⇒ Object
81 82 83 84 85 |
# File 'app/helpers/curate_helper.rb', line 81 def (curation_concern, solr_document = nil) solr_document ||= curation_concern.to_solr dom_label_class, link_title = extract_dom_label_class_and_link_title(solr_document) %(<span class="label #{dom_label_class}" title="#{link_title}">#{link_title}</span>).html_safe end |
#polymorphic_path_args(asset) ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'app/helpers/curate_helper.rb', line 87 def polymorphic_path_args(asset) # A better approximation, but we still need one location for this information # either via routes or via the initializer of the application if asset.class.included_modules.include?(CurationConcern::Model) return [:curation_concern, asset] else return asset end end |
#polymorphic_path_for_asset(asset) ⇒ Object
96 97 98 |
# File 'app/helpers/curate_helper.rb', line 96 def polymorphic_path_for_asset(asset) return polymorphic_path(polymorphic_path_args(asset)) end |