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

🐛 Return early for no snippets #260

Merged
merged 1 commit into from
Jul 13, 2023
Merged

Conversation

kirkkwang
Copy link
Contributor

This commit fixes a bug where the render_snippet method would return ... ... when there are no snippets. This way, in the main application's app/views/catalog/_index_list_default.html.erb file, we can do something like:

<% index_fields(document).each do |field_name, field| -%>
  <% if should_render_index_field? document, field %>
      <div class="search-index-metadata-group metadata-<%= field_name %>">
        <% field_value = doc_presenter.field_value field_name %>
        <%# Don't show the snippets field if it's empty %>
        <% next if field_value.blank? %>
        <dt><%= render_index_field_label document, field: field_name %></dt>
        <dd><%= field_value %></dd>
      </div>
  <% end %>
<% end %>

This way the field label doesn't show up if there are no snippets.

Expected Behavior Before Changes

... ... would appear if there were no snippets

Expected Behavior After Changes

Nothing would appear so in the main application, we can not show the field label.

Screenshots / Video

Before image
After image

This commit fixes a bug where the `render_snippet` method would return
`... ...` when there are no snippets.  This way, in the main
application's `app/views/catalog/_index_list_default.html.erb` file, we
can do something like:

```erb
<% index_fields(document).each do |field_name, field| -%>
  <% if should_render_index_field? document, field %>
      <div class="search-index-metadata-group metadata-<%= field_name %>">
        <% field_value = doc_presenter.field_value field_name %>
        <%# Don't show the snippets field if it's empty %>
        <% next if field_value.blank? %>
        <dt><%= render_index_field_label document, field: field_name %></dt>
        <dd><%= field_value %></dd>
      </div>
  <% end %>
<% end %>
```

This way the field label doesn't show up if there are no snippets.
@kirkkwang kirkkwang merged commit 4a3caaf into main Jul 13, 2023
@kirkkwang kirkkwang deleted the modify-snippet-rendering branch July 13, 2023 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants