Module: ResourcesHelper
- Included in:
- ScavengerHunt::ApplicationHelper
- Defined in:
- app/helpers/resources_helper.rb
Overview
View methods for displaying resources
Instance Method Summary collapse
- #resource_content_uri(resource) ⇒ Object
- #resource_group_list ⇒ Object
- #resource_link(resource, options = {}) ⇒ Object
-
#resource_link_target(resource, options = {}) ⇒ String
An HTML fragment that best depicts the resource (such as an image thumbnail, or an audio icon) based on the type of resource.
- #resource_status_list(resource, id: nil, title_tag: :h2) ⇒ Object
- #scope_search_collection ⇒ Object
Instance Method Details
#resource_content_uri(resource) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/helpers/resources_helper.rb', line 28 def resource_content_uri(resource) if resource.source_uri.present? resource.source_uri elsif resource.uploaded_resource.attached? # FIXME: Metamagic's, ahem, "magic" is hijacking `url_for` and causing # this to explode, so we call the helper method directly rather than # using the included one that has been overridden by, ahem, poorly # behaving libraries Rails.application.routes.url_helpers.url_for(resource.uploaded_resource) else nil end end |
#resource_group_list ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'app/helpers/resources_helper.rb', line 9 def resource_group_list if current_user.staff? current_organization.resource_groups else current_user.resource_groups end.by_default_and_name.map do |c| [c.title_with_default_annotation, c.id] end end |
#resource_link(resource, options = {}) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'app/helpers/resources_helper.rb', line 19 def resource_link(resource, = {}) = .delete(:link) || {} target = .delete(:href) || resource_path(resource) link_to(target, ) do resource_link_target(resource, .merge(alt: [:alt] || "Image for resource ##{resource.id}")) end end |
#resource_link_target(resource, options = {}) ⇒ String
Returns an HTML fragment that best depicts the resource (such as an image thumbnail, or an audio icon) based on the type of resource
46 47 48 49 50 51 52 |
# File 'app/helpers/resources_helper.rb', line 46 def resource_link_target(resource, = {}) if resource.viewable? image_tag(resource_content_uri(resource), ) else "#{resource.title} (#{resource.resource_type})" end end |
#resource_status_list(resource, id: nil, title_tag: :h2) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/helpers/resources_helper.rb', line 54 def resource_status_list(resource, id: nil, title_tag: :h2) return unless resource.statuses.any? id ||= "resource-#{resource.id}" = [] if resource.unrepresented? .push(tag_for('Undescribed', type: :neutral, hint: 'Status')) elsif resource.partially_complete? .push(tag_for('Partially Completed', type: :partial, hint: 'Status')) elsif resource.approved? .push(tag_for('Approved', type: :success, hint: 'Status')) end resource..each do |metum| .push(metum_tag(metum, tag: :li)) end .push(tag_for('Urgent', type: :error)) if resource.priority_flag? if resource.ordinality.present? .push(tag_for(resource.ordinality.to_s)) end ( content_tag(title_tag, class: 'sr-only', id: "tag-list-#{id}") { "Properties for resource ##{resource.id}" } + content_tag(:ul, aria: { labelledby: "tag-list-#{id}" }, class: 'tag-list') { .join.html_safe } ).html_safe end |
#scope_search_collection ⇒ Object
3 4 5 6 7 |
# File 'app/helpers/resources_helper.rb', line 3 def scope_search_collection Resource.ransackable_scopes.map do |scope_name| [scope_name.to_s.titleize.split(/\s+/).join(' & ').html_safe, scope_name] end end |