Module: Redmineup::TagsHelper
- Defined in:
- lib/redmineup/helpers/tags_helper.rb
Instance Method Summary collapse
- #monochrome? ⇒ Boolean
-
#tag_cloud(tags, classes) ⇒ Object
See the README for an example using tag_cloud.
-
#tag_cloud_links(tags, key, options = {}) ⇒ Object
Renders span.tag_list from an array of tag objects (respond to .name and .count).
- #tag_link(url, tag_name, options = {}) ⇒ Object
- #tag_links(tag_list, options = {}, &url_block) ⇒ Object
- #tag_separator ⇒ Object
Instance Method Details
#monochrome? ⇒ 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(, classes) return if .empty? max_count = .sort_by(&:count).last.count.to_f .each do |tag| index = ((tag.count / max_count) * (classes.size - 1)).round yield tag, classes[index] end end |
#tag_cloud_links(tags, key, options = {}) ⇒ Object
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., :contact) # → contact_tag_url(name)
tag_cloud_links(, :people) # → people_tag_url(name)
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/redmineup/helpers/tags_helper.rb', line 42 def tag_cloud_links(, key, = {}) return if .blank? url_method = :"#{key}_tag_url" raise NoMethodError, "#{url_method} is not defined in view context" unless respond_to?(url_method, true) content_tag(:span, class: 'tag_list') do safe_join(.map { |tag| tag_link(send(url_method, tag.name), tag.name, .merge(count: tag.count).dup) }, tag_separator) end end |
#tag_link(url, tag_name, options = {}) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/redmineup/helpers/tags_helper.rb', line 13 def tag_link(url, tag_name, = {}) count = .delete(:count) inner = link_to(tag_name, url, ) inner << content_tag('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)}" } content_tag(:span, inner, { class: css }.merge(style)) end |
#tag_links(tag_list, options = {}, &url_block) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/redmineup/helpers/tags_helper.rb', line 30 def tag_links(tag_list, = {}, &url_block) return if tag_list.blank? content_tag(:span, class: 'tag_list') do safe_join(tag_list.map { |tag| tag_link(url_block.call(tag), tag, .dup) }, tag_separator) end end |
#tag_separator ⇒ Object
22 23 24 |
# File 'lib/redmineup/helpers/tags_helper.rb', line 22 def tag_separator monochrome? ? ', ' : ' ' end |