Skip to content

Commit

Permalink
use strict locals, surely this big churn won't break anything
Browse files Browse the repository at this point in the history
  • Loading branch information
pushcx committed Jan 17, 2024
1 parent 4c01d77 commit 7a80cc1
Show file tree
Hide file tree
Showing 57 changed files with 157 additions and 114 deletions.
6 changes: 0 additions & 6 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ def find_user_from_rss_token
end
end

def flag_warning
@flag_warning_int ||= time_interval("1m")
return false if Rails.env.development? # expensive because Rails doesn't cache in dev
@show_flag_warning ||= @user && !!FlaggedCommenters.new(@flag_warning_int[:param], 1.day).check_list_for(@user)
end

def heinous_inline_partials
do_heinous_inline_partial_replacement
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class CommentsController < ApplicationController
before_action :require_logged_in_user_or_400,
only: [:create, :reply, :upvote, :flag, :unvote, :update]
before_action :require_logged_in_user, only: [:upvoted]
before_action :flag_warning, only: [:user_threads]
before_action :show_title_h1

# for rss feeds, load the user's tag filters if a token is passed
Expand Down
35 changes: 17 additions & 18 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def active
}

@title = "Active Discussions"
@above = "active"
@above = {partial: "active"}

respond_to do |format|
format.html { render action: :index }
Expand All @@ -31,7 +31,7 @@ def hidden
}

@title = "Hidden Stories"
@above = "saved/subnav"
@above = {partial: "saved/subnav"}

render action: "index"
end
Expand Down Expand Up @@ -76,7 +76,7 @@ def newest
}

@title = "Newest Stories"
@above = "stories/subnav"
@above = {partial: "stories/subnav"}

@rss_link = {
title: "RSS 2.0 - Newest Items",
Expand All @@ -102,8 +102,7 @@ def newest_by_user
@stories, @show_more = paginate stories.newest_by_user(by_user)

@title = "Newest Stories by #{by_user.username}"
@newest_by_user = by_user
@above = "newest_by_user"
@above = {partial: "newest_by_user", locals: {newest_by_user: by_user}}

respond_to do |format|
format.html { render action: "index" }
Expand All @@ -120,8 +119,8 @@ def recent
}

@title = "Recent Stories"
@above = "stories/subnav"
@below = "recent"
@above = {partial: "stories/subnav"}
@below = {partial: "recent"}

# our list is unstable because upvoted stories get removed, so point at /newest.rss
@rss_link = {title: "RSS 2.0 - Newest Items", href: user_token_link("/newest.rss")}
Expand All @@ -140,7 +139,7 @@ def saved
}

@title = "Saved Stories"
@above = "saved/subnav"
@above = {partial: "saved/subnav"}

respond_to do |format|
format.html { render action: "index" }
Expand All @@ -156,16 +155,16 @@ def saved

def category
category_params = params[:category].split(",")
@categories = Category.where(category: category_params)
categories = Category.where(category: category_params)

raise ActiveRecord::RecordNotFound unless @categories.length == category_params.length
raise ActiveRecord::RecordNotFound unless categories.length == category_params.length

@stories, @show_more = get_from_cache(categories: category_params.sort.join(",")) do
paginate stories.categories(@categories)
paginate stories.categories(categories)
end

@title = @categories.map(&:category).join(" ")
@above = "category"
@title = categories.map(&:category).join(" ")
@above = {partial: "category", locals: {categories: categories}}

