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 (phlex v2) #237

Open
wants to merge 3 commits into
base: main
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.

See the commit messages 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?

NB: I've also fixed the existing tests to use the phlex v2 naming conventions (see 594fdbc)

…B templates

* 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.

1 participant