Module: Redmineup::TagsHelper

Defined in:
lib/redmineup/helpers/tags_helper.rb

Instance Method Summary collapse

Instance Method Details

#monochrome?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/redmineup/helpers/tags_helper.rb', line 26

def monochrome?
  @monochrome ||= defined?(RedmineupTags) && !RedmineupTags.use_colors?
end

#tag_cloud(tags, classes) ⇒ Object

See the README for an example using tag_cloud.



4
5
6
7
8
9
10
11
# File 'lib/redmineup/helpers/tags_helper.rb', line 4

def tag_cloud(tags, classes)
  return if tags.empty?
  max_count = tags.sort_by(&:count).last.count.to_f
  tags.each do |tag|
    index = ((tag.count / max_count) * (classes.size - 1)).round
    yield tag, classes[index]
  end
end

Renders span.tag_list from an array of tag objects (respond to .name and .count). Resolves URL via ‘key_tag_url(name)` in the current view context.

tag_cloud_links(contact.available_tags, :contact)   # → contact_tag_url(name)
tag_cloud_links(tags_cloud, :people)                # → people_tag_url(name)

Raises:

  • (NoMethodError)


42
43
44
45
46
47
48
49
50
51
# File 'lib/redmineup/helpers/tags_helper.rb', line 42

def tag_cloud_links(tags, key, options = {})
  return if tags.blank?
  url_method = :"#{key}_tag_url"
  raise NoMethodError, "#{url_method} is not defined in view context" unless respond_to?(url_method, true)
  (:span, class: 'tag_list') do
    safe_join(tags.map { |tag|
      tag_link(send(url_method, tag.name), tag.name, options.merge(count: tag.count).dup)
    }, tag_separator)
  end
end


13
14
15
16
17
18
19
20
# File 'lib/redmineup/helpers/tags_helper.rb', line 13

def tag_link(url, tag_name, options = {})
  count      = options.delete(:count)
  inner      = link_to(tag_name, url, options)
  inner << ('span', "(#{count})", class: 'tag-count') if count
  css        = monochrome? ? 'tag-label' : 'tag-label-color'
  style      = monochrome? ? {} : { style: "background-color: #{Redmineup::ActsAsTaggable::Tag.color_from_name(tag_name)}" }
  (:span, inner, { class: css }.merge(style))
end


30
31
32
33
34
35
# File 'lib/redmineup/helpers/tags_helper.rb', line 30

def tag_links(tag_list, options = {}, &url_block)
  return if tag_list.blank?
  (:span, class: 'tag_list') do
    safe_join(tag_list.map { |tag| tag_link(url_block.call(tag), tag, options.dup) }, tag_separator)
  end
end

#tag_separatorObject



22
23
24
# File 'lib/redmineup/helpers/tags_helper.rb', line 22

def tag_separator
  monochrome? ? ', ' : ' '
end