link_helper.rb revision 7cc85babaf117501a3a0846f6ebff3ae44a2709b
1516N/Amodule LinkHelper
154N/A
154N/A include ExternalMapping
154N/A
154N/A def counter_link(url, counter, subject)
154N/A text = content_tag(:strong, counter || '?')
154N/A text << content_tag(:span, counter == 1 ? subject : subject.pluralize)
154N/A
154N/A link_to text, url
154N/A end
154N/A
154N/A def fancy_link(resource)
154N/A return nil unless resource
154N/A
154N/A clazz = resource.class
154N/A clazz = 'Ontology' if clazz.to_s.include?('Ontology')
409N/A data_type, value = determine_image_type(resource)
409N/A
154N/A name = block_given? ? yield(resource) : resource
154N/A
154N/A if resource.is_a? Array
154N/A title = resource.last.respond_to?(:title) ? resource.last.title : nil
3339N/A else
154N/A title = resource.respond_to?(:title) ? resource.title : nil
3339N/A end
1715N/A
1715N/A if resource.is_a? Ontology
1715N/A linked_to = repository_ontology_path(resource.repository, resource)
1715N/A else
526N/A linked_to = resource
154N/A end
154N/A
2721N/A link_to name, linked_to,
2721N/A data_type => value,
154N/A :title => title
430N/A end
154N/A
2721N/A def format_links(*args, &block)
2721N/A options = args.extract_options!
2721N/A args = %w(xml json) if args.empty?
2721N/A args.flatten!
2983N/A
2983N/A options[:url] ||= {}
2721N/A
2721N/A links = ''
2721N/A links << capture(&block) << ' ' if block_given?
2721N/A links << args.collect do |f|
2721N/A content_tag :li, link_to(f.to_s.upcase, params.merge(options[:url]).merge(format: f), title: "Get this page as #{f.upcase}")
2721N/A end.join("")
2721N/A
2721N/A content_tag('ul', links.html_safe, class: 'formats')
154N/A end
2721N/A
2721N/A def determine_image_type(resource)
158N/A if resource.is_a?(Repository) && resource.is_private
2721N/A return ['data-type', "Private#{resource.class.to_s}"]
2721N/A end
2721N/A
2721N/A if resource.is_a?(Repository) && resource.mirror?
2721N/A return ['data-type', "Remote#{resource.class.to_s}"]
3236N/A end
2721N/A
1185N/A unless resource.is_a?(Ontology)
2721N/A return ['data-type', resource.class.to_s]
2721N/A end
154N/A
2721N/A data_type = 'data-ontologyclass'
2721N/A
2721N/A distributed_type = ->(distributed_ontology) do
2721N/A if distributed_ontology.homogeneous?
3236N/A "distributed_homogeneous_ontology"
2721N/A else
158N/A "distributed_heterogeneous_ontology"
2721N/A end
2721N/A end
2721N/A
2721N/A value = if resource.is_a?(DistributedOntology)
2721N/A distributed_type[resource]
3158N/A else
3339N/A if resource.parent
2721N/A "single_in_#{distributed_type[resource.parent]}"
2721N/A else
3236N/A 'single_ontology'
2721N/A end
154N/A end
3236N/A
3236N/A [data_type, value]
2962N/A end
2962N/A
2962N/A def ontology_link_to(resource)
2962N/A data_type, value = determine_image_type(resource)
2962N/A content_tag(:span, class: 'ontology_title') do
2962N/A link_to resource, {}, data_type => value
2962N/A end
2962N/A end
3236N/A
3339N/A def sort_link_list(collection)
3339N/A hash = {}
2962N/A
3236N/A collection.each_with_index do |link, i|
3339N/A if link.symbol_mappings.empty?
3339N/A hash["empty#{i}"] = [{link: link, target: ""}]
2962N/A else
3236N/A link.symbol_mappings.each do |mapping|
3339N/A sym = mapping.source.to_s.to_sym
3339N/A if hash[sym]
2962N/A hash[sym] << {link: link, target: mapping.target}
3236N/A else
3339N/A hash[sym] = [{link: link, target: mapping.target}]
3339N/A end
2962N/A end
2962N/A end
154N/A end
2721N/A
hash
end
def wiki_link(controller, action)
generate_external_link controller, action, 'controller', 'wiki'
end
end