Skip to content

Commit c9c4ae4

Browse files
committed
feature/Only display more button for snippets that have a preview
1 parent 94a4a03 commit c9c4ae4

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

app/models/snippet.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ def liked_by?(user)
4848
likes.find_by_user_id(user&.id).present?
4949
end
5050

51-
def language_label
52-
"<span style='border-radius: 5px; position: absolute; top: -13px; right: 25px; border: 1px solid lightgrey; font-family: monospace; padding: 4px 28px 4px 10px; background-color: snow;'><i style='position: absolute; right: 7px;' class='devicon-ruby-plain colored'></i>#{ language.name }</span>"
53-
end
5451

5552
# Prevent needing to do on the fly by saving to db
5653
def preview
57-
body.split("\n").first(15).join("\n")
54+
@preview ||= body.split("\n").first(15).join("\n")
55+
end
56+
57+
def has_preview?
58+
preview != body
5859
end
5960

6061
def client_id

app/views/snippets/_snippet_preview.html.erb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@
3131
</div>
3232

3333
<div class="relative">
34-
<div class="transition text-gray-500 hover:underline absolute border rounded-md bottom-2 right-2 z-3 bg-white text-sm px-2 py-1">
35-
<span>More...</span>
36-
</div>
34+
<% if snippet.has_preview? %>
35+
<div title="View the entire snippet" class="transition text-gray-500 hover:underline absolute border rounded-md bottom-2 right-2 z-3 bg-white text-sm px-2 py-1">
36+
<span>More...</span>
37+
</div>
38+
<% end %>
3739
<%= render partial: 'shared/codemirror', locals: { code: snippet.preview, mode: snippet.language.slug, read_only: true, classes: 'snippet--content' } %>
3840
</div>
3941
</div>

0 commit comments

Comments
 (0)