Module: TagsHelper
- Defined in:
- /var/apps/qpixel/app/helpers/tags_helper.rb
Defined Under Namespace
Classes: TagWikiScrubber
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.
-
#rendered_wiki(tag) ⇒ ActiveSupport::SafeBuffer
Renders wiki for a given tag.
- #scrubber ⇒ Object
-
#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 '/var/apps/qpixel/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.
44 45 46 47 |
# File '/var/apps/qpixel/app/helpers/tags_helper.rb', line 44 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 |
#rendered_wiki(tag) ⇒ ActiveSupport::SafeBuffer
Renders wiki for a given tag
21 22 23 |
# File '/var/apps/qpixel/app/helpers/tags_helper.rb', line 21 def rendered_wiki(tag) sanitize(tag.wiki, scrubber: scrubber) end |
#scrubber ⇒ Object
55 56 57 |
# File '/var/apps/qpixel/app/helpers/tags_helper.rb', line 55 def scrubber TagsHelper::TagWikiScrubber.new end |
#tag_classes(tag, category) ⇒ String
Generate a list of classes to be applied to a tag.
30 31 32 33 34 35 36 37 38 |
# File '/var/apps/qpixel/app/helpers/tags_helper.rb', line 30 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 |