Skip to content

Commit 80fe072

Browse files
authored
Merge pull request #306 from joyofrails/feat/permanent-draft
Adding a permanent draft
2 parents 71df909 + ba0a958 commit 80fe072

File tree

8 files changed

+65
-32
lines changed

8 files changed

+65
-32
lines changed
10.6 KB
Loading

app/content/pages/articles.html.erb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@ title: Articles
33
description: Read the latest articles from Joy of Rails
44
---
55

6-
<section style="min-height: 51vh">
7-
<%= render Pages::Header.new(
8-
title: "Articles",
9-
description: "Read the latest articles from Joy of Rails"
10-
) %>
11-
<div class="main-content container py-gap">
12-
<%= render Pages::List.new(SitepressArticle.published(params)) %>
13-
</div>
14-
</section>
6+
<% articles = Page.all.published.order(published_at: :desc) %>
7+
<%= render Pages::Header.new(
8+
title: "Articles",
9+
description: "Read the latest articles from Joy of Rails"
10+
) %>
11+
<div class="main-content container py-gap">
12+
<%= render Pages::List.new(articles) %>
13+
</div>
1514
<section>
1615
<%= render "users/newsletter_subscriptions/banner" %>
1716
</section>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
title: Zee Kitchen Sink Permanent Draft
3+
author: Ross Kaffenberger
4+
layout: article
5+
summary: This article is a kitchen sink of features I may be experimenting with and is never meant to be published
6+
description: This article is a kitchen sink of features I may be experimenting with and is never meant to be published
7+
published: '2999-12-31'
8+
image: articles/zee-kitchen-sink-permanent-draft/placeholder.jpg
9+
meta_image: articles/zee-kitchen-sink-permanent-draft/placeholder.jpg
10+
tags:
11+
- Rails
12+
---
13+
14+
## Inline Poll Demo
15+
16+
<%= render Share::Polls::LazyPagePoll.new(Current.page, "SQLite on Rails Poll", "How likely are you to use SQLite in your Rails app?" => ["100%", "Strongly considering", "On the fence", "Not very, but open minded", "No way"]) if Current.page %>

app/content/pages/drafts.html.erb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<% articles = SitepressArticle.draft %>
2-
<section style="min-height: 51vh">
3-
<div class="main-content container py-gap lg:py-3xl">
4-
<% articles.take(3).zip(%w[left right].cycle).each do |(page, side)| %>
5-
<%= render Pages::Summary.from_page(page, side: side) %>
6-
<% end %>
1+
<% articles = Page.all.draft.order(published_at: :asc) %>
72

8-
<h3 class="mt-16">More articles</h3>
9-
<%= render Pages::List.new(articles.drop(3).take(6)) %>
3+
<section style="min-height: 51vh">
4+
<%= render Pages::Header.new(
5+
title: "Drafts articles",
6+
description: "Drafts articles set to be published at some point in the future"
7+
) %>
8+
<div class="main-content container py-gap">
9+
<%= render Pages::List.new(articles) %>
1010
</div>
1111
</section>
1212
<section>

app/controllers/share/polls/votes_controller.rb

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,15 @@ def create
1111
@vote ||= record_vote(@answer)
1212

1313
if @vote.valid?
14-
flash[:notice] = "Thank you for voting!".emojoy
1514
respond_to do |format|
1615
format.html { redirect_to [:share, @poll] }
17-
18-
# Why is request_id set to nil?
19-
#
20-
# Credit: https://radanskoric.com/articles/update-full-page-on-form-in-frame-submit
21-
# "By default Turbo will ignore refreshes that result from requests
22-
# started from the current page. This is done to avoid double
23-
# refresh when we make a change which then broadcasts a refresh
24-
# through ActionCable. However, in this case this is exactly what
25-
# we want to do so we have to clear request id."
26-
format.turbo_stream { render turbo_stream: turbo_stream.refresh(request_id: nil) }
16+
format.turbo_stream do
17+
flash.now[:notice] = "Thank you for voting!"
18+
render turbo_stream: [
19+
turbo_stream.prepend("flash", partial: "application/flash"),
20+
turbo_stream.replace(@poll, renderable: Share::Polls::PollComponent.new(@poll, device_uuid: ensure_device_uuid))
21+
]
22+
end
2723
end
2824
else
2925
render :new
@@ -37,10 +33,6 @@ def record_vote(answer)
3733
vote.user = Current.user if user_signed_in?
3834
end
3935
end
40-
41-
def ensure_device_uuid
42-
cookies.signed[:device_uuid] ||= SecureRandom.uuid_v7
43-
end
4436
end
4537
end
4638
end

app/models/page/sitepressed.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def upsert_collection_from_sitepress!(limit: nil)
5252
enum.to_a
5353
end
5454

55+
def upsert_page_by_request_path!(request_path)
56+
upsert_page_from_sitepress!(Sitepress.site.get(request_path))
57+
end
58+
5559
def upsert_page_from_sitepress!(sitepress_resource)
5660
page = find_or_initialize_by(request_path: sitepress_resource.request_path)
5761
page.published_at = sitepress_resource.data.published.to_time.middle_of_day if sitepress_resource.data.published

spec/requests/site/articles_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
describe "GET /articles" do
2424
it "lists published articles" do
25+
Page.upsert_collection_from_sitepress!
2526
get "/articles"
2627

2728
expect(response).to have_http_status(:ok)
@@ -33,6 +34,7 @@
3334

3435
describe "GET /drafts" do
3536
it "lists draft articles" do
37+
Page.upsert_collection_from_sitepress!
3638
get "/drafts"
3739

3840
expect(response).to have_http_status(:ok)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require "rails_helper"
2+
3+
RSpec.describe "Zee Kitchen Sink Permanent Draft", type: :system do
4+
it "displays the article content" do
5+
FactoryBot.create(:user, :primary_author)
6+
Page.upsert_page_by_request_path! "/articles/zee-kitchen-sink-permanent-draft"
7+
8+
visit "/articles/zee-kitchen-sink-permanent-draft"
9+
10+
expect(page).to have_content "Zee Kitchen Sink Permanent Draft"
11+
12+
expect(page).to have_content "How likely are you to use SQLite in your Rails app?"
13+
14+
within ".poll" do
15+
click_button "Strongly considering"
16+
end
17+
18+
expect(page).to have_content "Thank you for voting!"
19+
end
20+
end

0 commit comments

Comments
 (0)