From e772de40a7b3458c95685efc0b109310236a1837 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 25 Apr 2018 20:12:06 -0500 Subject: [PATCH] posts: add /posts/{id}.html?variant=tooltip template. --- app/assets/stylesheets/common/erb/tags.scss.erb | 8 ++++++++ app/controllers/application_controller.rb | 5 +++++ app/controllers/posts_controller.rb | 5 ++++- app/helpers/application_helper.rb | 4 ++++ app/presenters/tag_set_presenter.rb | 4 ++++ app/views/posts/show.html+tooltip.erb | 7 +++++++ 6 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 app/views/posts/show.html+tooltip.erb diff --git a/app/assets/stylesheets/common/erb/tags.scss.erb b/app/assets/stylesheets/common/erb/tags.scss.erb index 2ab04e490..1ca6d51ca 100644 --- a/app/assets/stylesheets/common/erb/tags.scss.erb +++ b/app/assets/stylesheets/common/erb/tags.scss.erb @@ -23,3 +23,11 @@ } } } + +.split-inline-tag-list { + @extend .inline-tag-list; + + ul { + display: block; + } +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 494d1cab4..eff5ab2aa 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -9,6 +9,7 @@ class ApplicationController < ActionController::Base before_action :set_started_at_session before_action :api_check before_action :set_safe_mode + before_action :set_variant # before_action :secure_cookies_check layout "default" helper_method :show_moderation_notice? @@ -184,6 +185,10 @@ class ApplicationController < ActionController::Base end end + def set_variant + request.variant = params[:variant].try(:to_sym) + end + User::Roles.each do |role| define_method("#{role}_only") do if !CurrentUser.user.is_banned_or_ip_banned? && CurrentUser.user.__send__("is_#{role}?") diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 7bf2dd475..e79432ac6 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -31,7 +31,10 @@ class PostsController < ApplicationController include_deleted = @post.is_deleted? || (@post.parent_id.present? && @post.parent.is_deleted?) || CurrentUser.user.show_deleted_children? @parent_post_set = PostSets::PostRelationship.new(@post.parent_id, :include_deleted => include_deleted) @children_post_set = PostSets::PostRelationship.new(@post.id, :include_deleted => include_deleted) - respond_with(@post) + + respond_with(@post) do |format| + format.html.tooltip { render layout: false } + end end def show_seq diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 85535e984..827f6d463 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -113,6 +113,10 @@ module ApplicationHelper link_to ip, moderator_ip_addrs_path(:search => {:ip_addr => ip}) end + def link_to_search(search) + link_to search, posts_path(tags: search) + end + def link_to_wiki(*wiki_titles, **options) links = wiki_titles.map do |title| link_to title.tr("_", " "), wiki_pages_path(title: title) diff --git a/app/presenters/tag_set_presenter.rb b/app/presenters/tag_set_presenter.rb index 307964484..879230380 100644 --- a/app/presenters/tag_set_presenter.rb +++ b/app/presenters/tag_set_presenter.rb @@ -46,6 +46,10 @@ class TagSetPresenter < Presenter template.tag.span(html, class: classes) end + def split_inline_tag_list_html(template, **options) + inline_tag_list_html(template, classes: "split-inline-tag-list", **options) + end + private def typed_tags(name) diff --git a/app/views/posts/show.html+tooltip.erb b/app/views/posts/show.html+tooltip.erb new file mode 100644 index 000000000..e1551ac9b --- /dev/null +++ b/app/views/posts/show.html+tooltip.erb @@ -0,0 +1,7 @@ +<%= @post.presenter.split_inline_tag_list_html(self) %> + +
+ <%= link_to_search "user:#{@post.uploader_name}" if CurrentUser.is_moderator? %> + <%= link_to_search "rating:#{@post.pretty_rating.downcase}" %> + <%= link_to_search "score:#{@post.score}" %> +