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

WIP: Utilize props mimetype #14

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

joshleblanc
Copy link

@joshleblanc joshleblanc commented Jan 14, 2024

I was playing around with Superglue in a hobby app, which uses the same controller for html views and api calls. So games/show.json would be your json response, and games/show.html would be your html response.

When you install superglue, it assumes that your json response will be the props, so any jbuilder templates will no longer function in favor of the prop templates. This didn't feel right, so I went poking around at adding a new mime type.

This PR allows specifying the format for a request as :props rather than :json. Your file would have to be names [name].props.pbuilder to be picked up properly.

Note that I changed the name of the file to pbuilder instead of props. This was just to get it working so I had something to show. The reason it's changed is because the file format is [name].[format].[handler]. Without changing the name of either the mime type or the handler, the format ends up being [name].props.props, which looks awful.

--

If you want to test this in a superglue app, the following changes need to be made

  1. Rename app/layouts/application.json.props to app/layouts/application.props.pbuilder
  2. Change the first line of the layout to check if format.props? instead of format.json?
  3. Change formats: [:json] to formats: [:props] in your erb views
  4. Rename your .json.props files to .props.pbuilder

@jho406
Copy link
Contributor

jho406 commented Jan 19, 2024

Hi! Thanks for commenting and trying out superglue!

I'm not quite ready for the proposed change.

When you install superglue, it assumes that your json response will be the props, so any jbuilder templates will no longer function in favor of the prop templates. This didn't feel right, so I went poking around at adding a new mime type.

Yup! props_template is a DSL that builds JSON. Its is a friendly alternative to jbuilder that competes for the same json mime type.

so any jbuilder templates will no longer function in favor of the prop templates.

You can still use jbuilder, as long as its on a different route. Or if you really prefer, superglue.js just expects a JSON response so you can create a games/show.json.jbuilder instead, but you won't have support for layouts or digging, and will have to build your response to match the page response

@joshleblanc
Copy link
Author

@jho406 Understandable!

I've changed the PR to use Props::Handler.default_format in place of hardcoded :json symbols. This should let users override it if they want, and register their own mimetype

@jho406
Copy link
Contributor

jho406 commented Jan 28, 2024

@joshleblanc Thanks! I'm more open to that change. Would it be possible to add a test case for it?

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