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

Add leex/heex to projectionist #85

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

zolrath
Copy link
Contributor

@zolrath zolrath commented May 5, 2023

This adds the html.leex/html.heex files to projectionist.
Only odd part on this is that we can't have multiple alternates so :A will jump to the test which will jump back to the .ex file.

Alternatives/Questions

  • We could have the alternate file be the .ex file instead of the test.
  • Do we want a basic ["<div>", "", "</div>"] template or just leave it blank?

Usage

Due to the ambiguity these would mostly be used via :Eleex and :Eheex to switch to the file or create it if it does not exist.

"",
},
},
["lib/**/live/*_live.html.heex"] = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think people name their templates suffixed with _live.

I have no memory of ever doing that or of having seen the generators do that. Where have you seen this convention?

image

Copy link
Collaborator

Choose a reason for hiding this comment

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

It's unclear to me what the convention is at this time.

Copy link
Contributor Author

@zolrath zolrath May 5, 2023

Choose a reason for hiding this comment

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

Hm in this example the LiveView files themselves tend to be suffixed with _live.ex as seen in the screenshot you posted with /live/home_live.ex

also seen at

https://github.com/fly-apps/live_beats/tree/master/lib/live_beats_web/live

And in order for Phoenix to use the .html.heex file it should be named the same as the .ex file but with the modified extension.

The most compelling example is seen in the official Phoenix LiveView documentation for Colocating Templates

For larger templates, you can place them in a file in the same directory and same name as the LiveView. For example, if the file above is placed at lib/my_app_web/live/thermostat_live.ex, you can also remove the render/1 definition above and instead put the template code at lib/my_app_web/live/thermostat_live.html.heex.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm in this example the liveview files themselves tend to be suffixed with _live.ex as seen In the screenshot you posted with /live/home_live.ex

also seen at

https://github.com/fly-apps/live_beats/tree/master/lib/live_beats_web/live

I'm referring to the template naming.

The most compelling example is seen in the official Phoneix LiveView documentation for Colocating Templates

For larger templates, you can place them in a file in the same directory and same name as the LiveView. For example, if the file above is placed at lib/my_app_web/live/thermostat_live.ex, you can also remove the render/1 definition above and instead put the template code at lib/my_app_web/live/thermostat_live.html.heex.

I think this might be an outdated example, as I think the current way to do the templates is just with components, using the embed_templates macro

Copy link
Contributor Author

@zolrath zolrath May 5, 2023

Choose a reason for hiding this comment

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

If you'd like I could remove the _live portion and it would effectively allow that to be optional since _live is part of the filename if present.

Also, at the moment this is only covering the liveview heex/leex options, not the controller versions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

makes me wonder if we should make the live view and live view test projections also drop that static convention.

Copy link
Contributor Author

@zolrath zolrath May 5, 2023

Choose a reason for hiding this comment

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

I could do that!

It would change generating a new file with the Elive blog_web/post command to Elive blog_web/post_live but make it more applicable to people who use different conventions so that seems like a worthy tradeoff.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think that makes sense. Thanks.

I probably won't get to testing this until next week.

Could you also (can be a separate PR) add some examples to the README?

@mhanberg
Copy link
Collaborator

mhanberg commented Jun 7, 2023

@zolrath when #108 merges, you should have a foundation for adding projectionist tests.

you can run the tests with bin/test or bin/test path/to/file.

You should run this with >= 0.9 for it to work well.

I'm copy pasting this comment to your other PR

@mhanberg
Copy link
Collaborator

Only odd part on this is that we can't have multiple alternates

I think you can

						*projectionist-alternate*
"alternate"  
        Determines the destination of the |projectionist-:A| command.  If this
        is a list, the first readable file will be used.  Will also be used as
        a default for |projectionist-related|.

@mhanberg
Copy link
Collaborator

@zolrath let me know if you can get to this in the next week or so. if you can, i'll wait to cut the next release, but if not, i'll cut it and this can go in the next one

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