From f2998585e966d6c3f9517b3457b734f0fa490a3e Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 25 Apr 2018 19:57:43 -0500 Subject: [PATCH] tag_set_presenter: refactor inline_tag_list_html. * Sort tags by category in inline tag lists (on /comments page, /uploads page, and modqueue). * Move tags css to common/erb/tags.scss.erb. --- app/assets/stylesheets/application.scss | 2 +- .../stylesheets/common/erb/tags.scss.erb | 25 +++++++++++++++++++ app/assets/stylesheets/specific/comments.scss | 12 --------- .../{erb/posts.scss.erb => posts.scss} | 17 +------------ app/presenters/tag_set_presenter.rb | 11 +++----- 5 files changed, 30 insertions(+), 37 deletions(-) create mode 100644 app/assets/stylesheets/common/erb/tags.scss.erb rename app/assets/stylesheets/specific/{erb/posts.scss.erb => posts.scss} (95%) diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 7b7d3b22f..b4df952e9 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -6,5 +6,5 @@ // directory and load them explicitly to work around this. // https://github.com/rails/sass-rails/issues/185 @import "specific/*"; -@import "specific/erb/posts"; @import "specific/erb/mod_queue"; +@import "common/erb/tags"; diff --git a/app/assets/stylesheets/common/erb/tags.scss.erb b/app/assets/stylesheets/common/erb/tags.scss.erb new file mode 100644 index 000000000..2ab04e490 --- /dev/null +++ b/app/assets/stylesheets/common/erb/tags.scss.erb @@ -0,0 +1,25 @@ +<% TagCategory.css_mapping.each do |category,cssmap| %> + .category-<%= category %> a, a.tag-type-<%= category %>, .ui-state-focus a.tag-type-<%= category %> { + color: <%= cssmap["color"] %>; + + &:hover { + color: <%= cssmap["hover"] %>; + } + } +<% end %> + +.category-banned a, a.tag-type-banned, .ui-state-focus a.tag-type-banned { + color: black; + background-color: red; +} + +.inline-tag-list { + ul { + display: inline; + + li { + display: inline; + margin-right: 0.5em; + } + } +} diff --git a/app/assets/stylesheets/specific/comments.scss b/app/assets/stylesheets/specific/comments.scss index 9d15f26aa..8ada861f5 100644 --- a/app/assets/stylesheets/specific/comments.scss +++ b/app/assets/stylesheets/specific/comments.scss @@ -66,12 +66,6 @@ div#c-comments { margin-right: 0.3em; } - div.list-of-tags { - a { - margin-right: 0.5em; - } - } - div.notices { margin: 1em 0; } @@ -133,12 +127,6 @@ div#c-comments { div.post.blacklisted.blacklisted-active { display: none; } - - div.list-of-tags { - span { - display: inline-block; - } - } } } diff --git a/app/assets/stylesheets/specific/erb/posts.scss.erb b/app/assets/stylesheets/specific/posts.scss similarity index 95% rename from app/assets/stylesheets/specific/erb/posts.scss.erb rename to app/assets/stylesheets/specific/posts.scss index 378e4b8aa..d0b6ab846 100644 --- a/app/assets/stylesheets/specific/erb/posts.scss.erb +++ b/app/assets/stylesheets/specific/posts.scss @@ -1,4 +1,4 @@ -@import "../../common/000_vars.scss"; +@import "../common/000_vars.scss"; article.post-preview { height: 154px; @@ -179,21 +179,6 @@ body[data-user-can-approve-posts="true"] .post-preview { } } -<% TagCategory.css_mapping.each do |category,cssmap| %> - .category-<%= category %> a, a.tag-type-<%= category %>, .ui-state-focus a.tag-type-<%= category %> { - color: <%= cssmap["color"] %>; - - &:hover { - color: <%= cssmap["hover"] %>; - } - } -<% end %> - -.category-banned a, a.tag-type-banned,, .ui-state-focus a.tag-type-banned { - color: black; - background-color: red; -} - .post-count { color: #CCC; margin-left: 0.2em; diff --git a/app/presenters/tag_set_presenter.rb b/app/presenters/tag_set_presenter.rb index b6e4b1e93..307964484 100644 --- a/app/presenters/tag_set_presenter.rb +++ b/app/presenters/tag_set_presenter.rb @@ -41,14 +41,9 @@ class TagSetPresenter < Presenter end # compact (horizontal) list, as seen in the /comments index. - def inline_tag_list_html(template) - @tags.map do |tag_name| - <<-EOS - - #{template.link_to(tag_name.tr("_", " "), template.posts_path(tags: tag_name))} - - EOS - end.join.html_safe + def inline_tag_list_html(template, classes: "inline-tag-list", **options) + html = split_tag_list_html(template, category_list: TagCategory.categorized_list, headers: false, name_only: true, humanize_tags: true, **options) + template.tag.span(html, class: classes) end private