Skip to content

Commit a1870c5

Browse files
committed
Render snippet with user-generated markdown support
1 parent 96b12c6 commit a1870c5

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

app/views/share/snippets/index.html.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99
<% @snippets.each do |snippet| %>
1010
<div id="<%= dom_id(snippet) %>" class="section-content mb-xl">
11-
<%= link_to share_snippet_path(snippet), class: "block" do %>
11+
<%= render Markdown::Safe.new(snippet.description) if snippet.description %>
12+
<%= link_to share_snippet_path(snippet), class: "section-content" do %>
1213
<%= render CodeBlock::Snippet.new(snippet) %>
1314
<% end %>
1415
<div>

app/views/share/snippets/show.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<div class="section-content container py-gap mb-3xl">
1515
<%= turbo_frame_tag :snippet_form do %>
1616
<div class="section-content">
17+
<%= render Markdown::Safe.new(@snippet.description) if @snippet.description %>
1718
<%= render CodeBlock::Snippet.new(@snippet) %>
1819
<div>
1920
<%= render Share::Snippets::Toolbar.new(@snippet, current_user: current_user) %>

spec/factories/snippets.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
source { "puts \"Hello, world!\"" }
44
language { "ruby" }
55
filename { "example.rb" }
6+
description { "# Hello World in Ruby" }
67
author { build(:user) }
78
end
89
end

spec/requests/share/snippets_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
expect(response).to be_successful
99
end
1010

11+
it "renders a successful response without filename" do
12+
FactoryBot.create(:snippet, filename: nil)
13+
get share_snippets_url
14+
expect(response).to be_successful
15+
end
16+
17+
it "renders a successful response without description" do
18+
FactoryBot.create(:snippet, description: nil)
19+
get share_snippets_url
20+
expect(response).to be_successful
21+
end
22+
1123
it "does not render the New Snippet button when not allowed" do
1224
get share_snippets_url
1325

@@ -29,6 +41,18 @@
2941
expect(response).to be_successful
3042
end
3143

44+
it "renders a successful response without filename" do
45+
snippet = FactoryBot.create(:snippet, filename: nil)
46+
get share_snippet_url(snippet)
47+
expect(response).to be_successful
48+
end
49+
50+
it "renders a successful response without description" do
51+
snippet = FactoryBot.create(:snippet, description: nil)
52+
get share_snippet_url(snippet)
53+
expect(response).to be_successful
54+
end
55+
3256
it "does not render the Edit Snippet button when not allowed" do
3357
Flipper.enable(:snippets, login_as_user)
3458
snippet = FactoryBot.create(:snippet)

0 commit comments

Comments
 (0)