From a418ed72813f76635d54e0bb9f5e9b47b9f0bcf2 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 4 Nov 2019 18:18:56 -0600 Subject: [PATCH] post tooltips: use more compact timestamps. * Use more compact timestamps in post tooltips ("39 minutes ago" -> "39m ago") * Move timestamps to the right (after favcount + score). * Switch favorite icon from star to heart. --- app/helpers/application_helper.rb | 25 +++++++++++++++++++------ app/views/posts/show.html+tooltip.erb | 8 +++++--- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6aee47d3a..27edc5037 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -50,10 +50,10 @@ module ApplicationHelper end end - def time_tag(content, time) + def time_tag(content, time, **options) datetime = time.strftime("%Y-%m-%dT%H:%M%:z") - content_tag(:time, content || datetime, :datetime => datetime, :title => time.to_formatted_s) + tag.time content || datetime, datetime: datetime, title: time.to_formatted_s, **options end def humanized_duration(from, to) @@ -71,11 +71,24 @@ module ApplicationHelper def time_ago_in_words_tagged(time, compact: false) if time.past? - text = time_ago_in_words(time) + " ago" - text = text.gsub(/almost|about|over/, "").strip if compact - raw time_tag(text, time) + if compact + text = time_ago_in_words(time) + text = text.gsub(/almost|about|over/, "").strip + text = text.gsub(/less than a/, "<1") + text = text.gsub(/ minutes?/, "m") + text = text.gsub(/ hours?/, "h") + text = text.gsub(/ days?/, "d") + text = text.gsub(/ months?/, "mo") + text = text.gsub(/ years?/, "y") + klass = "compact-timestamp" + else + text = time_ago_in_words(time) + " ago" + klass = "" + end + + time_tag(text, time, class: klass) else - raw time_tag("in " + distance_of_time_in_words(Time.now, time), time) + time_tag("in " + distance_of_time_in_words(Time.now, time), time) end end diff --git a/app/views/posts/show.html+tooltip.erb b/app/views/posts/show.html+tooltip.erb index 402f53d31..520662ad5 100644 --- a/app/views/posts/show.html+tooltip.erb +++ b/app/views/posts/show.html+tooltip.erb @@ -4,11 +4,9 @@ <%= link_to_user @post.uploader %> <% end %> - <%= link_to time_ago_in_words_tagged(@post.created_at, compact: true), posts_path(tags: "date:#{@post.created_at.strftime("%Y-%m-%d")}"), class: "post-tooltip-date post-tooltip-info" %> - <%= @post.fav_count %> - + @@ -22,6 +20,10 @@ <% end %> + + <%= link_to posts_path(tags: "date:#{@post.created_at.strftime("%Y-%m-%d")}"), class: "post-tooltip-date post-tooltip-info" do %> + <%= time_ago_in_words_tagged(@post.created_at, compact: true) %> ago + <% end %>