Skip to content

Commit 339e882

Browse files
committed
AO3-5513 Reviewdog
1 parent 0aa2417 commit 339e882

File tree

8 files changed

+45
-23
lines changed

8 files changed

+45
-23
lines changed

app/controllers/fandoms_controller.rb

+10-13
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,18 @@ def index
99
@counts = SearchCounts.fandom_ids_for_collection(@collection)
1010
@fandoms = (@medium ? @medium.fandoms : Fandom.all).where(id: @counts.keys).by_name
1111
elsif params[:media_id]
12-
if @medium = Media.find_by_name(params[:media_id])
13-
@page_subtitle = @medium.name
14-
if @medium == Media.uncategorized
15-
@fandoms = @medium.fandoms.in_use.by_name
16-
else
17-
@fandoms = @medium.fandoms.canonical.by_name.with_count
18-
end
19-
else
20-
raise ActiveRecord::RecordNotFound, "Couldn't find media category named '#{params[:media_id]}'"
21-
end
12+
@medium = Media.find_by_name!(params[:media_id]) # rubocop:disable Rails/DynamicFindBy
13+
@page_subtitle = @medium.name
14+
@fandoms = if @medium == Media.uncategorized
15+
@medium.fandoms.in_use.by_name
16+
else
17+
@medium.fandoms.canonical.by_name.with_count
18+
end
2219
else
23-
redirect_to media_index_path(notice: "Please choose a media category to start browsing fandoms.")
24-
return
20+
flash[:notice] = t(".choose_media")
21+
redirect_to media_index_path and return
2522
end
26-
@fandoms_by_letter = @fandoms.group_by {|f| f.sortable_name[0].upcase}
23+
@fandoms_by_letter = @fandoms.group_by { |f| f.sortable_name[0].upcase }
2724
end
2825

2926
def show

app/models/tag.rb

