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_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
129 130 131 132 |
# File 'app/helpers/curate_helper.rb', line 129 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
75 76 77 |
# File 'app/helpers/curate_helper.rb', line 75 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
4 5 6 7 8 9 10 11 |
# File 'app/helpers/curate_helper.rb', line 4 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
25 26 27 |
# File 'app/helpers/curate_helper.rb', line 25 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
16 17 18 19 20 21 22 23 |
# File 'app/helpers/curate_helper.rb', line 16 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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/helpers/curate_helper.rb', line 46 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| if method_name == :rights # Special treatment for license/rights. A URL from the Sufia gem's config/sufia.rb is stored in the descMetadata of the # curation_concern. If that URL is valid in form, then it is used as a link. If it is not valid, it is used as plain text. parsedUri = URI.parse(value) rescue nil if parsedUri.nil? markup << %(<li class="attribute #{method_name}">#{h(value)}</li>\n) else markup << %(<li class="attribute #{method_name}"><a href=#{h(value)} target="_blank"> #{h(Sufia.config.cc_licenses_reverse[value])}</a></li>\n) end else markup << %(<li class="attribute #{method_name}">#{h(value)}</li>\n) end end markup << %(</ul></td></tr>) markup.html_safe end |
#curation_concern_page_title(curation_concern) ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/helpers/curate_helper.rb', line 29 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
37 38 39 40 41 42 43 |
# File 'app/helpers/curate_helper.rb', line 37 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
106 107 108 |
# File 'app/helpers/curate_helper.rb', line 106 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
79 80 81 82 83 84 85 86 |
# File 'app/helpers/curate_helper.rb', line 79 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
88 89 90 91 92 |
# File 'app/helpers/curate_helper.rb', line 88 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
94 95 96 97 98 99 100 101 102 |
# File 'app/helpers/curate_helper.rb', line 94 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
103 104 105 |
# File 'app/helpers/curate_helper.rb', line 103 def polymorphic_path_for_asset(asset) return polymorphic_path(polymorphic_path_args(asset)) end |