@rss_link = {
title: "RSS 2.0 - Categorized #{@title}",
Expand All @@ -186,12 +185,12 @@ def single_tag
paginate stories.tagged([@tag])
end

@title = [@tag.tag, @tag.description].compact.join(" - ")
@above = "single_tag"
@related = Rails.cache.fetch("related_#{@tag.tag}", expires_in: 1.day) {
Tag.related(@tag)
}
@below = "tags/multi_tag_tip"
@title = [@tag.tag, @tag.description].compact.join(" - ")
@above = {partial: "single_tag", locals: {tag: @tag, related: @related}}
@below = {partial: "tags/multi_tag_tip"}

@rss_link = {
title: "RSS 2.0 - Tagged #{@tag.tag} (#{@tag.description})",
Expand All @@ -217,7 +216,7 @@ def multi_tag
@title = @tags.map do |tag|
[tag.tag, tag.description].compact.join(" - ")
end.join(" ")
@above = "multi_tag"
@above = {partial: "multi_tag", locals: {tags: @tags}}

@rss_link = {
title: "RSS 2.0 - Tagged #{tags_with_description_for_rss(@tags)}",
Expand All @@ -239,7 +238,7 @@ def for_domain
end

@title = @domain.domain
@above = "for_domain"
@above = {partial: "for_domain", locals: {domain: @domain, stories: @stories}}

@rss_link = {
title: "RSS 2.0 - For #{@domain.domain}",
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/replies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class RepliesController < ApplicationController
REPLIES_PER_PAGE = 25

before_action :require_logged_in_user, :flag_warning, :set_page, :show_title_h1
before_action :require_logged_in_user, :set_page, :show_title_h1
after_action :update_read_ribbons, only: [:unread]
after_action :clear_unread_replies_cache, only: [:comments, :stories]
after_action :zero_unread_replies_cache, only: [:all, :unread]
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/stories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def show
end
if !@story.can_be_seen_by_user?(@user)
respond_to do |format|
format.html { return render action: "_missing", status: 404 }
format.html { return render action: "_missing", status: 404, locals: {story: @story, moderation: @moderation} }
format.json { raise ActiveRecord::RecordNotFound }
end
end
Expand Down
9 changes: 4 additions & 5 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class UsersController < ApplicationController
before_action :load_showing_user, only: [:show, :standing]
before_action :require_logged_in_moderator,
only: [:enable_invitation, :disable_invitation, :ban, :unban]
before_action :flag_warning, only: [:show, :standing]
before_action :require_logged_in_user, only: [:standing]
before_action :only_user_or_moderator, only: [:standing]
before_action :show_title_h1, only: [:show]
Expand Down Expand Up @@ -124,9 +123,9 @@ def unban
end

def standing
int = @flag_warning_int
@interval = time_interval("1m")

fc = FlaggedCommenters.new(int[:param], 1.day)
fc = FlaggedCommenters.new(@interval[:param], 1.day)
@fc_flagged = fc.commenters.map { |_, c| c[:n_flags] }.sort
@flagged_user_stats = fc.check_list_for(@showing_user)

Expand All @@ -139,7 +138,7 @@ def standing
from
comments
where
comments.created_at >= now() - interval #{int[:dur]} #{int[:intv]}
comments.created_at >= now() - interval #{@interval[:dur]} #{@interval[:intv]}
group by comments.user_id) count_by_user
group by 1
order by 1 asc;
Expand All @@ -151,7 +150,7 @@ def standing
@flagged_comments = @showing_user.comments
.where("
comments.flags > 0 and
comments.created_at >= now() - interval #{int[:dur]} #{int[:intv]}")
comments.created_at >= now() - interval #{@interval[:dur]} #{@interval[:intv]}")
.order("id DESC")
.includes(:user, :hat, story: :user)
.joins(:story)
Expand Down
10 changes: 10 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ def page_numbers_for_pagination(max, cur)
pages
end

def possible_flag_warning(showing_user, user)
return render partial: "users/dev_flag_warning" unless Rails.env.production?
return unless self_or_mod(showing_user, user)

interval = time_interval("1m")
if FlaggedCommenters.new(interval[:param], 1.day).check_list_for(showing_user)
render partial: "users/flag_warning", locals: {showing_user: showing_user, interval: interval}
end
end

def tag_link(tag)
link_to tag.tag, tag_path(tag), class: tag.css_class, title: tag.description
end
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# typed: false

module UsersHelper
def self_or_mod(showing_user, user)
user == showing_user || user.try(:is_moderator?)
end

def stories_submitted_content(user, showing_user)
tag = showing_user.most_common_story_tag

Expand Down
1 change: 1 addition & 0 deletions app/views/about/_subnav.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%# locals: () -%>
<% content_for :subnav do %>
<%= link_to_different_page 'About', about_path %>
<%= link_to_different_page 'Chat', chat_path %>
Expand Down
5 changes: 3 additions & 2 deletions app/views/categories/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<%= form_with model: @category, url: @category.persisted? ? update_category_path : categories_path, method: :post do |f| %>
<%# locals: (category:) -%>
<%= form_with model: category, url: category.persisted? ? update_category_path : categories_path, method: :post do |f| %>
<div class="boxline">
<%= f.label :category, 'Name:', class: 'required' %>
<%= f.text_field :category %>
</div>

<div class="boxline">
<%= f.submit @category.persisted? ? 'Update Category' : 'Create Category' %>
<%= f.submit category.persisted? ? 'Update Category' : 'Create Category' %>
</div>
<% end %>
1 change: 1 addition & 0 deletions app/views/categories/_multi_category_tip.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%# locals: () -%>
<p class="hint">
Tip: read stories across multiple categories with <code>/categories/foo,bar</code>
</p >
2 changes: 1 addition & 1 deletion app/views/categories/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Category Edit
</div>

<%= render partial: 'form' %>
<%= render partial: 'form', locals: { category: @category } %>
</div>
2 changes: 1 addition & 1 deletion app/views/categories/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
Category Create
</div>

<%= render partial: 'form' %>
<%= render partial: 'form', locals: { category: @category } %>
</div>
12 changes: 6 additions & 6 deletions app/views/comments/_comment.html.erb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<%# locals: (comment:, force_open: false, show_tree_lines: false, show_story: false, was_merged: false, is_unread: false) -%>
<%
# partial inputs:
comment ||= raise "required Comment missing" # the Comment to render
force_open ||= false # this comment is allowed to collapse
show_tree_lines ||= false # render collapse button (misnamed?)
show_story ||= false # show "on: story title" end of byline
was_merged ||= false # show merged icon start of byline
is_unread ||= false # show (unread) in byline
# force_open: this comment is allowed to collapse
# show_tree_lines: render collapse button (misnamed?)
# show_story: show "on: story title" end of byline
# was_merged: show merged icon start of byline
# is_unread: show (unread) in byline
%>
<input id="comment_folder_<%= comment.short_id %>"
class="comment_folder_button" type="checkbox"
Expand Down
1 change: 1 addition & 0 deletions app/views/comments/_postedreply.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%# locals: (comment:) -%>
<li class="comments_subtree">
<%= render "comments/comment", :comment => comment,
:show_tree_lines => true %>
Expand Down
21 changes: 11 additions & 10 deletions app/views/comments/_threads.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%# locals: (thread:, story: nil, ribbon: nil) -%>
<% previous_depth = nil %>
<% top_comment_depth = nil %>
<% thread.each do |comment| %>
Expand All @@ -21,25 +22,25 @@
<li class="comments_subtree">

<%
force_option = true
force_open = true
show_tree_lines = true
# show "on: <title>" for comments from merged stories + on non-story pages
show_story ||= @story.try(:id) != comment.story_id
show_story ||= story.try(:id) != comment.story_id
# show merge icon only on story page when merged
was_merged = @story && (@story.id != comment.story_id)
is_unread = @ribbon&.is_unread?(comment)
was_merged = story && (story.id != comment.story_id)
is_unread = ribbon&.is_unread?(comment)
%>
<%#heinous_inline_partial(comments/_comment.html.erb)%>
<%# Do not edit, the content before /heinous_inline_partial comes from the named partial %>
<%# locals: (comment:, force_open: false, show_tree_lines: false, show_story: false, was_merged: false, is_unread: false) -%>
<%
# partial inputs:
comment ||= raise "required Comment missing" # the Comment to render
force_open ||= false # this comment is allowed to collapse
show_tree_lines ||= false # render collapse button (misnamed?)
show_story ||= false # show "on: story title" end of byline
was_merged ||= false # show merged icon start of byline
is_unread ||= false # show (unread) in byline
# force_open: this comment is allowed to collapse
# show_tree_lines: render collapse button (misnamed?)
# show_story: show "on: story title" end of byline
# was_merged: show merged icon start of byline
# is_unread: show (unread) in byline
%>
<input id="comment_folder_<%= comment.short_id %>"
class="comment_folder_button" type="checkbox"
Expand Down
1 change: 1 addition & 0 deletions app/views/comments/_too_deep.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%# locals: () -%>
<div class="comment comment_form_container flash-notice">
Max reply depth reached.
Perhaps blog about this and submit it?
Expand Down
2 changes: 1 addition & 1 deletion app/views/comments/user_threads.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= render partial: 'messages/subnav' %>
<%= render partial: 'users/flag_warning' if @show_flag_warning && @showing_user == @user %>
<%= possible_flag_warning(@showing_user, @user) %>

<ol class="comments comments1">
<li class="comments_subtree">
Expand Down
3 changes: 2 additions & 1 deletion app/views/global/_markdownhelp.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%# locals: (allow_images: false) -%>
<div class="markdown_help">
<table>
<tr>
Expand Down Expand Up @@ -31,7 +32,7 @@
text</pre></td>
<td>prefix text with at least<tt>&nbsp;&nbsp;&nbsp;&nbsp;4 spaces</tt></td>
</tr>
<% if defined?(allow_images) && allow_images %>
<% if allow_images %>
<tr>
<td>(inline image)</td>
<td><tt>![alt text](http://example.com/image.jpg)</tt></td>
Expand Down
1 change: 1 addition & 0 deletions app/views/helpers/_link_post.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%# locals: (button_label:, link:, class_name: "", confirm: nil) -%>
<%= form_tag url_for(link), class: 'link_post' do %>
<%# redundant class on the submit_tag because the form_tag isn't printed if nested in another form %>
<%= submit_tag button_label, class: "link_post #{class_name}", data: { confirm: confirm } %>
Expand Down
1 change: 1 addition & 0 deletions app/views/home/_active.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<%# locals: () -%>
<% render partial: 'stories/subnav' %>

<p class="hint">
Expand Down
8 changes: 4 additions & 4 deletions app/views/home/_category.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<%# locals: (categories:) -%>
<div class="box">
Stories with <a href="/tags">tags</a> in the
<% @categories.each do |c| %>
<% categories.each do |c| %>
<%= link_to c.category, category_path(c) %>
<% end %>
<%= "category".pluralize(@categories) %>
<%= "category".pluralize(categories) %>
<%= render(partial: 'categories/multi_category_tip') if @categories.length == 1 %>
<%= render(partial: 'categories/multi_category_tip') if categories.length == 1 %>
</div>

0 comments on commit 7a80cc1

Please sign in to comment.