Sha256: 92328d3225e18ad608cc44ea3ff41ae8b11e800ce9e45cbab4671325f8b8e9b8

Contents?: true

Size: 1.39 KB

Versions: 36

Compression:

Stored size: 1.39 KB

Contents

module PublishMyData
  module ResourcesHelper

    # uses eager loaded data to get the uri or label for a term
    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

    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

    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
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
publish_my_data-1.3.25 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.24 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.23 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.22 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.21 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.20 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.19 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.18 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.17 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.16 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.15 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.14 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.13 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.12 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.11 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.10 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.9 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.8 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.7 app/helpers/publish_my_data/resources_helper.rb
publish_my_data-1.3.6 app/helpers/publish_my_data/resources_helper.rb