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

Enable Rails Controller Generator to create Phlex Views instead of ERB templates #208

Open
rubyforbusiness opened this issue Jul 15, 2024 · 12 comments
Assignees

Comments

@rubyforbusiness
Copy link
Contributor

rubyforbusiness commented Jul 15, 2024

Back in 2022 @joeldrapper [said] (https://github.com/orgs/phlex-ruby/discussions/235#discussioncomment-3852112):

... Yeah, Phlex is not a Rails template engine. It's a complete replacement for ActionView. I think we could find a way to hook into controller generation to have it generate Phlex views instead of ERB templates.

I'd like to have a go at implementing this as it would really enable people to see the power of OO views quickly, easily and from a familiar starting point.

@rubyforbusiness rubyforbusiness changed the title Have Controller Generator create P Enable Rails Controller Generator to create Phlex Views instead of ERB templates Jul 15, 2024
@joeldrapper
Copy link
Collaborator

Sounds great! Give me a shout if you have any questions.

@trinitytakei
Copy link
Contributor

trinitytakei commented Aug 14, 2024

Hey @rubyforbusiness did you get anywhere with this? I'm pretty much betting the farm on Phlex (as in, all the apps (a relatively large amount) I'm creating from now on are going using Phlex), so I'm really keen on this (and other things, but this would be awesome ASAP).

Let me know if you'd like to discuss etc.

@rubyforbusiness
Copy link
Contributor Author

Hey @rubyforbusiness did you get anywhere with this? I'm pretty much betting the farm on Phlex (as in, all the apps (a relatively large amount) I'm creating from now on are going using Phlex), so I'm really keen on this (and other things, but this would be awesome ASAP).

Let me know if you'd like to discuss etc.

Hi @trinitytakei , yes I'm currently working on this, a little sporadically as I'm also looking for paid employment! But I'm really excited about the potential of Phlex and like you, already introduced it into a production system I was working on early this year.

I plan to do some more work on it this coming week. Here's where I've got to so far:

  • using a vanilla Ruby application as a test bed (will convert to the dummy app in this repo in due course)
  • using a command like this: bin/rails g scaffold article title:string body:text --template-engine=phlex_view
    • replace index.html.erb with phlex, including controller calls
    • ditto single record partial (e.g. `_article.html.erb)
    • ditto new.html.erb
    • in progress
      • form.html.erb
    • next
      • show.html.erb
      • edit.html.erb
      • layout in phlex (bonus)
      • move code to phlex_rails
      • adapt phlex install to pick it up
      • add tests

Obviously I'm making up some conventions regarding the naming of things, but we can discuss that at PR time.

What I'm excited to do in future tickets, and never got a chance on the production project I mentioned, is to really start taking advantage of an OOUI to do things like:

  • investigate the kits thing that @joeldrapper mentioned in the main phlex repo
  • make the styling of components easy to setup and change at a high level (instead of having moutains of repeated CSS especially when using Tailwind)
  • make it possible to plugin Hotwire features (instead of having to grapple with all the low-level moving parts)

@julianrubisch
Copy link

count me in!

@rubyforbusiness
Copy link
Contributor Author

Thanks for assigning this to me @joeldrapper . I've done the code and am in the process of writing some tests.

@rubyforbusiness
Copy link
Contributor Author

Sorry for the delay in doing this work. I've been working on a short-term contract which is the first paid work I've had in quite a while. Now I'm looking for another job.

I was going to finish this ticket today, but when I tried to rebase to the latest main, I realised there have been quite a few changes to the install_generator.rb. I'll see if I can follow them and update my code to work with them. Happy to receive any pointers though @joeldrapper .

@rubyforbusiness
Copy link
Contributor Author

Sorry for the delay in doing this work. I've been working on a short-term contract which is the first paid work I've had in quite a while. Now I'm looking for another job.

I was going to finish this ticket today, but when I tried to rebase to the latest main, I realised there have been quite a few changes to the install_generator.rb. I'll see if I can follow them and update my code to work with them. Happy to receive any pointers though @joeldrapper .

I've just had a thought. I bet a lot of people are still on Ruby 2 and can't upgrade that easily yet would like to try Phlex. I could put my current change into a patch release for phlex-rails 1.2. Is that something you'd support? Then I could do a separate ticket for the phlex-rails 2+. What do you think @joeldrapper ? (Happy to discuss on Slack or Twitter if that's helpful)

@rubyforbusiness
Copy link
Contributor Author

Hi @joeldrapper I've created a PR for the v1 changes: #234.

@rubyforbusiness
Copy link
Contributor Author

FYI @joeldrapper , I'm working on the v2 changes in a separate branch. Whilst I'm there I'm going to change the existing tests to use the new namespacing e.g. get rid of ApplicationComponent and use Components::Base instead.

@rubyforbusiness
Copy link
Contributor Author

Hi @joeldrapper , I've created another PR for the v2 changes: #237

@rubyforbusiness
Copy link
Contributor Author

@trinitytakei , @julianrubisch I'd be interested in your input on this, now there's something to try :-).
I've tested it out manually but would be keen to test automatically if you can find a nice way. See comments in the commits for how to test.

@rubyforbusiness
Copy link
Contributor Author

I guess an obvious improvement, if these PRs go in, is to add the 'scaffold' examples to the handbook on phlex.fun and beta.phlex.fun.

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

No branches or pull requests

4 participants