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

Use Rails' CurrentAttributes to store globals #2701

Merged
merged 5 commits into from
Mar 5, 2024

Conversation

tvdeyen
Copy link
Member

@tvdeyen tvdeyen commented Jan 22, 2024

What is this pull request for?

Instead of our own custom implementation for Alchemy globals that
use the request_store gem, we use Rails' built in Current Attributes.

Notable changes

Alchemy::Page.current_preview, Alchemy::Language.current and Alchemy::Site.current are now deprecated
and replaced by Alchemy::Current.preview_page, Alchemy::Current.language and Alchemy::Current.site.

We also introduced a new global Alchemy::Current.preview_page? that returns true if the current rendered page
is also the page currently previewed in page editor. You should use that instead of @preview_mode.

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

@mamhoff
Copy link
Contributor

mamhoff commented Jan 22, 2024

Sweet - would this allow us to remove the request_store dependency?

@tvdeyen
Copy link
Member Author

tvdeyen commented Jan 22, 2024

@mamhoff yes, thats why its still WIP

@tvdeyen tvdeyen self-assigned this Jan 22, 2024
@tvdeyen tvdeyen force-pushed the use-current-attributes branch 2 times, most recently from 8a0d153 to f7cc9a6 Compare January 24, 2024 11:17
@tvdeyen tvdeyen added this to the 7.2 milestone Jan 24, 2024
@tvdeyen tvdeyen force-pushed the use-current-attributes branch 2 times, most recently from a696479 to 322bea8 Compare March 2, 2024 19:45
@tvdeyen tvdeyen marked this pull request as ready for review March 2, 2024 19:52
This deprecates

- `Alchemy::Site.current`
- `Alchemy::Language.current`

in favor of

`Alchemy::Current.site`
`Alchemy::Current.language`

Also introduces

- `Alchemy::Current.preview_page`
This is an alias for `Site.first`. Use that instead.
We use Alchemy::Current now, that uses Rails' built in
CurrentAttributes instead.
@tvdeyen tvdeyen changed the title Use Rails' CurrentAttributes Use Rails' CurrentAttributes to store globals Mar 2, 2024
@tvdeyen tvdeyen requested a review from a team March 2, 2024 20:40
@tvdeyen tvdeyen removed their assignment Mar 2, 2024
@tvdeyen
Copy link
Member Author

tvdeyen commented Mar 4, 2024

@mamhoff ready for review

Copy link
Contributor

@mamhoff mamhoff left a comment

Choose a reason for hiding this comment

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

Nice! :)

@tvdeyen tvdeyen merged commit d2d1f1b into AlchemyCMS:main Mar 5, 2024
34 checks passed
@tvdeyen tvdeyen deleted the use-current-attributes branch March 5, 2024 09:48
tvdeyen added a commit to tvdeyen/alchemy_cms that referenced this pull request Sep 3, 2024
With Alchemy 7.2 (AlchemyCMS#2701) we started to use `Alchemy::Current.page`
for rendering elements of current page. If one has a custom
controller to render Alchemy content with:

    render(template: "alchemy/pages/show")

it is now empty if `Alchemy::Current.page` is not set.

Someday we might deprecate the `@page` instance variable,
but until then we need to fall back to it.
tvdeyen added a commit to tvdeyen/alchemy_cms that referenced this pull request Sep 3, 2024
Since Alchemy 7.2 (AlchemyCMS#2701) we need to set `Alchemy::Page.current`
if we want to render a page from another controller.
tvdeyen added a commit that referenced this pull request Sep 4, 2024
With Alchemy 7.2 (#2701) we started to use `Alchemy::Current.page`
for rendering elements of current page. If one has a custom
controller to render Alchemy content with:

    render(template: "alchemy/pages/show")

it is now empty if `Alchemy::Current.page` is not set.

Someday we might deprecate the `@page` instance variable,
but until then we need to fall back to it.

(cherry picked from commit 26072ab)
tvdeyen added a commit that referenced this pull request Sep 4, 2024
Since Alchemy 7.2 (#2701) we need to set `Alchemy::Page.current`
if we want to render a page from another controller.

(cherry picked from commit 19b2b34)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants