phlex-rails icon indicating copy to clipboard operation
phlex-rails copied to clipboard

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

Open rubyforbusiness opened this issue 1 year ago • 5 comments

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 avatar Jul 15 '24 09:07 rubyforbusiness

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

joeldrapper avatar Jul 23 '24 01:07 joeldrapper

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.

trinitytakei avatar Aug 14 '24 12:08 trinitytakei

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)

rubyforbusiness avatar Aug 15 '24 17:08 rubyforbusiness

count me in!

julianrubisch avatar Aug 27 '24 14:08 julianrubisch

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

rubyforbusiness avatar Sep 15 '24 15:09 rubyforbusiness

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 avatar Oct 07 '24 18:10 rubyforbusiness

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 avatar Oct 08 '24 10:10 rubyforbusiness

Hi @joeldrapper I've created a PR for the v1 changes: https://github.com/phlex-ruby/phlex-rails/pull/234.

rubyforbusiness avatar Oct 09 '24 17:10 rubyforbusiness

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 avatar Oct 15 '24 16:10 rubyforbusiness

Hi @joeldrapper , I've created another PR for the v2 changes: https://github.com/phlex-ruby/phlex-rails/pull/237

rubyforbusiness avatar Oct 16 '24 17:10 rubyforbusiness

@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 avatar Oct 16 '24 17:10 rubyforbusiness

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.

rubyforbusiness avatar Oct 16 '24 17:10 rubyforbusiness