feat(posts): extend _comment and _post

This commit is contained in:
dualfroz committed 2026-09-04 20:02:28 +02:00
1 parent 0e972ae191
commit 10d1cdaf1e
4 files changed
+168 -9

No files matched your search

@@ -0,0 +1,28 @@
<li class="comment" id="comment-<%= comment.id %>">
<strong><%= comment.author %></strong>
<% unless comment.approved? %>
<span class="comment-status"><%= t("comments.status_#{comment.status}") %></span>
<% end %>
<p><%= comment.body %></p>
<p>
<%= t('likes.count', count: likes_count(comment)) %>
<% if user_signed_in? %>
<% own_like = current_user_like(comment) %>
<% if own_like %>
<%== button_to(t('likes.unlike'), "/likes/#{own_like.id}", method: :delete) %>
<% else %>
<%== button_to(t('likes.like'), "/likes?likeable_type=Comment&likeable_id=#{comment.id}") %>
<% end %>
<% end %>
</p>
<% if current_user && current_user.id == comment.user_id %>
<%== link_to(t('comments.edit_link'), url_for(:edit_comment, post_id: post.to_param, id: comment.id)) %>
<%== button_to(t('comments.delete'), "/posts/#{post.to_param}/comments/#{comment.id}", method: :delete, data_confirm: t('comments.confirm_delete')) %>
<% end %>
<% if current_user && current_user.id == post.user_id && !comment.approved? %>
<%== button_to(t('comments.approve'), "/posts/#{post.to_param}/comments/#{comment.id}/approve", method: :patch) %>
<% end %>
<% if current_user && current_user.id == post.user_id && !comment.rejected? %>
<%== button_to(t('comments.reject'), "/posts/#{post.to_param}/comments/#{comment.id}/reject", method: :patch) %>
<% end %>
</li>
+21 -2
View File
@@ -1,4 +1,23 @@
<li class="post" id="post-<%= post.id %>">
<h2><%= post.title %></h2>
<li class="post" id="post-<%= post.to_param %>">
<h2><%== link_to(post.title, url_for(:post, slug: post.to_param)) %></h2>
<% if post.featured %>
<p class="featured-badge"><%= t('posts.featured_badge') %></p>
<% end %>
<% if featured_only && post.featured && user_signed_in? && current_user.id == post.user_id %>
<p class="featured-reorder">
<% unless post.first_in_list? %>
<%== button_to(t('posts.move_up'), url_for(:move_up_post, slug: post.to_param), method: :patch) %>
<% end %>
<% unless post.last_in_list? %>
<%== button_to(t('posts.move_down'), url_for(:move_down_post, slug: post.to_param), method: :patch) %>
<% end %>
</p>
<% end %>
<% if post.cover %>
<p><img src="/uploads/<%= post.cover %>" alt="<%= post.title %>" width="120"></p>
<% end %>
<p><%= post.body %></p>
<p><%= t('posts.comments_count', count: post.comments_count) %></p>
<p class="last-activity"><%= t('posts.last_activity', when: l(post.updated_at)) %></p>
<p><%== link_to(t('posts.read_more'), url_for(:post, slug: post.to_param)) %></p>
</li>
+56
View File
@@ -0,0 +1,56 @@
<h1><%= t('posts.edit_heading') %></h1>
<% unless errors.empty? %>
<h2><%= t('posts.errors_heading') %></h2>
<ul class="errors">
<% errors.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<% end %>
<% form_for(post, url: url_for(:post, slug: post.to_param)) do |f| %>
<%== f.hidden_field(:lock_version) %>
<p>
<%== f.label(:title, t('posts.title_label')) %>
<%== f.text_field(:title) %>
<%== f.error_messages(:title) %>
</p>
<p>
<%== f.label(:body, t('posts.body_label')) %>
<%== f.text_area(:body) %>
<%== f.error_messages(:body) %>
</p>
<p>
<%== f.check_box(:featured) %>
<%== f.label(:featured, t('posts.featured_label')) %>
</p>
<p>
<%== f.label(:giveaway_slots, t('claims.giveaway_slots_label')) %>
<%== f.text_field(:giveaway_slots) %>
<%== f.error_messages(:giveaway_slots) %>
</p>
<%== f.submit(t('posts.update_submit')) %>
<%== f.submit(t('posts.preview_submit'), formaction: url_for(:preview_post, slug: post.to_param)) %>
<h2><%= t('posts.moderate_comments_heading') %></h2>
<% moderated_comments = post.comments.order(:created_at, :desc).to_a %>
<% if moderated_comments.empty? %>
<p><%= t('posts.moderate_comments_empty') %></p>
<% else %>
<% f.fields_for(:comments, moderated_comments) do |cf| %>
<p class="moderated-comment">
<%== cf.hidden_field(:id) %>
<%== cf.label(:body, t('posts.moderate_comment_body_label')) %>
<%== cf.text_area(:body) %>
<%== cf.error_messages(:body) %>
<label>
<%== cf.check_box(:_destroy) %>
<%= t('posts.moderate_comment_remove_label') %>
</label>
</p>
<% end %>
<% end %>
<% end %>
<p><%== link_to(t('posts.back_to_list'), url_for(:posts)) %></p>
+63 -7
View File
@@ -1,21 +1,77 @@
<h1>Blog</h1>
<% content_for(:sidebar) do %>
<%# Deliberately NOT keyed on current_user, unlike the fresh_when etag on this same action: the 5 most recent post titles/links are identical for every viewer, and the signed-in-as banner + new-post form that DO vary per viewer render outside this block, never inside the cached fragment. See prism-postep.md session 62/64. %>
<% cache(:recent_posts_sidebar, expires_in: 60) do %>
<h2><%= t('posts.recent_heading') %></h2>
<ul>
<% Post.order(:created_at, :desc).limit(5).each do |recent| %>
<li><%== link_to(recent.title, url_for(:post, slug: recent.to_param)) %></li>
<% end %>
</ul>
<% end %>
<% end %>
<% if notice %>
<p class="notice"><%= notice %></p>
<% end %>
<% unless errors.empty? %>
<h2><%= t('posts.errors_heading') %></h2>
<ul class="errors">
<% errors.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
<% end %>
<form method="post" action="/posts">
<input type="text" name="title" placeholder="Title">
<textarea name="body" placeholder="Body"></textarea>
<button type="submit">Create post</button>
</form>
<% if user_signed_in? %>
<h2><%= t('posts.new_post_heading') %></h2>
<% form_for(new_post, url: url_for(:posts), html: { enctype: 'multipart/form-data' }) do |f| %>
<p>
<%== f.label(:title, t('posts.title_label')) %>
<%== f.text_field(:title) %>
<%== f.error_messages(:title) %>
</p>
<p>
<%== f.label(:body, t('posts.body_label')) %>
<%== f.text_area(:body) %>
<%== f.error_messages(:body) %>
</p>
<p>
<%== f.label(:cover, t('posts.cover_label')) %>
<%== f.tag(:input, type: 'file', name: 'post[cover]', id: 'post_cover') %>
</p>
<p>
<%== f.check_box(:featured) %>
<%== f.label(:featured, t('posts.featured_label')) %>
</p>
<p>
<%== f.label(:giveaway_slots, t('claims.giveaway_slots_label')) %>
<%== f.text_field(:giveaway_slots) %>
<%== f.error_messages(:giveaway_slots) %>
</p>
<%== f.submit(t('posts.submit')) %>
<% end %>
<h2><%= t('posts.import_heading') %></h2>
<% form_for(Post.new, url: url_for(:import_posts), method: :post, html: { enctype: 'multipart/form-data' }) do |f| %>
<p>
<%== f.label(:file, t('posts.import_label')) %>
<%== f.tag(:input, type: 'file', name: 'file', id: 'post_file', accept: '.csv,text/csv') %>
</p>
<%== f.submit(t('posts.import_submit')) %>
<% end %>
<% end %>
<p class="post-filters">
<%== link_to(t('posts.filter_all'), url_for(:posts)) %>
| <%== link_to(t('posts.filter_recent', days: 7), "#{url_for(:posts)}?days=7") %>
| <%== link_to(t('posts.filter_recent', days: 30), "#{url_for(:posts)}?days=30") %>
| <%== link_to(t('posts.filter_featured'), "#{url_for(:posts)}?featured=1") %>
</p>
<ul class="posts">
<% posts.each do |post| %>
<%== partial('post', locals: { post: post }) %>
<%== partial('post', locals: { post: post, featured_only: featured_only }) %>
<% end %>
</ul>
<%== paginate(posts, path: ->(page) { "#{url_for(:posts)}?page=#{page}#{days.positive? ? "&days=#{days}" : ''}#{featured_only ? '&featured=1' : ''}" }) %>