Module: ResourceLinksHelper

Defined in:
app/helpers/resource_links_helper.rb

Overview

Utilities for building ResourceLink views

See Also:

Constant Summary collapse

SELF_ID =
' (self)'.freeze

Instance Method Summary collapse

Instance Method Details

#object_resource_choices_for(resources, subject_resource) ⇒ Array<Integer, String>

Returns a collection of linkable objects for use with ResourceLink forms

Parameters:

  • resources (Array<Resource>)

    the pool of total resources available for linking

  • subject_resource (Resource)

    the potential subject of a new ResourceLink predicate

Returns:

  • (Array<Integer, String>)

    a collection of linkable objects for use with ResourceLink forms



7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/resource_links_helper.rb', line 7

def object_resource_choices_for(resources, subject_resource)
  resources.map do |resource|
    option_name = if resource == subject_resource
                    "#{resource.title} #{SELF_ID}"
                  else
                    resource.label
                  end
    [option_name, resource.id]
  end
end

#predicate_for(resource_link) ⇒ String

Returns a subject-verb-object predicate that describes the resource link

Parameters:

  • resource_link (ResourceLink)

    the object to render as a predicate

Returns:

  • (String)

    a subject-verb-object predicate that describes the resource link



20
21
22
# File 'app/helpers/resource_links_helper.rb', line 20

def predicate_for(resource_link)
  "#{sanitize(resource_link.subject_resource_title)} #{(:em, resource_link.verb)} #{sanitize(resource_link.object_resource_title)}".html_safe
end