-
Notifications
You must be signed in to change notification settings - Fork 10
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
centralize abstraction for thumbnail generation #1681
Merged
pgwillia
merged 2 commits into
integration_postmigration
from
1343_centralize_abstraction_for_thumbnail
Jun 4, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
<% begin %> | ||
<%# NOTE: This is superficially similar to the logic in DraftItem#thumbnail, but this file is run against | ||
every file attached to an item via a JS callback rendering files/update_files_list.js.erb calling _files_list.html.erb | ||
whereas DraftItem#thumbnail specifically only deals with rendering the designated file for representing it as a | ||
thumbnail and is used on various other pages, like profiles, which use the application/_thumbnail partial.%> | ||
<% thumbnail = rails_representation_path(file.variant(resize: '100x100', auto_orient: true).processed) %> | ||
<%= safe_thumbnail_tag(thumbnail, alt: '', title: file.filename, size: '100x100') %> | ||
<% rescue ActiveStorage::InvariableError %> | ||
<% begin %> | ||
<% thumbnail = rails_representation_path(file.preview(resize: '100x100', auto_orient: true).processed) %> | ||
<%= safe_thumbnail_tag(thumbnail, alt: '', title: file.filename, size: '100x100') %> | ||
<% rescue ActiveStorage::UnpreviewableError %> | ||
<div class="text-muted text-center img-thumbnail p-3"> | ||
<%= icon('far', file_icon(file.content_type), class: 'fa-5x') %> | ||
<span class="sr-only"><%= file.filename %></span> | ||
</div> | ||
<% end %> | ||
<% if thumbnail_path(file).present? %> | ||
<%= safe_thumbnail_tag(thumbnail_path(file), alt: '', title: file.filename, size: '100x100') %> | ||
<% else %> | ||
<div class="text-muted text-center img-thumbnail p-3"> | ||
<%= icon('far', file_icon(file.content_type), class: 'fa-5x') %> | ||
<span class="sr-only"><%= file.filename %></span> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,8 @@ | ||
<% begin %> | ||
<%# NOTE: This is superficially similar to the logic in DraftItem#thumbnail, but this file is run against | ||
every file attached to an item via a JS callback rendering files/update_files_list.js.erb calling _files_list.html.erb | ||
whereas DraftItem#thumbnail specifically only deals with rendering the designated file for representing it as a | ||
thumbnail and is used on various other pages, like profiles, which use the application/_thumbnail partial.%> | ||
<% thumbnail = rails_representation_path(file.variant(resize: '100x100', auto_orient: true).processed) %> | ||
<%= safe_thumbnail_tag(thumbnail, alt: '', title: file.filename, size: '100x100') %> | ||
<% rescue ActiveStorage::InvariableError %> | ||
<% begin %> | ||
<% thumbnail = rails_representation_path(file.preview(resize: '100x100', auto_orient: true).processed) %> | ||
<%= safe_thumbnail_tag(thumbnail, alt: '', title: file.filename, size: '100x100') %> | ||
<% rescue ActiveStorage::UnpreviewableError %> | ||
<div class="text-muted text-center img-thumbnail p-3"> | ||
<%= icon('far', file_icon(file.content_type), class: 'fa-5x') %> | ||
<span class="sr-only"><%= file.filename %></span> | ||
</div> | ||
<% end %> | ||
<% if thumbnail_path(file).present? %> | ||
<%= safe_thumbnail_tag(thumbnail_path(file), alt: '', title: file.filename, size: '100x100') %> | ||
<% else %> | ||
<div class="text-muted text-center img-thumbnail p-3"> | ||
<%= icon('far', file_icon(file.content_type), class: 'fa-5x') %> | ||
<span class="sr-only"><%= file.filename %></span> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
logo: | ||
name: 'files' | ||
record_type: 'Item' | ||
record_id: <%= ActiveRecord::FixtureSet.identify(:fancy) %> | ||
blob_id: <%= ActiveRecord::FixtureSet.identify(:jpeg) %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
jpeg: | ||
key: '12345' | ||
filename: 'image-sample.jpeg' | ||
content_type: 'image/jpeg' | ||
byte_size: 12086 | ||
checksum: "GxpIjJsC4KnRoBKNjWnkJA==" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ def base_url | |
|
||
# page_title | ||
|
||
# page_title | ||
test 'should return the page title when given one' do | ||
assert_equal t('site_name'), page_title(t('site_name')) | ||
end | ||
|
@@ -93,9 +92,66 @@ def base_url | |
@community.logo.attach io: File.open(file_fixture('image-sample.jpeg')), | ||
filename: 'image-sample.jpeg', content_type: 'image/jpeg' | ||
|
||
assert_equal page_image_url, request.base_url + @community.thumbnail_path | ||
assert_equal page_image_url, request.base_url + thumbnail_path(@community.thumbnail_file) | ||
end | ||
|
||
# thumbnail_path | ||
|
||
def mupdf_exists? | ||
ActiveStorage::Previewer::MuPDFPreviewer.mutool_exists? | ||
end | ||
|
||
def poppler_exists? | ||
ActiveStorage::Previewer::PopplerPDFPreviewer.pdftoppm_exists? | ||
end | ||
|
||
test 'thumbnail_path should return preview for pdf (Invariable but Previewable)' do | ||
skip 'this test requires the dependency MuPDF or Poppler to be installed' unless mupdf_exists? || poppler_exists? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some information about the dependencies here https://guides.rubyonrails.org/active_storage_overview.html#previewing-files |
||
|
||
item = items(:fancy) | ||
File.open(file_fixture('pdf-sample.pdf'), 'r') do |file| | ||
item.add_and_ingest_files([file]) | ||
end | ||
|
||
logo = item.reload.files.first | ||
expected = Rails.application.routes.url_helpers.rails_representation_path( | ||
logo.preview(resize: '100x100', auto_orient: true).processed | ||
) | ||
assert_equal expected, thumbnail_path(logo) | ||
end | ||
|
||
test 'thumbnail_path should return preview for image (Variable)' do | ||
item = items(:fancy) | ||
File.open(file_fixture('image-sample.jpeg'), 'r') do |file| | ||
item.add_and_ingest_files([file]) | ||
end | ||
|
||
logo = item.reload.files.first | ||
expected = Rails.application.routes.url_helpers.rails_representation_path( | ||
logo.variant(resize: '100x100', auto_orient: true).processed | ||
) | ||
assert_equal expected, thumbnail_path(logo) | ||
end | ||
|
||
test 'thumbnail_path should provide nil if no thumbnail is possible (StandardError on variable)' do | ||
logo = active_storage_attachments(:logo) | ||
logo.define_singleton_method(:variant) { |_| throw StandardError } | ||
|
||
assert_nil thumbnail_path(logo) | ||
# TODO: assert that the logger.warn was written | ||
end | ||
|
||
test 'thumbnail_path should return nil if both the variant and preview fail' do | ||
logo = active_storage_attachments(:logo) | ||
logo.define_singleton_method(:variant) { |_| throw ActiveStorage::InvariableError } | ||
logo.define_singleton_method(:preview) { |_| throw StandardError } | ||
|
||
assert_nil thumbnail_path(logo) | ||
# TODO: assert that the logger.warn was written | ||
end | ||
|
||
# canonical_href | ||
|
||
test 'canonical_href is returning the correct canoncial url' do | ||
assert_equal Jupiter::PRODUCTION_URL, canonical_href(nil) | ||
assert_equal Jupiter::PRODUCTION_URL, canonical_href('/') | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is installing poppler easy on CI/Dev machines? If not then maybe we should keep it as an "optional" dependency (if not installed we just fallback to file icon image which already happens as it returns nil)? Maybe this test only runs if Poppler dependency is defined 🤔 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's pretty easy in Ubuntu
sudo apt-get install poppler-utils
I'll see if I can get this to work like Clamby.jupiter/app/models/concerns/draft_properties.rb
Line 153 in be07bda
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jupiter/.github/workflows/push.yml
Line 6 in b667a36
https://github.com/actions/virtual-environments/blob/master/images/linux/Ubuntu2004-README.md
Has ImageMagick installed but not the PDF dependencies.