Skip to content

feat(Picture): Add support for only and except setting#3522

Draft
tvdeyen wants to merge 4 commits intomainfrom
pictures-only-except
Draft

feat(Picture): Add support for only and except setting#3522
tvdeyen wants to merge 4 commits intomainfrom
pictures-only-except

Conversation

@tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Dec 15, 2025

What is this pull request for?

This allows to use only and except setting on Picture ingredients like on File ingredients.

TODO

  • Fix "not used on pages scope"

Checklist

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have added tests to cover this change

@tvdeyen tvdeyen self-assigned this Dec 15, 2025
@tvdeyen tvdeyen added this to the 8.1 milestone Dec 15, 2025
@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.45%. Comparing base (bddb4cd) to head (1712cc0).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3522      +/-   ##
==========================================
- Coverage   97.46%   97.45%   -0.02%     
==========================================
  Files         314      314              
  Lines        8218     8239      +21     
==========================================
+ Hits         8010     8029      +19     
- Misses        208      210       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tvdeyen tvdeyen force-pushed the pictures-only-except branch from b318d92 to cd69a59 Compare January 27, 2026 11:24
@tvdeyen tvdeyen added the enhancement New feature or enhancement label Jan 27, 2026
@tvdeyen tvdeyen changed the title Pictures only except feat(Picture): Add support for only and except setting Jan 27, 2026
@tvdeyen tvdeyen marked this pull request as ready for review January 27, 2026 11:25
@tvdeyen tvdeyen requested a review from a team as a code owner January 27, 2026 11:25
@tvdeyen tvdeyen force-pushed the pictures-only-except branch 5 times, most recently from 2e0aed3 to 328668c Compare January 27, 2026 18:11
@tvdeyen tvdeyen marked this pull request as draft January 27, 2026 18:12
Use Ruby's `File.basename` and Rails' `humanize` to create the first
initial human readable `name` of `Attachment`s and `Picture`s.

Before we where using our own brittle Regexp, that expected the file
suffix to be known from it's mime type. This is not the case for unknown
mimetypes.

We also move the name conversion before filename sanitization in order
to get a nice human readable name and not escape characters. Since the
name is not used to load the file and all output is escaped in Rails by
default, this is fine.

Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud>
Both Attachment.file_types and Picture.file_formats now delegate
from_extensions handling to the storage adapter's file_formats method.
Each adapter converts extensions to the format it uses internally:
Dragonfly keeps bare extensions for pictures and converts to MIME
types for attachments, while Active Storage always converts to MIME
types via Marcel.

This removes the Marcel conversion that lived in Attachment.file_types
and centralizes all format-aware logic in the adapters where it
belongs.
The Picture ingredient now supports `only` and `except` settings to
constrain which image formats are available in the picture library
overlay, matching the existing Attachment/File ingredient behavior.

Signed-off-by: Thomas von Deyen <vondeyen@blish.cloud>
We never used the not_file_type scope, but used the
by_file_type scope with a inverted collection instead.

Also use Attachment.file_types(from_extensions:) instead
of inline Marcel::MimeType.for conversion.
@tvdeyen tvdeyen force-pushed the pictures-only-except branch from 328668c to 1712cc0 Compare January 28, 2026 09:13
@tvdeyen tvdeyen removed this from the 8.1 milestone Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant