Class: Components::Tag
- Inherits:
-
Base
- Object
- Base
- Components::Tag
- Includes:
- Phlex::Rails::Helpers::LinkTo
- Defined in:
- app/components/tag.rb
Constant Summary collapse
- CLASSES =
"badge rounded-pill bg-secondary tag"
Instance Method Summary collapse
-
#initialize(tag:, show_count: false, filters: {}, html_options: {}, filter_in_place: false, link: true) ⇒ Tag
constructor
A new instance of Tag.
- #view_template ⇒ Object
Constructor Details
#initialize(tag:, show_count: false, filters: {}, html_options: {}, filter_in_place: false, link: true) ⇒ Tag
Returns a new instance of Tag.
8 9 10 11 12 13 14 15 16 |
# File 'app/components/tag.rb', line 8 def initialize(tag:, show_count: false, filters: {}, html_options: {}, filter_in_place: false, link: true) @tag = tag @show_count = show_count @filter_in_place = filter_in_place @filters = filters || {} @filters[:tag] ||= [] @html_options = .merge({class: CLASSES}) @link = link end |
Instance Method Details
#view_template ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/components/tag.rb', line 18 def view_template new_filters = @filters.merge(tag: @filters[:tag] | [@tag.name]) span itemprop: "keywords" do if @link link_to (@filter_in_place ? new_filters : models_path(new_filters)), @html_options do parts = [@tag.name] parts << "(#{@tag.taggings_count})" if @show_count parts.join " " end else span(class: CLASSES) { @tag.name } end end end |