Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display summary and description #504

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion app/models/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,26 @@ def yanked?
end

def info
[ description, summary, "This rubygem does not have a description or summary." ].detect(&:present?)
text_or_apology_for :summary, :description
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this correctly, the existing code shows the description if both are present, not the summary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I mis-typed. It's counterintuitive to show a summary iff it's the only thing, then discard it if there's a description.

end

def summary_or_apology
text_or_apology_for :summary
end

def description_or_apology
desc = text_or_apology_for :description
if summary
desc.sub summary, ''
else
desc
end
end

def text_or_apology_for *attrs
apology = "This rubygem does not have a #{attrs.map(&:to_s).join ' or '}."
candidates = attrs.map { |e| send e } + [ apology ]
candidates.detect(&:present?)
end

def update_attributes_from_gem_specification!(spec)
Expand Down
7 changes: 6 additions & 1 deletion app/views/rubygems/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<% else %>
<% if @latest_version.indexed %>
<div id="markup">
<%= simple_markup(@latest_version.info) %>
<div id="gem_summary">
<%= simple_markup(@latest_version.summary_or_apology) %>
</div>
<div id="gem_description">
<%= simple_markup(@latest_version.description_or_apology) %>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need to display both the summary and the description.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it out with a few existing gems (on my local server), and it seems to be an improvement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is not the desired behavior, then the "specification" doc should be updated to say something like, "The description takes precedence over the summary in cases where a longer description is needed", then people can start doing like:

gem.description = gem.summary + "\n…"

</div>

<div class="border">
Expand Down
3 changes: 3 additions & 0 deletions public/stylesheets/screen.css
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,9 @@ table {
list-style: inside disc;
}

#gem_summary {
border-bottom: 1px solid #DAD0BD;
}

.main .info p {
color: #5e543e;
Expand Down
13 changes: 12 additions & 1 deletion test/unit/version_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,35 @@ class VersionTest < ActiveSupport::TestCase
should "have description for info" do
@version.description = @info
assert_equal @info, @version.info
assert_equal @info, @version.description_or_apology
end

should "have summary for info if description does not exist" do
@version.description = nil
@version.summary = @info
assert_equal @info, @version.info
assert_equal @info, @version.summary_or_apology
end

should "have summary for info if description is blank" do
@version.description = ""
@version.summary = @info
assert_equal @info, @version.info
assert_equal @info, @version.summary_or_apology
end

should "filter out the bad habit of putting the summary in the desc" do
@version.description = @info + 'etc.'
@version.summary = @info
assert_equal 'etc.', @version.description_or_apology
end

should "have some text for info if neither summary or description exist" do
@version.description = nil
@version.summary = nil
assert_equal "This rubygem does not have a description or summary.", @version.info
assert_equal "This rubygem does not have a summary or description.", @version.info
assert_equal 'This rubygem does not have a summary.', @version.summary_or_apology
assert_equal 'This rubygem does not have a description.', @version.description_or_apology
end

context "when yanked" do
Expand Down