Sha256: f11dbb9ef171f9925649d2ba6feb4a4aa5284a41692c86f61417c99f0f8f07d6

Contents?: true

Size: 670 Bytes

Versions: 21

Compression:

Stored size: 670 Bytes

Contents

# frozen_string_literal: true

class TagSidebar < Sidebar
  display_name "Tags"
  description "Show most popular tags for this blog"

  setting :maximum_tags, 20

  def tags
    @tags ||= Tag.find_all_with_content_counters.
      take(maximum_tags.to_i).sort_by(&:name)
  end

  def sizes
    return @sizes if @sizes

    total = tags.reduce(0) { |sum, tag| sum + tag.content_counter }
    average = total.to_f / @tags.size
    @sizes = tags.reduce({}) do |h, tag|
      size = tag.content_counter.to_f / average
      h.merge tag => [[2.0 / 3.0, size].max, 2].min * 100
    end
  end

  def font_multiplier
    80
  end
end

SidebarRegistry.register_sidebar TagSidebar

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
HornsAndHooves-publify_core-10.5.0 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.4.0 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.3.0 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.2.0 app/models/tag_sidebar.rb
publify_core-9.2.10 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.1.1 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.1.0 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.0.3 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.0.2 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.0.1 app/models/tag_sidebar.rb
HornsAndHooves-publify_core-10.0.0 app/models/tag_sidebar.rb
publify_core-9.2.9 app/models/tag_sidebar.rb
publify_core-9.2.8 app/models/tag_sidebar.rb
publify_core-9.2.7 app/models/tag_sidebar.rb
publify_core-9.2.6 app/models/tag_sidebar.rb
publify_core-9.2.5 app/models/tag_sidebar.rb
publify_core-9.2.4 app/models/tag_sidebar.rb
publify_core-9.2.3 app/models/tag_sidebar.rb
publify_core-9.2.2 app/models/tag_sidebar.rb
publify_core-9.2.1 app/models/tag_sidebar.rb