Module: PublishMyData::ResourcesHelper

Defined in:
app/helpers/publish_my_data/resources_helper.rb

Instance Method Summary collapse

Instance Method Details

#resource_path_from_uri(uri) ⇒ Object



19
20
21
22
23
24
25
26
# File 'app/helpers/publish_my_data/resources_helper.rb', line 19

def resource_path_from_uri(uri)
  resource = Resource.new(uri)
  if resource.in_domain?(request.host)
    uri.to_s
  else
    publish_my_data.show_resource_path(:uri => uri.to_s)
  end
end

#resource_uri_or_label(resource, term) ⇒ Object

uses eager loaded data to get the uri or label for a term



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/helpers/publish_my_data/resources_helper.rb', line 5

def resource_uri_or_label(resource, term)

  if term.try(:uri?) # if it's a RDF::URI it will respond to uri? with true
    res = resource.get_related_resource(term, PublishMyData::Resource)
    if res
      link_to((res.label || res.uri.to_s), resource_path_from_uri(res.uri))
    else
      link_to term.to_s, resource_path_from_uri(term)
    end
  else
    term.to_s
  end
end

#resources_list_table_titleObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/helpers/publish_my_data/resources_helper.rb', line 28

def resources_list_table_title

  str = "<strong> #{pluralize @resources.total_count, 'resource'}</strong>"
  if @type_filter
    str += " of type "
    if @type
      str += link_to @type.label || @type.uri, resource_path_from_uri(@type.uri)
    else
      str += link_to @type_filter, resource_path_from_uri(@type_filter)
    end
  end

  if @dataset_filter
    str += " in dataset "
    if @dataset
      str += link_to @dataset.title, @dataset
    else
      str += link_to @dataset_filter, resource_path_from_uri(@dataset_filter)
    end
  end

  str.html_safe
end