+12-2
Original file line numberDiff line numberDiff line change
@@ -582,15 +582,25 @@ def self.autocomplete_fandom_lookup(options = {})
582582
# Substitute characters that are particularly prone to cause trouble in urls
583583
def self.find_by_name(string)
584584
return unless string.is_a? String
585-
string = string.gsub(
585+
586+
self.find_by(name: from_param(string))
587+
end
588+
589+
def self.find_by_name!(string)
590+
return unless string.is_a? String
591+
592+
self.find_by!(name: from_param(string))
593+
end
594+
595+
def self.from_param(string)
596+
string.gsub(
586597
/\*[sadqh]\*/,
587598
'*s*' => '/',
588599
'*a*' => '&',
589600
'*d*' => '.',
590601
'*q*' => '?',
591602
'*h*' => '#'
592603
)
593-
self.where('tags.name = ?', string).first
594604
end
595605

596606
# If a tag by this name exists in another class, add a suffix to disambiguate them

app/views/bookmarks/index.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<% end %>
4747
4848
<% unless @owner.present? || @bookmarkable.present? %>
49-
<p><%= ts("These are some of the latest bookmarks created on the Archive. To find more bookmarks, #{link_to 'choose a fandom', media_index_path} or #{link_to 'try our advanced search', search_bookmarks_path}.").html_safe %>
49+
<p><%= t(".recent_bookmarks_html", choose_fandom_link: link_to(t(".choose_fandom"), media_index_path), advanced_search_link: link_to(t(".advanced_search"), search_bookmarks_path)) %>
5050
<% end %>
5151
5252
<%== pagy_nav @pagy %>

app/views/fandoms/index.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<!--SEARCHBROWSE Descriptive page name, messages and instructions-->
22
<h2 class="heading">
33
<% if @collection %>
4-
<%= link_to(@collection.title, @collection) %> > <%= ts("Fandoms") %>
4+
<%= link_to(@collection.title, @collection) %> > <%= t(".page_heading") %>
55
<% elsif @medium %>
6-
<%= link_to ts("Fandoms"), media_index_path %> > <%= @medium.name %>
6+
<%= link_to t(".page_heading"), media_index_path %> > <%= @medium.name %>
77
<% else %>
8-
<%= link_to ts("Fandoms"), media_index_path %>
8+
<%= link_to t(".page_heading"), media_index_path %>
99
<% end %>
1010
</h2>
1111
<p>You can search this page by pressing <kbd>ctrl F</kbd> / <kbd>cmd F</kbd> and typing in what you are looking for.</p>
@@ -14,7 +14,7 @@
1414
<%= form_tag "", method: :get, class: "filter", id: "media-filter" do %>
1515
<fieldset>
1616
<p title="<%=ts("Choose media type") %>">
17-
<%= select_tag :media_id, options_for_select(["All Media Types"] + @media.map{|m| m.name}, params[:media_id]) %>
17+
<%= select_tag :media_id, options_for_select(["All Media Types"] + @media.map(&:name), params[:media_id]) %>
1818
<%= submit_tag ts("Show") %>
1919
</p>
2020
</fieldset>

app/views/home/_fandoms.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<% cache "homepage-fandoms-version1", skip_digest: true do %>
55
<% Media.for_menu.each do |medium| %>
66
<% unless medium.id.nil? %>
7-
<li><%= link_to ts("#{medium.name}"), media_fandoms_path(medium) %></li>
7+
<li><%= link_to medium.name, media_fandoms_path(medium) %></li>
88
<% end %>
99
<% end %>
1010
<% end %>

app/views/media/index.html.erb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--SEARCHBROWSE descriptive page name and system messages, descriptions, and instructions.-->
2-
<h2 class="heading"><%= ts('Fandoms') %></h2>
2+
<h2 class="heading"><%= t(".page_heading") %></h2>
33
<!--/descriptions-->
44

55
<!--main content-->
@@ -20,7 +20,7 @@
2020
</ol>
2121

2222
<% unless @fandom_listing[medium].size < 5 %>
23-
<p class="actions" role="navigation"><%= link_to ts("All %{media_type}...", :media_type => medium.name), media_fandoms_path(medium) %></p>
23+
<p class="actions" role="navigation"><%= link_to t(".all", media_type: medium.name), media_fandoms_path(medium) %></p>
2424
<% end %>
2525
</li>
2626
<% end %>

config/locales/controllers/en.yml

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ en:
9393
external_works:
9494
update:
9595
successfully_updated: External work was successfully updated.
96+
fandoms:
97+
index:
98+
choose_media: Please choose a media category to start browsing fandoms.
9699
home:
97100
content:
98101
page_title: Content Policy

config/locales/views/en.yml

+12
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ en:
462462
comments_on_works: delete or hide comments they previously left on your works; you can delete these individually
463463
hide_works: hide their works or bookmarks from you
464464
intro: 'Blocking a user will not:'
465+
bookmarks:
466+
index:
467+
advanced_search: try our advanced search
468+
choose_fandom: choose a fandom
469+
recent_bookmarks_html: These are some of the latest bookmarks created on the Archive. To find more bookmarks, %{choose_fandom_link} or %{advanced_search_link}.
465470
challenge_signups:
466471
signup_form:
467472
notice:
@@ -611,6 +616,9 @@ en:
611616
restricted_html: A translation of [Restricted Work] by %{creator_link}
612617
revealed_html: A translation of %{work_link} by %{creator_link}
613618
unrevealed: A translation of a work in an unrevealed collection
619+
fandoms:
620+
index:
621+
page_heading: Fandoms
614622
feedbacks:
615623
new:
616624
abuse:
@@ -1515,6 +1523,10 @@ en:
15151523
read_and_understood: I have read & understood the 2024 Terms of Service, including the Content Policy and Privacy Policy.
15161524
summary_html: On the Archive of Our Own (AO3), users can create works, bookmarks, comments, tags, and other %{content_link}. Any information you publish on AO3 may be accessible by the public, AO3 users, and/or AO3 personnel. Be mindful when sharing personal information, including but not limited to your name, email, age, location, personal relationships, gender or sexual identity, racial or ethnic background, religious or political views, and/or account usernames for other sites.
15171525
tos: Terms of Service
1526+
media:
1527+
index:
1528+
all: All %{media_type}...
1529+
page_heading: Fandoms
15181530
menu:
15191531
menu_about:
15201532
about_us: About Us

0 commit comments

Comments
 (0)