link_helper.rb revision 0d3763fcd43f738899afcf8699b0e02b833c8132
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainenmodule LinkHelper
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen include ExternalMapping
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
bdd36cfdba3ff66d25570a9ff568d69e1eb543cfTimo Sirainen def counter_link(url, counter, subject)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen text = content_tag(:strong, counter || '?')
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen text << content_tag(:span, counter == 1 ? subject : subject.pluralize)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen link_to text, url
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen end
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
9522aa5f33cc37fe8ccd0d647cc51dd3ba6a9b55Timo Sirainen def fancy_link(resource)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return nil unless resource
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen data_type, value = determine_image_type(resource)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen name = block_given? ? yield(resource) : resource
4fda77c9e9fc68feb292c4dacae1fac49dd08165Timo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen title_target = resource.respond_to?(:last) ? resource.last : resource
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen title = title_target.title if title_target.respond_to?(:title)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen linked_to =
f158d9a303bb15a6848ca276c9391c7ca52e452bTimo Sirainen if resource.respond_to?(:locid)
f158d9a303bb15a6848ca276c9391c7ca52e452bTimo Sirainen locid_for(resource)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen elsif resource.is_a?(Ontology)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen repository_ontology_path(resource.repository, resource)
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen else
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen resource
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen end
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen link_to name, linked_to,
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen data_type => value,
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen title: title
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen end
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen def format_links(*args, &block)
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen options = args.extract_options!
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen args = %w(xml json) if args.empty?
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen args.flatten!
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen options[:url] ||= {}
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen links = ''
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen links << capture(&block) << ' ' if block_given?
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen links << args.collect do |f|
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen content_tag :li, link_to(f.to_s.upcase, params.merge(options[:url]).merge(format: f), title: "Get this page as #{f.upcase}")
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end.join("")
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen content_tag('ul', links.html_safe, class: 'formats')
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainen end
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen def determine_image_type(resource)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if resource.is_a?(Repository) && resource.is_private
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen return ['data-type', "Private#{resource.class.to_s}"]
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end
11ee3b40320a31669bd717fecbe1e332dad4fd84Timo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen if resource.is_a?(Repository) && resource.mirror?
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return ['data-type', "Remote#{resource.class.to_s}"]
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen unless resource.is_a?(Ontology)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen return ['data-type', resource.class.to_s]
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end
cf9d67e4a9bfee31cf3be05244555d51a3d1b9feTimo Sirainen
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen data_type = 'data-ontologyclass'
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen distributed_type = ->(distributed_ontology) do
093b42b11c1236a687d3da564b26a324e2189ae6Timo Sirainen if distributed_ontology.homogeneous?
a5ddfd7a8b473f73135b93d5e081e470a87f0f7eTimo Sirainen "distributed_homogeneous_ontology"
a5ddfd7a8b473f73135b93d5e081e470a87f0f7eTimo Sirainen else
09060303d565e15d54e42b4ef722f9d3c26f5336Timo Sirainen "distributed_heterogeneous_ontology"
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen end
e2a88d59c0d47d63ce1ad5b1fd95e487124a3fd4Timo Sirainen
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen value = if resource.is_a?(DistributedOntology)
2670cd577aa57eb9f915a4f4220ae48c9b4fc5fbTimo Sirainen distributed_type[resource]
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen else
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen if resource.parent
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen "single_in_#{distributed_type[resource.parent]}"
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen else
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen 'single_ontology'
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen end
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen end
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen
eb209d12e3b1cfed564c35cf19fdb1bf7fcc6811Timo Sirainen [data_type, value]
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen end
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen def ontology_link_to(resource)
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen data_type, value = determine_image_type(resource)
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen content_tag(:span, class: 'ontology_title') do
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen link_to resource, {}, data_type => value
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen end
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen end
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen def wiki_link(controller, action)
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen generate_external_link controller, action, 'controller', 'wiki'
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen end
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainenend
8b16d3b00f051401c97568697ccdbba48663759aTimo Sirainen