Sha256: 2df5d9e48d6e81985b5ba8626fb628135a2ec492567269fbf3c4f362093e8e2d

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

module Calagator

module TagsHelper
  def tag_links_for(model)
    model.tags.sort_by(&:name).map{|tag| tag_link(model.class.model_name.human.downcase, tag)}.join(', ').html_safe
  end

  def tag_link(type, tag, link_class=nil)
    internal_url = "/#{type.pluralize}/tag/#{tag.name}"

    link_classes = [link_class, "p-category"]
    link_classes << "external #{tag.machine_tag[:namespace]} #{tag.machine_tag[:predicate]}" if tag.machine_tag[:url]

    link_text = [tag_icon(tag.name), escape_once(tag.name)].compact.join(' ').html_safe

    link_to link_text, (tag.machine_tag[:url] || internal_url), :class => link_classes.compact.join(' ')
  end
  private :tag_link

  def icon_exists_for?(tag_name)
    !!Rails.application.assets["tag_icons/#{tag_name}.png"]
  end

  def tag_icon(tag_name)
    if icon_exists_for?(tag_name)
      image_tag(asset_path("tag_icons/#{tag_name}.png"), title: tag_name)
    end
  end

  def get_tag_icon_links(event)
    event.tag_list.map do |tag_name|
      icon = tag_icon(tag_name)
      link_to(icon, tag_events_path(tag_name)) if icon
    end
  end

  def display_tag_icons(event)
    get_tag_icon_links(event).join(' ').html_safe
  end
end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
calagator-1.0.0.rc2 app/helpers/calagator/tags_helper.rb
calagator-1.0.0.rc1 app/helpers/calagator/tags_helper.rb
calagator-0.0.1.pre1 app/helpers/calagator/tags_helper.rb