Module: TagsHelper
- Defined in:
- app/helpers/tags_helper.rb
Instance Method Summary collapse
-
#category_sort_tags(tags, required_ids, topic_ids, moderator_ids) ⇒ Array<Tag>
Sort a list of tags by importance within the context of a category’s set of required, moderator, and topic tags.
-
#post_ids_for_tags(tag_ids) ⇒ Array<Integer>
Get a list of post IDs that belong to any of the specified tag IDs.
-
#tag_classes(tag, category) ⇒ String
Generate a list of classes to be applied to a tag.
Instance Method Details
#category_sort_tags(tags, required_ids, topic_ids, moderator_ids) ⇒ Array<Tag>
Sort a list of tags by importance within the context of a category’s set of required, moderator, and topic tags.
9 10 11 12 13 14 15 16 |
# File 'app/helpers/tags_helper.rb', line 9 def (, required_ids, topic_ids, moderator_ids) .to_a .sort_by do |t| [required_ids.include?(t.id) ? 0 : 1, moderator_ids.include?(t.id) ? 0 : 1, topic_ids.include?(t.id) ? 0 : 1, t.id] end end |
#post_ids_for_tags(tag_ids) ⇒ Array<Integer>
Get a list of post IDs that belong to any of the specified tag IDs.
37 38 39 40 |
# File 'app/helpers/tags_helper.rb', line 37 def (tag_ids) sql = "SELECT post_id FROM posts_tags WHERE tag_id IN #{ApplicationRecord.sanitize_sql_in(tag_ids)}" ActiveRecord::Base.connection.execute(sql).to_a.flatten end |
#tag_classes(tag, category) ⇒ String
Generate a list of classes to be applied to a tag.
23 24 25 26 27 28 29 30 31 |
# File 'app/helpers/tags_helper.rb', line 23 def tag_classes(tag, category) required_ids = category&.required_tag_ids moderator_ids = category&.moderator_tag_ids topic_ids = category&.topic_tag_ids required = required_ids&.include?(tag.id) ? 'is-filled' : '' topic = topic_ids&.include?(tag.id) ? 'is-outlined' : '' moderator = moderator_ids&.include?(tag.id) ? 'is-red is-outlined' : '' "badge is-tag #{required} #{topic} #{moderator}" end |