Module: PostTypesHelper
- Defined in:
- app/helpers/post_types_helper.rb
Instance Method Summary collapse
-
#post_type_badge(type) ⇒ ActiveSupport::SafeBuffer
Create a badge to display the specified post type.
-
#post_type_criteria ⇒ Array<Symbol>
private
Get a list of predicate post type attributes (i.e. is_* and has_* attributes).
-
#post_type_ids(**opts) ⇒ Array<Integer>
Get a list of post type IDs matching specified criteria.
Instance Method Details
#post_type_badge(type) ⇒ ActiveSupport::SafeBuffer
Create a badge to display the specified post type.
6 7 8 9 10 |
# File 'app/helpers/post_types_helper.rb', line 6 def post_type_badge(type) tag.span class: 'badge is-tag is-filled is-muted' do "#{tag.i(class: type.icon_name)} #{tag.span(type.name)}".html_safe end end |
#post_type_criteria ⇒ Array<Symbol>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get a list of predicate post type attributes (i.e. is_* and has_* attributes).
16 17 18 |
# File 'app/helpers/post_types_helper.rb', line 16 def post_type_criteria PostType.new.attributes.keys.select { |k| k.start_with?('has_') || k.start_with?('is_') }.map(&:to_sym) end |
#post_type_ids(**opts) ⇒ Array<Integer>
Get a list of post type IDs matching specified criteria. Available criteria are based on predicate attributes on the post_types table (i.e. has_*
and is_*
attributes).
39 40 41 42 43 44 |
# File 'app/helpers/post_types_helper.rb', line 39 def post_type_ids(**opts) key = post_type_criteria.map { |a| opts[a] ? '1' : '0' }.join Rails.cache.fetch "network/post_types/post_type_ids/#{key}", include_community: false do PostType.where(**opts).select(:id).map(&:id) end end |