【问题标题】:Algorithm for assignment of css categories in act-as-taggable-on gem在act-as-taggable-on gem中分配css类别的算法
【发布时间】:2017-05-13 18:42:32
【问题描述】:

我正在使用作为可标记的 gem。试图了解标签是如何在 4 个 css 类别之间分配的。如本例所示:https://github.com/mbleigh/acts-as-taggable-on#tag-cloud-calculations

决定分配给每个 css 类别的标签数量的算法是什么?我可以将 css 类别的数量从 4 更改为 6,例如,我可以这样做吗:

<% tag_cloud(@tags, %w(css1 css2 css3 css4 css5 css6)) do |tag, css_class| %> <%= link_to tag.name, { :action => :tag, :id => tag.name }, :class => css_class %> <% end %>

基本上,css类别的分配是如何分布的?我浏览了文档,但尚未找到答案。

【问题讨论】:

    标签: css ruby-on-rails act-as-taggable-on


    【解决方案1】:

    tag_cloud方法源码如下:

    def tag_cloud(tags, classes)
      return [] if tags.empty?
        max_count = tags.sort_by(&:taggings_count).last.taggings_count.to_f
    
      tags.each do |tag|
        index = ((tag.taggings_count / max_count) * (classes.size - 1))
          yield tag, classes[index.nan? ? 0 : index.round]
        end
      end
    end
    

    这意味着您可以根据需要通过任意数量的课程。您可以找到来源here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多