Module: Alchemy::Admin::TagsHelper
- Defined in:
- app/helpers/alchemy/admin/tags_helper.rb
Instance Method Summary collapse
-
#filtered_by_tag?(tag) ⇒ Boolean
Returns true if the given tag is in
params[:tagged_with]
. -
#render_tag_list(class_name) ⇒ String
Renders tags list items for given class name.
- #sorted_tags_from(class_name:) ⇒ Object
-
#tags_for_filter(current:) ⇒ Object
Returns the tags from params suitable for the tags filter.
-
#tags_from_params ⇒ Object
Returns tags from params.
Instance Method Details
#filtered_by_tag?(tag) ⇒ Boolean
Returns true if the given tag is in params[:tagged_with]
34 35 36 |
# File 'app/helpers/alchemy/admin/tags_helper.rb', line 34 def filtered_by_tag?(tag) .include?(tag.name) end |
#render_tag_list(class_name) ⇒ String
Renders tags list items for given class name
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'app/helpers/alchemy/admin/tags_helper.rb', line 14 def render_tag_list(class_name) raise ArgumentError, "Please provide a String as class_name" if class_name.nil? (class_name: class_name).map do |tag| content_tag("li", name: tag.name, class: filtered_by_tag?(tag) ? "active" : nil) do link_to( "#{tag.name} (#{tag.taggings_count})", url_for( search_filter_params.except(:page, :tagged_with).merge( tagged_with: (current: tag).presence ) ), remote: request.xhr? ) end end.join.html_safe end |
#sorted_tags_from(class_name:) ⇒ Object
56 57 58 |
# File 'app/helpers/alchemy/admin/tags_helper.rb', line 56 def (class_name:) class_name.constantize.tag_counts.sort { |x, y| x.name.downcase <=> y.name.downcase } end |
#tags_for_filter(current:) ⇒ Object
Returns the tags from params suitable for the tags filter.
42 43 44 45 46 47 48 |
# File 'app/helpers/alchemy/admin/tags_helper.rb', line 42 def (current:) if filtered_by_tag?(current) - Array(current.name) else .push(current.name) end.uniq.join(",") end |
#tags_from_params ⇒ Object
Returns tags from params
52 53 54 |
# File 'app/helpers/alchemy/admin/tags_helper.rb', line 52 def search_filter_params[:tagged_with].to_s.split(",") end |