link_helper.rb revision 8d050e0562ded9f29d349f3589d870fe9121f7e2
409N/Amodule LinkHelper
26N/A
26N/A def sort_link_list(collection)
26N/A hash = {}
26N/A collection.each_with_index do |link, i|
26N/A if link.entity_mappings.empty?
26N/A hash["empty#{i}"] = [{link: link, target: ""}]
26N/A else
26N/A link.entity_mappings.each do |mapping|
26N/A sym = mapping.source.to_s.to_sym
26N/A if hash[sym]
26N/A hash[sym] << {link: link, target: mapping.target}
26N/A else
26N/A hash[sym] = [{link: link, target: mapping.target}]
26N/A end
26N/A end
26N/A end
26N/A end
26N/A return hash
26N/A end
26N/A
26N/A def fancy_link(resource)
1191N/A return nil unless resource
26N/A
26N/A clazz = resource.class
1431N/A clazz = 'Ontology' if clazz.to_s.include?('Ontology')
1218N/A data_type, value = determine_image_type(resource)
1431N/A
1218N/A name = block_given? ? yield(resource) : resource
576N/A
576N/A unless resource.is_a? Array then
1431N/A title = resource.respond_to?(:title) ? resource.title : nil
1431N/A else
1431N/A title = resource.last.respond_to?(:title) ? resource.last.title : nil
1431N/A end
1431N/A
1431N/A if resource.is_a? Ontology
1431N/A linked_to = repository_ontology_path(resource.repository, resource)
1431N/A else
576N/A linked_to = resource
576N/A end
576N/A
576N/A link_to name, linked_to,
576N/A data_type => value,
576N/A :title => title
1431N/A end
1431N/A
1431N/A def determine_image_type(resource)
696N/A if resource.is_a?(Repository) && resource.is_private
1448N/A return ['data-type', "Private#{resource.class.to_s}"]
1448N/A end
1448N/A
1448N/A unless resource.is_a? Ontology
1218N/A return ['data-type', resource.class.to_s]
1448N/A end
1218N/A
1448N/A data_type = 'data-ontologyclass'
1448N/A distributed_type = ->(distributed_ontology) do
1218N/A if distributed_ontology.homogeneous?
1218N/A "distributed_homogeneous_ontology"
1218N/A else
1218N/A "distributed_heterogeneous_ontology"
1448N/A end
1448N/A end
1448N/A
1218N/A value = if resource.is_a?(DistributedOntology)
1218N/A distributed_type[resource]
1218N/A else
1218N/A if resource.parent
1218N/A "single_in_#{distributed_type[resource.parent]}"
1218N/A else
1218N/A 'single_ontology'
1218N/A end
1218N/A end
1218N/A
1218N/A [data_type, value]
1218N/A end
1218N/A
1218N/A def ontology_link_to(resource)
1218N/A data_type, value = determine_image_type(resource)
1218N/A
1218N/A content_tag(:span, class: 'ontology_title') do
1218N/A link_to resource, {}, data_type => value
1218N/A end
1218N/A end
1218N/A
1218N/A def counter_link(url, counter, subject)
1218N/A text = content_tag(:strong, counter || '?')
1218N/A text << content_tag(:span, counter==1 ? subject : subject.pluralize)
1218N/A
1218N/A link_to text, url
1448N/A end
1448N/A
1448N/A def format_links(*args, &block)
1448N/A options = args.extract_options!
1448N/A args = %w(xml json) if args.empty?
1448N/A args.flatten!
1448N/A
1448N/A options[:url] ||= {}
1448N/A
1448N/A links = ''
1448N/A links << capture(&block) << ' ' if block_given?
1448N/A links << args.collect{ |f|
1448N/A content_tag :li, link_to(f.to_s.upcase, params.merge(options[:url]).merge(:format => f), :title => "Get this page as #{f.upcase}")
1448N/A }.join("")
1448N/A
1448N/A content_tag('ul', links.html_safe, :class => 'formats')
1448N/A end
1448N/A
1431N/Aend
1431N/A