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 scaffold generator to create phlex classes not erb files #234

Open
wants to merge 15 commits into
base: v1
Choose a base branch
from

Conversation

rubyforbusiness
Copy link
Contributor

This change enables the standard rails scaffold generator to create Phlex views instead of .erb templates.

It also wires up the generated controllers to these views. The actual look of the views is almost identical to the erb ones which means the generated standard tests all work fine.

The purpose is to showcase how Phlex can be used to create a (basic but well understood) object-oriented UI in Rails.

NB: the target of this change is phlex-rails:v1 - because there have been some breaking changes in v2 and because many people will not be able to move to Ruby 3.3 easily which v2 demands.

See the commit message for how to try this out manually.

I've been through the rails generator code and tried all the cases I can find including attachments, password digests and references.

Unfortnately I couldn't find an easy way to test this automatically without interfering with the existing test/dummy/app installation. There are issues with rails locking the application layout file, and with wanting to run the generated tests from within the test that generates them!

I'd be happy to add tests in if someone can suggest a good way to do it. Perhaps creating a dummy2 app? Or perhaps putting all this generation code in a new repo?

bradgessler and others added 15 commits October 9, 2024 17:30
Goodcop config was using an old URL
The issues fixed in the branch have been resolved, merged, released.
…B templates

* use phlex 1.11.0 rather than deleted branch
* update ApplicationComponent template to include helpers and methods needed for scaffold generation
* add generator for phlex views and controllers via scaffold, by installing these files:
```
(in local app) lib/templates/rails/scaffold_controller/controller.rb.tt
(ref in gem) lib/generators/rails/phlex_scaffold/phlex_scaffold_generator.rb
```

Usage:

Simple example:
```
bin/rails g scaffold author name:string auth_token:token  --template-engine=phlex_scaffold
```

Complex example, testing all field types, attachments and an association (the model above)
* NB: uncomment 'bcrypt' and 'image_processing' in Rails 7 Gemfile, bundle and restart server
```
bin/rails active_storage:install
bin/rails g scaffold article title:string body:text finalised:boolean viewed:date commission_rate:float password:digest avatar:attachment images:attachments author:references --template-engine=phlex_scaffold
```
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.

8 participants