Sha256: edaa01cd3dbdc5e9d8a144408a6469815567bda31f4516e8cbd2c0c6d327b097

Contents?: true

Size: 645 Bytes

Versions: 6

Compression:

Stored size: 645 Bytes

Contents

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_article_counters.
      take(maximum_tags.to_i).sort_by(&:name)
  end

  def sizes
    return @sizes if @sizes
    total = @tags.reduce(0) { |sum, tag| sum + tag.article_counter }
    average = total.to_f / @tags.size.to_f
    @sizes = @tags.reduce({}) do |h, tag|
      size = tag.article_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

6 entries across 6 versions & 1 rubygems

Version Path
publify_core-9.0.0.pre6 app/models/tag_sidebar.rb
publify_core-9.0.0.pre5 app/models/tag_sidebar.rb
publify_core-9.0.0.pre4 app/models/tag_sidebar.rb
publify_core-9.0.0.pre3 app/models/tag_sidebar.rb
publify_core-9.0.0.pre2 app/models/tag_sidebar.rb
publify_core-9.0.0.pre1 app/models/tag_sidebar.rb