From c44a7002525d6f87dde923971ac7a95a48e9bc4f Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 12 Apr 2017 12:24:18 -0400 Subject: [PATCH] Quick best practice cleanup of views/helpers (#1546) * Remove trailing whitespace * Use query methods instead of explicit .blank? checks --- app/controllers/concerns/localized.rb | 2 +- app/helpers/stream_entries_helper.rb | 2 +- app/lib/atom_serializer.rb | 6 +++--- app/views/admin/pubsubhubbub/index.html.haml | 6 +++--- app/views/admin/reports/show.html.haml | 5 +---- app/views/authorize_follow/_card.html.haml | 2 +- app/views/stream_entries/_detailed_status.html.haml | 4 ++-- app/views/stream_entries/_simple_status.html.haml | 4 ++-- app/workers/pubsubhubbub/delivery_worker.rb | 2 +- config/initializers/blacklists.rb | 2 +- 10 files changed, 16 insertions(+), 19 deletions(-) diff --git a/app/controllers/concerns/localized.rb b/app/controllers/concerns/localized.rb index bcf3fd0a0b..22bb5b21af 100644 --- a/app/controllers/concerns/localized.rb +++ b/app/controllers/concerns/localized.rb @@ -26,7 +26,7 @@ module Localized end def default_locale - ENV.fetch('DEFAULT_LOCALE') { + ENV.fetch('DEFAULT_LOCALE') { http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale } end diff --git a/app/helpers/stream_entries_helper.rb b/app/helpers/stream_entries_helper.rb index 59aac78416..18ef8b909f 100644 --- a/app/helpers/stream_entries_helper.rb +++ b/app/helpers/stream_entries_helper.rb @@ -2,7 +2,7 @@ module StreamEntriesHelper def display_name(account) - account.display_name.blank? ? account.username : account.display_name + account.display_name.presence || account.username end def stream_link_target diff --git a/app/lib/atom_serializer.rb b/app/lib/atom_serializer.rb index 68d2fce688..69e1f153c3 100644 --- a/app/lib/atom_serializer.rb +++ b/app/lib/atom_serializer.rb @@ -26,8 +26,8 @@ class AtomSerializer append_element(author, 'link', nil, rel: :avatar, type: account.avatar_content_type, 'media:width': 120, 'media:height': 120, href: full_asset_url(account.avatar.url(:original))) append_element(author, 'link', nil, rel: :header, type: account.header_content_type, 'media:width': 700, 'media:height': 335, href: full_asset_url(account.header.url(:original))) append_element(author, 'poco:preferredUsername', account.username) - append_element(author, 'poco:displayName', account.display_name) unless account.display_name.blank? - append_element(author, 'poco:note', Formatter.instance.simplified_format(account).to_str) unless account.note.blank? + append_element(author, 'poco:displayName', account.display_name) if account.display_name? + append_element(author, 'poco:note', Formatter.instance.simplified_format(account).to_str) if account.note? append_element(author, 'mastodon:scope', account.locked? ? :private : :public) author @@ -327,7 +327,7 @@ class AtomSerializer end def serialize_status_attributes(entry, status) - append_element(entry, 'summary', status.spoiler_text) unless status.spoiler_text.blank? + append_element(entry, 'summary', status.spoiler_text) if status.spoiler_text? append_element(entry, 'content', Formatter.instance.format(status.proper).to_str, type: 'html') status.mentions.each do |mentioned| diff --git a/app/views/admin/pubsubhubbub/index.html.haml b/app/views/admin/pubsubhubbub/index.html.haml index 2b8e36e6a3..dcbb11c114 100644 --- a/app/views/admin/pubsubhubbub/index.html.haml +++ b/app/views/admin/pubsubhubbub/index.html.haml @@ -21,9 +21,9 @@ %i.fa.fa-check %td= distance_of_time_in_words(Time.now, subscription.expires_at) %td - - if subscription.last_successful_delivery_at.nil? - %i.fa.fa-times - - else + - if subscription.last_successful_delivery_at? = l subscription.last_successful_delivery_at + - else + %i.fa.fa-times = paginate @subscriptions diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml index 1143c2c2ee..ecbb98482b 100644 --- a/app/views/admin/reports/show.html.haml +++ b/app/views/admin/reports/show.html.haml @@ -12,10 +12,7 @@ %p %strong= t('reports.comment.label') \: - - if @report.comment.blank? - = t('reports.comment.none') - - else - = @report.comment + = @report.comment.presence || t('reports.comment.none') - unless @statuses.empty? %hr/ diff --git a/app/views/authorize_follow/_card.html.haml b/app/views/authorize_follow/_card.html.haml index eef0bec07c..16af9220e5 100644 --- a/app/views/authorize_follow/_card.html.haml +++ b/app/views/authorize_follow/_card.html.haml @@ -7,5 +7,5 @@ %strong.emojify= display_name(account) %span= "@#{account.acct}" - - unless account.note.blank? + - if account.note? .account__header__content.emojify= Formatter.instance.simplified_format(account) diff --git a/app/views/stream_entries/_detailed_status.html.haml b/app/views/stream_entries/_detailed_status.html.haml index 5fc6ab42f3..c42e6614a2 100644 --- a/app/views/stream_entries/_detailed_status.html.haml +++ b/app/views/stream_entries/_detailed_status.html.haml @@ -8,11 +8,11 @@ %span.p-nickname= acct(status.account) .status__content.e-content.p-name.emojify< - - unless status.spoiler_text.blank? + - if status.spoiler_text? %p{ style: 'margin-bottom: 0' }< %span>= "#{status.spoiler_text} " %a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more') - %div{ style: "display: #{status.spoiler_text.blank? ? 'block' : 'none'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status) + %div{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status) - unless status.media_attachments.empty? - if status.media_attachments.first.video? diff --git a/app/views/stream_entries/_simple_status.html.haml b/app/views/stream_entries/_simple_status.html.haml index 5b6069e335..a758d5ccdf 100644 --- a/app/views/stream_entries/_simple_status.html.haml +++ b/app/views/stream_entries/_simple_status.html.haml @@ -13,11 +13,11 @@ %span.p-nickname= acct(status.account) .status__content.e-content.p-name.emojify< - - unless status.spoiler_text.blank? + - if status.spoiler_text? %p{ style: 'margin-bottom: 0' }< %span>= "#{status.spoiler_text} " %a.status__content__spoiler-link{ href: '#' }= t('statuses.show_more') - %div{ style: "display: #{status.spoiler_text.blank? ? 'block' : 'none'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status) + %div{ style: "display: #{status.spoiler_text? ? 'none' : 'block'}; direction: #{rtl?(status.content) ? 'rtl' : 'ltr'}" }= Formatter.instance.format(status) - unless status.media_attachments.empty? .status__attachments diff --git a/app/workers/pubsubhubbub/delivery_worker.rb b/app/workers/pubsubhubbub/delivery_worker.rb index 8412be4b75..b440f7986e 100644 --- a/app/workers/pubsubhubbub/delivery_worker.rb +++ b/app/workers/pubsubhubbub/delivery_worker.rb @@ -19,7 +19,7 @@ class Pubsubhubbub::DeliveryWorker headers['User-Agent'] = 'Mastodon/PubSubHubbub' headers['Link'] = LinkHeader.new([[api_push_url, [%w(rel hub)]], [account_url(subscription.account, format: :atom), [%w(rel self)]]]).to_s - headers['X-Hub-Signature'] = signature(subscription.secret, payload) unless subscription.secret.blank? + headers['X-Hub-Signature'] = signature(subscription.secret, payload) if subscription.secret? response = HTTP.timeout(:per_operation, write: 50, connect: 20, read: 50) .headers(headers) diff --git a/config/initializers/blacklists.rb b/config/initializers/blacklists.rb index 6db7be7dc5..020d84f569 100644 --- a/config/initializers/blacklists.rb +++ b/config/initializers/blacklists.rb @@ -2,5 +2,5 @@ Rails.application.configure do config.x.email_domains_blacklist = ENV.fetch('EMAIL_DOMAIN_BLACKLIST') { 'mvrht.com' } - config.x.email_domains_whitelist = ENV.fetch('EMAIL_DOMAIN_WHITELIST') { '' } + config.x.email_domains_whitelist = ENV.fetch('EMAIL_DOMAIN_WHITELIST') { '' } end