diff --git a/app/controllers/async_info_controller.rb b/app/controllers/async_info_controller.rb index c903de0e9..50a1590c7 100644 --- a/app/controllers/async_info_controller.rb +++ b/app/controllers/async_info_controller.rb @@ -43,7 +43,7 @@ class AsyncInfoController < ApplicationController id: @user.id, name: @user.name, username: @user.username, - profile_image_90: Images::Profile.call(@user.profile_image_url, length: 90), + profile_image_90: @user.profile_image_url_for(length: 90), followed_tags: @user.cached_followed_tags.to_json(only: %i[id name bg_color_hex text_color_hex hotness_score], methods: [:points]), followed_podcast_ids: @user.cached_following_podcasts_ids, diff --git a/app/controllers/notifications_controller.rb b/app/controllers/notifications_controller.rb index 71ca05ea9..d9128c486 100644 --- a/app/controllers/notifications_controller.rb +++ b/app/controllers/notifications_controller.rb @@ -47,7 +47,16 @@ class NotificationsController < ApplicationController # the first few notifications. After that the JS frontend code (see `initNotification.js`) # will call this action again by sending the offset id for the last known notifications, the result # will be the partial rendering of only the list of notifications that will be attached to the DOM by JS - render partial: "notifications_list" if notified_at_offset + if notified_at_offset + render partial: "notifications_list" + else + # [@jeremyf] I added an explicit render. Before adding the explicit render, we relied on the + # implicit render cycle of Rails. Which is fine, but it's very disarming to read `render + # partial: "notifications_list" if notified_at_offset` as the last line of the method. + # + # My hope is that this explicit render removes at least one future head scratch. + render "index" + end end # rubocop:enable Metrics/CyclomaticComplexity # rubocop:enable Metrics/PerceivedComplexity diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb index 07b9ea0b9..9ba1668e3 100644 --- a/app/controllers/stories_controller.rb +++ b/app/controllers/stories_controller.rb @@ -337,11 +337,11 @@ class StoriesController < ApplicationController }, url: URL.user(@user), sameAs: user_same_as, - image: Images::Profile.call(@user.profile_image_url, length: 320), + image: @user.profile_image_url_for(length: 320), name: @user.name, email: decorated_user.profile_email, description: decorated_user.profile_summary - }.reject { |_, v| v.blank? } + }.compact_blank end def set_article_json_ld @@ -399,7 +399,7 @@ class StoriesController < ApplicationController "@id": URL.organization(@organization) }, url: URL.organization(@organization), - image: Images::Profile.call(@organization.profile_image_url, length: 320), + image: @organization.profile_image_url_for(length: 320), name: @organization.name, description: @organization.summary.presence || "404 bio not found" } @@ -412,6 +412,6 @@ class StoriesController < ApplicationController @user.twitter_username.present? ? "https://twitter.com/#{@user.twitter_username}" : nil, @user.github_username.present? ? "https://github.com/#{@user.github_username}" : nil, @user.profile.website_url, - ].reject(&:blank?) + ].compact_blank end end diff --git a/app/models/articles/cached_entity.rb b/app/models/articles/cached_entity.rb index 612444df5..0a080f7dc 100644 --- a/app/models/articles/cached_entity.rb +++ b/app/models/articles/cached_entity.rb @@ -1,6 +1,8 @@ module Articles # NOTE: articles cache either users or organizations, but they have the same attributes. CachedEntity = Struct.new(:name, :username, :slug, :profile_image_90, :profile_image_url) do + include Images::Profile.for(:profile_image_url) + def self.from_object(object) new( object.name, diff --git a/app/models/organization.rb b/app/models/organization.rb index d963fd772..a77a3b169 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -1,6 +1,8 @@ class Organization < ApplicationRecord include CloudinaryHelper + include Images::Profile.for(:profile_image_url) + COLOR_HEX_REGEXP = /\A#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\z/ INTEGER_REGEXP = /\A\d+\z/ SLUG_REGEXP = /\A[a-zA-Z0-9\-_]+\z/ @@ -103,7 +105,7 @@ class Organization < ApplicationRecord end def profile_image_90 - Images::Profile.call(profile_image_url, length: 90) + profile_image_url_for(length: 90) end def enough_credits?(num_credits_needed) diff --git a/app/models/podcast.rb b/app/models/podcast.rb index 1b825217f..273731c69 100644 --- a/app/models/podcast.rb +++ b/app/models/podcast.rb @@ -1,6 +1,8 @@ class Podcast < ApplicationRecord resourcify + include Images::Profile.for(:profile_image_url) + belongs_to :creator, class_name: "User", inverse_of: :created_podcasts, optional: true has_many :podcast_episodes, dependent: :destroy @@ -50,7 +52,7 @@ class Podcast < ApplicationRecord end def image_90 - Images::Profile.call(profile_image_url, length: 90) + profile_image_url_for(length: 90) end private diff --git a/app/models/user.rb b/app/models/user.rb index fd5c6323a..dd879e93a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -4,6 +4,8 @@ class User < ApplicationRecord include CloudinaryHelper + include Images::Profile.for(:profile_image_url) + # NOTE: we are using an inline module to keep profile related things together. concerning :Profiles do included do @@ -507,7 +509,7 @@ class User < ApplicationRecord end def profile_image_90 - Images::Profile.call(profile_image_url, length: 90) + profile_image_url_for(length: 90) end def unsubscribe_from_newsletters diff --git a/app/serializers/search/podcast_episode_serializer.rb b/app/serializers/search/podcast_episode_serializer.rb index f3359e3c4..af5be99e9 100644 --- a/app/serializers/search/podcast_episode_serializer.rb +++ b/app/serializers/search/podcast_episode_serializer.rb @@ -1,7 +1,7 @@ module Search class PodcastEpisodeSerializer < ApplicationSerializer def self.podcast_image_url(podcast_episode) - Images::Profile.call(podcast_episode.podcast.profile_image_url, length: 90) + podcast_episode.podcast.profile_image_url_for(length: 90) end attribute :id, &:search_id diff --git a/app/services/images/profile.rb b/app/services/images/profile.rb index 4031cbbff..384c866e8 100644 --- a/app/services/images/profile.rb +++ b/app/services/images/profile.rb @@ -1,5 +1,22 @@ module Images module Profile + # A convenience module for wrapping the Profile::Images logic. + # + # @param attribute [Symbol] named attribute that is an image_url + # + # @return [Module] for inclusion into the given class + # + # @example + # class User + # include Images::Profile.for(:image_url) + # end + def self.for(attribute) + Module.new do + define_method("#{attribute}_for") do |length:| + Images::Profile.call(public_send(attribute), length: length) + end + end + end BACKUP_LINK = "https://thepracticaldev.s3.amazonaws.com/i/99mvlsfu5tfj9m7ku25d.png".freeze def self.call(image_url, length: 120) diff --git a/app/views/admin/comments/index.html.erb b/app/views/admin/comments/index.html.erb index dfb5b2534..0fccede1f 100644 --- a/app/views/admin/comments/index.html.erb +++ b/app/views/admin/comments/index.html.erb @@ -19,7 +19,7 @@
<% if comment.user %> - <%= comment.user.username %> profile <%= comment.user.username %> + <%= comment.user.username %> profile <%= comment.user.username %> <% end %> <% if comment.user && comment.user.twitter_username.present? %> diff --git a/app/views/api/v0/articles/onboarding.json.jbuilder b/app/views/api/v0/articles/onboarding.json.jbuilder index 25754a4c4..c282ec462 100644 --- a/app/views/api/v0/articles/onboarding.json.jbuilder +++ b/app/views/api/v0/articles/onboarding.json.jbuilder @@ -13,6 +13,6 @@ json.array! @articles do |article| json.user do json.name article.user.name - json.profile_image_url Images::Profile.call(article.user.profile_image_url, length: 90) + json.profile_image_url article.user.profile_image_url_for(length: 90) end end diff --git a/app/views/api/v0/organizations/show.json.jbuilder b/app/views/api/v0/organizations/show.json.jbuilder index 6f11e58f5..82cdaeb1c 100644 --- a/app/views/api/v0/organizations/show.json.jbuilder +++ b/app/views/api/v0/organizations/show.json.jbuilder @@ -15,4 +15,4 @@ json.extract!( ) json.joined_at utc_iso_timestamp(@organization.created_at) -json.profile_image Images::Profile.call(@organization.profile_image_url, length: 640) +json.profile_image @organization.profile_image_url_for(length: 640) diff --git a/app/views/api/v0/profile_images/show.json.jbuilder b/app/views/api/v0/profile_images/show.json.jbuilder index 4be52b59e..553c50d01 100644 --- a/app/views/api/v0/profile_images/show.json.jbuilder +++ b/app/views/api/v0/profile_images/show.json.jbuilder @@ -1,5 +1,5 @@ json.type_of "profile_image" json.image_of @profile_image_owner.class.name.downcase -json.profile_image Images::Profile.call(@profile_image_owner.profile_image_url, length: 640) -json.profile_image_90 Images::Profile.call(@profile_image_owner.profile_image_url, length: 90) +json.profile_image @profile_image_owner.profile_image_url_for(length: 640) +json.profile_image_90 @profile_image_owner.profile_image_url_for(length: 90) diff --git a/app/views/api/v0/shared/_follows.json.jbuilder b/app/views/api/v0/shared/_follows.json.jbuilder index 456337d1e..f7a483b34 100644 --- a/app/views/api/v0/shared/_follows.json.jbuilder +++ b/app/views/api/v0/shared/_follows.json.jbuilder @@ -1,4 +1,4 @@ json.name user.name json.path "/#{user.path.delete_prefix('/')}" json.username user.try(:username) || user.name -json.profile_image Images::Profile.call(user.profile_image_url, length: 60) +json.profile_image user.profile_image_url_for(length: 60) diff --git a/app/views/api/v0/shared/_organization.json.jbuilder b/app/views/api/v0/shared/_organization.json.jbuilder index d933741b9..14c44ef4d 100644 --- a/app/views/api/v0/shared/_organization.json.jbuilder +++ b/app/views/api/v0/shared/_organization.json.jbuilder @@ -1,6 +1,6 @@ json.organization do json.extract!(organization, :name, :username, :slug) - json.profile_image Images::Profile.call(organization.profile_image_url, length: 640) - json.profile_image_90 Images::Profile.call(organization.profile_image_url, length: 90) + json.profile_image organization.profile_image_url_for(length: 640) + json.profile_image_90 organization.profile_image_url_for(length: 90) end diff --git a/app/views/api/v0/shared/_user.json.jbuilder b/app/views/api/v0/shared/_user.json.jbuilder index d7a1d1344..0be193e5c 100644 --- a/app/views/api/v0/shared/_user.json.jbuilder +++ b/app/views/api/v0/shared/_user.json.jbuilder @@ -2,6 +2,6 @@ json.user do json.extract!(user, :name, :username, :twitter_username, :github_username) json.website_url user.processed_website_url - json.profile_image Images::Profile.call(user.profile_image_url, length: 640) - json.profile_image_90 Images::Profile.call(user.profile_image_url, length: 90) + json.profile_image user.profile_image_url_for(length: 640) + json.profile_image_90 user.profile_image_url_for(length: 90) end diff --git a/app/views/api/v0/shared/_user_show.json.jbuilder b/app/views/api/v0/shared/_user_show.json.jbuilder index 7c6316163..25313c846 100644 --- a/app/views/api/v0/shared/_user_show.json.jbuilder +++ b/app/views/api/v0/shared/_user_show.json.jbuilder @@ -14,4 +14,4 @@ Profile.static_fields.each do |attr| end json.joined_at I18n.l(user.created_at, format: :json) -json.profile_image Images::Profile.call(user.profile_image_url, length: 320) +json.profile_image user.profile_image_url_for(length: 320) diff --git a/app/views/articles/_liquid.html.erb b/app/views/articles/_liquid.html.erb index eaaed2769..609dbf6fe 100644 --- a/app/views/articles/_liquid.html.erb +++ b/app/views/articles/_liquid.html.erb @@ -10,9 +10,9 @@ <% if article.organization %> @@ -30,7 +30,7 @@ <% else %> diff --git a/app/views/articles/_single_story.html.erb b/app/views/articles/_single_story.html.erb index f169c2146..38e79c40f 100644 --- a/app/views/articles/_single_story.html.erb +++ b/app/views/articles/_single_story.html.erb @@ -30,7 +30,7 @@ <% end %> - <%= story.cached_user.username %> profile + <%= story.cached_user.username %> profile
@@ -54,7 +54,7 @@ diff --git a/app/views/articles/_sticky_nav.html.erb b/app/views/articles/_sticky_nav.html.erb index f0ede8fe1..58b457442 100644 --- a/app/views/articles/_sticky_nav.html.erb +++ b/app/views/articles/_sticky_nav.html.erb @@ -37,7 +37,7 @@ <% sticky_articles.each_with_index do |article, index| %> - <%= article.cached_user.name %> profile image + <%= article.cached_user.name %> profile image
<%= article.title %> diff --git a/app/views/articles/show.html.erb b/app/views/articles/show.html.erb index a6bcc5ac2..c102a2d5f 100644 --- a/app/views/articles/show.html.erb +++ b/app/views/articles/show.html.erb @@ -103,12 +103,12 @@
<% if @organization %> - <%= @organization.name %> profile image + <%= @organization.name %> profile image - <%= @user.name %> + <%= @user.name %> <% else %> - <%= @user.name %> + <%= @user.name %> <% end %>
diff --git a/app/views/comments/_comment.json.jbuilder b/app/views/comments/_comment.json.jbuilder index 9d90c1fe1..b870b3dc2 100644 --- a/app/views/comments/_comment.json.jbuilder +++ b/app/views/comments/_comment.json.jbuilder @@ -12,7 +12,7 @@ json.user do json.id current_user.id json.username current_user.username json.name current_user.name - json.profile_pic Images::Profile.call(current_user.profile_image_url, length: 50) + json.profile_pic current_user.profile_image_url_for(length: 50) json.twitter_username current_user.twitter_username json.github_username current_user.github_username end diff --git a/app/views/comments/_comment_avatar.html.erb b/app/views/comments/_comment_avatar.html.erb index 4e5086c34..28a9d8458 100644 --- a/app/views/comments/_comment_avatar.html.erb +++ b/app/views/comments/_comment_avatar.html.erb @@ -4,6 +4,6 @@ <% else %> - <%= comment.user.username %> profile image + <%= comment.user.username %> profile image <% end %> diff --git a/app/views/comments/_liquid.html.erb b/app/views/comments/_liquid.html.erb index 6f868b192..9d38ade8f 100644 --- a/app/views/comments/_liquid.html.erb +++ b/app/views/comments/_liquid.html.erb @@ -2,7 +2,7 @@ <% if comment %>
- <%= comment.user.username %> profile image + <%= comment.user.username %> profile image <%= comment.user.name %> diff --git a/app/views/dashboards/followers.html.erb b/app/views/dashboards/followers.html.erb index 2616d78b6..af50e83eb 100644 --- a/app/views/dashboards/followers.html.erb +++ b/app/views/dashboards/followers.html.erb @@ -20,7 +20,7 @@ <% if user %>
- <%= user.username %> profile image + <%= user.username %> profile image
diff --git a/app/views/dashboards/following_organizations.html.erb b/app/views/dashboards/following_organizations.html.erb index 64d08e376..9c49f9646 100644 --- a/app/views/dashboards/following_organizations.html.erb +++ b/app/views/dashboards/following_organizations.html.erb @@ -18,7 +18,7 @@ <% organization = follow.followable %>
diff --git a/app/views/dashboards/following_users.html.erb b/app/views/dashboards/following_users.html.erb index 5f0d1148a..d4d9f11a9 100644 --- a/app/views/dashboards/following_users.html.erb +++ b/app/views/dashboards/following_users.html.erb @@ -20,7 +20,7 @@ <% if user %>
- <%= user.username %> profile image + <%= user.username %> profile image
diff --git a/app/views/notifications/_broadcast.html.erb b/app/views/notifications/_broadcast.html.erb index 508c94d4b..49a5ab6e7 100644 --- a/app/views/notifications/_broadcast.html.erb +++ b/app/views/notifications/_broadcast.html.erb @@ -3,7 +3,7 @@ <% user = User.find_by(id: json_data["user"]["id"]) %> <% cache "broadcast-html-#{notification.json_data['broadcast']['title']}" do %> " class="crayons-avatar crayons-avatar--2xl m:crayons-avatar--3xl shrink-0 mb-4 m:mb-6"> - link to <%= json_data['s profile" width="128" height="128"> + link to <%= json_data['s profile" width="128" height="128">
"> <%= json_data["broadcast"]["processed_html"].html_safe %> diff --git a/app/views/notifications/_notifications_list.html.erb b/app/views/notifications/_notifications_list.html.erb index 11047437d..df0a89b63 100644 --- a/app/views/notifications/_notifications_list.html.erb +++ b/app/views/notifications/_notifications_list.html.erb @@ -6,6 +6,7 @@
<% rescue => e %> + <% Honeybadger.notify(e, context: { notification_id: notification.id }) %>
diff --git a/app/views/organizations/_header.html.erb b/app/views/organizations/_header.html.erb index 609c9a01e..c1a0196e3 100644 --- a/app/views/organizations/_header.html.erb +++ b/app/views/organizations/_header.html.erb @@ -13,7 +13,7 @@
diff --git a/app/views/organizations/_liquid.html.erb b/app/views/organizations/_liquid.html.erb index b7305d87a..66f7373c8 100644 --- a/app/views/organizations/_liquid.html.erb +++ b/app/views/organizations/_liquid.html.erb @@ -8,7 +8,7 @@
- <%= " /> + <%= " />
diff --git a/app/views/organizations/_sidebar_additional.html.erb b/app/views/organizations/_sidebar_additional.html.erb index d0886f5b9..80b30237c 100644 --- a/app/views/organizations/_sidebar_additional.html.erb +++ b/app/views/organizations/_sidebar_additional.html.erb @@ -18,7 +18,7 @@ <% @organization.users.find_each do |user| %> <% end %> diff --git a/app/views/shared/_profile_card_content.html.erb b/app/views/shared/_profile_card_content.html.erb index 68929536e..ebce954dc 100644 --- a/app/views/shared/_profile_card_content.html.erb +++ b/app/views/shared/_profile_card_content.html.erb @@ -1,7 +1,7 @@
crayons-avatar crayons-avatar--xl<% elsif actor.class.name == "Organization" %>crayons-logo crayons-logo--xl<% end %> mr-2 shrink-0"> - crayons-avatar__image<% elsif actor.class.name == "Organization" %>crayons-logo__image<% end %>" alt="" loading="lazy" /> + crayons-avatar__image<% elsif actor.class.name == "Organization" %>crayons-logo__image<% end %>" alt="" loading="lazy" /> <%= actor.name %> diff --git a/app/views/social_previews/articles/article.html.erb b/app/views/social_previews/articles/article.html.erb index 019ef2232..9f9af6bea 100644 --- a/app/views/social_previews/articles/article.html.erb +++ b/app/views/social_previews/articles/article.html.erb @@ -123,7 +123,7 @@

<%= @article.title %>

- + <%= truncate @article.user.name, length: 28 %>・<%= @article.readable_publish_date %>
diff --git a/app/views/social_previews/comment.html.erb b/app/views/social_previews/comment.html.erb index 414b343ba..d4f0dbe3f 100644 --- a/app/views/social_previews/comment.html.erb +++ b/app/views/social_previews/comment.html.erb @@ -120,7 +120,7 @@

<%= @comment.title %>

- + <%= truncate @comment.user.name, length: 28 %>・<%= @comment.readable_publish_date %>
diff --git a/app/views/social_previews/user.html.erb b/app/views/social_previews/user.html.erb index d51ca24ac..8ebe9bf76 100644 --- a/app/views/social_previews/user.html.erb +++ b/app/views/social_previews/user.html.erb @@ -110,7 +110,7 @@ <% font_size = 4.6 %> <% end %>

- <%= @user.name %> profile image + <%= @user.name %> profile image <%= truncate @user.name, length: 32 %>
@<%= @user.username %> diff --git a/app/views/stories/tagged_articles/_sidebar.html.erb b/app/views/stories/tagged_articles/_sidebar.html.erb index f58f1c5ce..d740c60af 100644 --- a/app/views/stories/tagged_articles/_sidebar.html.erb +++ b/app/views/stories/tagged_articles/_sidebar.html.erb @@ -44,7 +44,7 @@ <% @moderators.each do |user| %> <% end %> diff --git a/app/views/users/_liquid.html.erb b/app/views/users/_liquid.html.erb index 3297a1752..0de83f68d 100644 --- a/app/views/users/_liquid.html.erb +++ b/app/views/users/_liquid.html.erb @@ -9,12 +9,12 @@ <% if user_path.present? %>
- <%= " /> + <%= " />
<% else %>
- <%= " /> + <%= " />
<% end %>
diff --git a/app/views/users/_profile.html.erb b/app/views/users/_profile.html.erb index 7150f795b..495dce62a 100644 --- a/app/views/users/_profile.html.erb +++ b/app/views/users/_profile.html.erb @@ -45,7 +45,7 @@
<% if @user.profile_image_url.present? %> - <%= @user.username %> profile image + <%= @user.username %> profile image <% end %> <%= f.file_field "user[profile_image]", accept: "image/*", class: "crayons-card crayons-card--secondary p-3 flex items-center flex-1 w-100" %> @@ -164,13 +164,13 @@

<%= t("views.logo.color_1.description") %>

- <%= f.public_send("text_field", "users_setting[brand_color1]", - value: users_setting.public_send("brand_color1"), + <%= f.public_send(:text_field, "users_setting[brand_color1]", + value: users_setting.public_send(:brand_color1), placeholder: "#000000", class: "crayons-textfield js-color-field") %> - <%= f.public_send("color_field", + <%= f.public_send(:color_field, "users_setting[brand_color1]", - value: users_setting.public_send("brand_color1"), + value: users_setting.public_send(:brand_color1), class: "crayons-color-selector js-color-field ml-2") %>
@@ -181,13 +181,13 @@

<%= t("views.logo.color_2.description_html") %>

- <%= f.public_send("text_field", "users_setting[brand_color2]", - value: users_setting.public_send("brand_color2"), + <%= f.public_send(:text_field, "users_setting[brand_color2]", + value: users_setting.public_send(:brand_color2), placeholder: "#000000", class: "crayons-textfield js-color-field") %> - <%= f.public_send("color_field", + <%= f.public_send(:color_field, "users_setting[brand_color2]", - value: users_setting.public_send("brand_color2"), + value: users_setting.public_send(:brand_color2), class: "crayons-color-selector js-color-field ml-2") %>
diff --git a/app/views/users/_sidebar.html.erb b/app/views/users/_sidebar.html.erb index e42ecf1c7..675aef008 100644 --- a/app/views/users/_sidebar.html.erb +++ b/app/views/users/_sidebar.html.erb @@ -11,7 +11,7 @@ <% @user.organizations.each do |organization| %>

<%= organization.name %>

diff --git a/app/views/users/index.json.jbuilder b/app/views/users/index.json.jbuilder index 31d95d034..06c5d786f 100644 --- a/app/views/users/index.json.jbuilder +++ b/app/views/users/index.json.jbuilder @@ -2,6 +2,6 @@ json.array! @users.each do |user| json.extract!(user, :id, :name, :username) json.summary truncate(user.tag_line || t("json.author", community: community_name), length: 100) - json.profile_image_url Images::Profile.call(user.profile_image_url, length: 90) + json.profile_image_url user.profile_image_url_for(length: 90) json.following false end diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 352fc5854..984c0c664 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -28,7 +28,7 @@
- <%= @user.name %> profile picture + <%= @user.name %> profile picture
diff --git a/spec/liquid_tags/link_tag_spec.rb b/spec/liquid_tags/link_tag_spec.rb index 4aa124486..deca751e6 100644 --- a/spec/liquid_tags/link_tag_spec.rb +++ b/spec/liquid_tags/link_tag_spec.rb @@ -35,7 +35,7 @@ RSpec.describe LinkTag, type: :liquid_tag do