bullet-train-co / bullet_train-super_scaffolding Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Forgive me if this is not the right forum for asking, but I'm getting spun up on bullet train, and I'm noticing that CreativeConcept
hot reloads in the browser out of the box. I traced the logic back to the updates_for
PR in cable_ready.
That PR suggests that you would need some sort of enable_updates
method on your model. However, when I look at CreativeConcept
, I don't notice such a method call.
This is something I'd love to carry over to my experimentation, so any clarification here would be great!
bin/super-scaffold crud Orders::Invoices::LineItem Orders::Invoice,Order,Workspace,Team \
description:text_field \
external_id:text_field{vanilla} \
price:text_field
Results in:
Couldn't find 'app/views/account/line_items/index.json.jbuilder'
Couldn't find 'app/views/account/line_items/show.json.jbuilder'
Feels like the template file path maybe isn't the full path?
I'm not entirely sure why this is happening so I want to look into this, but errors aren't being raised in methods from the RoutesFileManipulator
, FileManipulator
, etc. when we're running code in the Transformer.
rails g model Project team:references title:string && \
bin/super-scaffold crud Project Team title:text_field --sidebar="ti.ti-world"
The console will raise errors and stop the process if it's coming from directly within the Transformer. For example, we put an undefined variable in Transformer#scaffold_add_line_to_file
def scaffold_add_line_to_file(file, content, hook, options = {})
puts "Will run"
foo # Undefined variable
puts "Won't run"
file = transform_string(file)
content = transform_string(content)
hook = transform_string(hook)
add_line_to_file(file, content, hook, options)
end
> bin/super-scaffold crud Project Team title:text_field --sidebar="ti.ti-world"
Writing './app/controllers/account/projects_controller.rb'.
Fixing Standard Ruby on './app/controllers/account/projects_controller.rb'.
Writing './app/views/account/projects/_index.html.erb'.
Writing './app/views/account/projects/_form.html.erb'.
Writing './app/views/account/projects/_menu_item.html.erb'.
Writing './app/views/account/projects/show.json.jbuilder'.
Writing './app/views/account/projects/index.html.erb'.
Writing './app/views/account/projects/_project.json.jbuilder'.
Writing './app/views/account/projects/index.json.jbuilder'.
Writing './app/views/account/projects/edit.html.erb'.
Writing './app/views/account/projects/show.html.erb'.
Writing './app/views/account/projects/_breadcrumbs.html.erb'.
Writing './app/views/account/projects/new.html.erb'.
Writing './config/locales/en/projects.en.yml'.
Writing './app/controllers/api/v1/projects_endpoint.rb'.
Fixing Standard Ruby on './app/controllers/api/v1/projects_endpoint.rb'.
Writing './test/controllers/api/v1/projects_endpoint_test.rb'.
Fixing Standard Ruby on './test/controllers/api/v1/projects_endpoint_test.rb'.
Writing './app/serializers/api/v1/project_serializer.rb'.
Fixing Standard Ruby on './app/serializers/api/v1/project_serializer.rb'.
Will run
rake aborted!
NameError: undefined local variable or method `foo' for #<Scaffolding::Transformer:0x00007f0b59c592c8 @child="Project", @parent="Team", @parents=["Team"], @namespace="account", @class_names_transformer=#<Scaffolding::ClassNamesTransformer:0x00007f0b59c59110 @child="Project", @parent="Team", @namespace="account">, @cli_options={"sidebar"=>"ti.ti-world"}, @additional_steps=[]>
foo # Undefined variable
^^^
/home/gazayas/work/bt/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb:345:in `scaffold_add_line_to_file'
/home/gazayas/work/bt/bullet_train-super_scaffolding/lib/scaffolding/transformer.rb:1293:in `scaffold_crud'
/home/gazayas/work/bt/bullet_train-super_scaffolding/lib/bullet_train/super_scaffolding/scaffolders/crud_scaffolder.rb:51:in `run'
/home/gazayas/work/bt/bullet_train-super_scaffolding/lib/scaffolding/script.rb:107:in `<main>'
/home/gazayas/work/bt/bullet_train-super_scaffolding/lib/bullet_train/super_scaffolding.rb:25:in `run'
/home/gazayas/work/bt/bullet_train-super_scaffolding/lib/tasks/bullet_train/super_scaffolding_tasks.rake:10:in `block (2 levels) in <main>'
Tasks: TOP => bullet_train:super_scaffolding
(See full trace by running task with --trace)
RoutesFileManipulator
Here are the same lines in RoutesFileManipulator#insert_before
def insert_before(new_lines, line_number, options = {})
puts "Will run"
foo # Undefined variable
puts "Won't run"
options[:indent] ||= false
before = lines[0..(line_number - 1)]
new_lines = new_lines.map { |line| (block_manipulator.indentation_of(line_number, lines) + (options[:indent] ? " " : "") + line).gsub(/\s+$/, "") + "\n" }
after = lines[line_number..]
self.lines = before + (options[:prepend_newline] ? ["\n"] : []) + new_lines + after
end
> bin/super-scaffold crud Project Team title:text_field --sidebar="ti.ti-world"
Writing './app/controllers/account/projects_controller.rb'.
Fixing Standard Ruby on './app/controllers/account/projects_controller.rb'.
Writing './app/views/account/projects/_index.html.erb'.
Writing './app/views/account/projects/_form.html.erb'.
Writing './app/views/account/projects/_menu_item.html.erb'.
Writing './app/views/account/projects/show.json.jbuilder'.
Writing './app/views/account/projects/index.html.erb'.
Writing './app/views/account/projects/_project.json.jbuilder'.
Writing './app/views/account/projects/index.json.jbuilder'.
Writing './app/views/account/projects/edit.html.erb'.
Writing './app/views/account/projects/show.html.erb'.
Writing './app/views/account/projects/_breadcrumbs.html.erb'.
Writing './app/views/account/projects/new.html.erb'.
Writing './config/locales/en/projects.en.yml'.
Writing './app/controllers/api/v1/projects_endpoint.rb'.
Fixing Standard Ruby on './app/controllers/api/v1/projects_endpoint.rb'.
Writing './test/controllers/api/v1/projects_endpoint_test.rb'.
Fixing Standard Ruby on './test/controllers/api/v1/projects_endpoint_test.rb'.
Writing './app/serializers/api/v1/project_serializer.rb'.
Fixing Standard Ruby on './app/serializers/api/v1/project_serializer.rb'.
Updating './app/controllers/api/v1/root.rb'.
Updating './test/factories/projects.rb'.
Updating './app/models/team.rb'.
Updating './test/controllers/api/v1/projects_endpoint_test.rb'.
Updating './app/views/account/teams/show.html.erb'.
Updating './app/models/project.rb'.
Updating './app/models/project.rb'.
Updating './app/views/account/projects/_form.html.erb'.
Updating './app/views/account/projects/show.html.erb'.
Updating './app/views/account/projects/_index.html.erb'.
Updating './app/views/account/projects/_index.html.erb'.
Updating './config/locales/en/projects.en.yml'.
Updating './config/locales/en/projects.en.yml'.
Updating './app/controllers/account/projects_controller.rb'.
Updating './app/controllers/api/v1/projects_endpoint.rb'.
Updating './app/views/account/projects/_project.json.jbuilder'.
Updating './app/serializers/api/v1/project_serializer.rb'.
Updating './test/controllers/api/v1/projects_endpoint_test.rb'.
Updating './test/controllers/api/v1/projects_endpoint_test.rb'.
Updating './test/controllers/api/v1/projects_endpoint_test.rb'.
Updating './app/models/project.rb'.
Updating './config/locales/en/projects.en.yml'.
Replacing in './config/locales/en/projects.en.yml'.
Will run
Updating 'config/routes.rb'.
Replacing in './config/locales/en/projects.en.yml'.
Updating './app/views/account/shared/_menu.html.erb'.
Restarting the server so it picks up the new localization .yml file.
1. We weren't able to automatically add your `account` routes for you. In theory this should be very rare, so if you could reach out on Slack, you could probably provide context that will help us fix whatever the problem was. In the meantime, to add the routes manually, we've got a guide at https://blog.bullettrain.co/nested-namespaced-rails-routing-examples/ .
2. If you would like the table view you've just generated to reactively update when a Project is updated on the server, please edit `app/models/team.rb`, locate the `has_many :projects`, and add `enable_updates: true` to it.
You can see that Will run
shows up near the bottom, but there is no error being raised, Won't run
never runs, and the process continues as if there's no problem.
Importing from an old to-do. Can we confirm this is working properly?
This is an old to-do I'm cleaning up, so I'm not sure if this is still an issue, but can we check whether this is working properly and add something to the Super Scaffolding test suite in test/bin/setup-super-scaffolding-system-test
and test/system/super_scaffolding_test.rb
to make sure this field partial type is working?
See https://bullet-train.slack.com/archives/C8853NBL1/p1648843400325159 for context.
I used super scaffolding to generate a Project
model/UI and when it got to the step asking for an icon I encountered two problems:
ti-music-alt
) and entered that, but I don't get that icon in my UI.I wondered if it was a problem with just that particular icon, so I tried using one that BT uses elsewhere (ti-home
) and that renders the same thing.
It seems like maybe Themify icons aren't working at all, and the process for choosing a Font Awesome font isn't working as expected.
Update: After poking at this some more I discovered that the music icon will work if I include ti
in the icon string (doing ti ti-music-alt
instead of just ti-music-alt
). It's not obvious that this would be needed.
The Themify docs only mention using the actual icon string and don't say anything about needing a stand alone ti
class. Is that something that's unique to the BT implementation?
It seems that certain actions don't successfully use passed in namespaces. Getting to this point was basically:
git clone [email protected]:bullet-train-co/bullet_train.git
bin/configure
bin/setup
bin/super-scaffold crud Job Team title:text_field --namespace=client
The is the log output:
Writing './app/controllers/clients/jobs_controller.rb'.
Fixing Standard Ruby on './app/controllers/clients/jobs_controller.rb'.
Proceeding to generate './app/views/clients/jobs'.
Writing './app/views/clients/jobs/_menu_item.html.erb'.
Writing './app/views/clients/jobs/show.html.erb'.
Writing './app/views/clients/jobs/_index.html.erb'.
Writing './app/views/clients/jobs/edit.html.erb'.
Writing './app/views/clients/jobs/new.html.erb'.
Writing './app/views/clients/jobs/_form.html.erb'.
Writing './app/views/clients/jobs/_breadcrumbs.html.erb'.
Writing './app/views/clients/jobs/index.html.erb'.
Writing './app/views/api/v1/jobs/_job.json.jbuilder'.
Writing './app/views/api/v1/jobs/index.json.jbuilder'.
Writing './app/views/api/v1/jobs/show.json.jbuilder'.
Writing './app/views/api/v1/open_api/jobs/_components.yaml.erb'.
Writing './app/views/api/v1/open_api/jobs/_paths.yaml.erb'.
Couldn't find './app/views/clients/teams/show.html.erb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/controllers/clients/jobs_controller.rb'.
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/views/clients/jobs/_index.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Updating './app/views/clients/jobs/_form.html.erb'.
Updating './app/views/clients/jobs/show.html.erb'.
Updating './app/controllers/clients/jobs_controller.rb'.
Couldn't find './app/controllers/api/v1/jobs_controller.rb'
Creating 'config/routes/clients.rb'.
Updating 'config/routes.rb'.
Hey, models that are scoped directly off of a Team (or nothing) are eligible to be added to the sidebar.
Do you want to add this resource to the sidebar menu? (y/N)
y
OK, great! Let's do this! By default these menu items appear as a gift icon,
but after you hit enter I'll open a page where you can view other icon options.
When you find one you like, hover your mouse over it and then come back here and
enter the name of the icon you want to use.
(Or hit enter when choosing to skip this step.)
Did you find an icon you wanted to use?
Enter the full CSS class here (e.g. 'ti ti-world') or hit enter to just use the gift icon:
ti ti-paint-roller
Replacing in './config/locales/en/jobs.en.yml'.
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen - ./config/locales/en/jobs.en.yml
Tasks: TOP => bullet_train:super_scaffolding
(See full trace by running task with --trace)
Importing from an old to-do. Can we confirm whether this is working properly?
Creating new provider with supper scaffolding causes error related to invalid system command call on Ubuntu.
➜ application git:(main) ✗ bin/super-scaffold oauth-provider omniauth-google-oauth2 google_oauth2 Oauth::GoogleAccount [...] [...]
OK, great! Let's do this! By default providers will appear with a dollar symbol,
but after you hit enter I'll open a page where you can view other icon options.
When you find one you like, hover your mouse over it and then come back here and
and enter the name of the icon you want to use.
rake aborted!
Errno::ENOENT: No such file or directory - open
/home/[...]/.rvm/gems/ruby-3.1.1/gems/bullet_train-super_scaffolding-1.0.21/lib/bullet_train/super_scaffolding/scaffolders/oauth_provider_scaffolder.rb:64:in ``'
/home/[...]/.rvm/gems/ruby-3.1.1/gems/bullet_train-super_scaffolding-1.0.21/lib/bullet_train/super_scaffolding/scaffolders/oauth_provider_scaffolder.rb:64:in `run'
/home/[...]/.rvm/gems/ruby-3.1.1/gems/bullet_train-super_scaffolding-1.0.21/lib/scaffolding/script.rb:99:in `<main>'
/home/[...]/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/[...]/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.11.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
/home/[...]/.rvm/gems/ruby-3.1.1/gems/zeitwerk-2.5.4/lib/zeitwerk/kernel.rb:35:in `require'
/home/[...]/.rvm/gems/ruby-3.1.1/gems/bullet_train-super_scaffolding-1.0.21/lib/bullet_train/super_scaffolding.rb:25:in `run'
/home/[...]/.rvm/gems/ruby-3.1.1/gems/bullet_train-super_scaffolding-1.0.21/lib/tasks/bullet_train/super_scaffolding_tasks.rake:10:in `block (2 levels) in <main>'
Tasks: TOP => bullet_train:super_scaffolding
(See full trace by running task with --trace)
On Linux distros it should be xdg-open
.
If Linux/Ubuntu should be supported I'll prepare fix with Gem::Platform.local.os == "linux"
.
Let's add a readonly
option to field scaffolding that skips Strong Parameters and fields on the form, but still adds to the table and show view and locales.
Was going to cut a release, but something's broken since merging the last couple PRs.
content
as an Array to add multiple lines at once.As you can see in the tests, we don't automatically add indentation when inserting content inside a block. Here's another example:
lines = [
"def foo",
"end"
]
Scaffolding::BlockManipulator.insert("# no indentation", lines: lines).each {|line| puts line}
#=> def foo
#=> # no indentation
#=> end
content
as an ArrayI think it would be useful to do this, especially if we're also handling the original lines as an Array. If content
is passed as a heredoc, we should probably be able to handle that too.
Importing an old to-do. Can we confirm this is working properly?
Following up on #13: Can we add every field partial type to the Super Scaffolding tests?
I've been looking into these TODOs from the Transformer, and on the surface they didn't seem too difficult, but the issue is definitely more complicated than first expected:
# TODO I _think_ this is the right way to check for whether we need `class_name` to specify the name of the model.
unless transform_string("completely_concrete_tangible_things").classify == child
has_many_line << "class_name: \"Scaffolding::CompletelyConcrete::TangibleThing\""
end
has_many_line << "dependent: :destroy"
# TODO I _think_ this is the right way to check for whether we need `foreign_key` to specify the name of the model.
unless transform_string("absolutely_abstract_creative_concept_id") == "#{parent.underscore}_id"
has_many_line << "foreign_key: :absolutely_abstract_creative_concept_id"
# And if we need `foreign_key`, we should also specify `inverse_of`.
has_many_line << "inverse_of: :absolutely_abstract_creative_concept"
end
The first block runs when Super Scaffolding Projects::Deliverable
within bundle exec test/bin/setup-super-scaffolding-system-test
. Here's the output we get when checking for the transformed string
pry(#<Scaffolding::Transformer>)> transform_string("completely_concrete_tangible_things")
=> "deliverables"
child
is Project::Deliverables
though, so although we should be getting projects_deliverables
, we get deliverables
so it's cutting off the namespace and will always add the class_name
option. It's technically adding it to the right place, but the check isn't entirely accurate.
I ended up using the following:
[1] pry(#<Scaffolding::Transformer>)> child
=> "Projects::Deliverable"
[2] pry(#<Scaffolding::Transformer>)> parent
=> "Project"
[3] pry(#<Scaffolding::Transformer>)> transform_string("scaffolding_completely_concrete_tangible_things")
=> "projects_deliverables"
However, when classfying it, we just get this:
ProjectsDeliverable
We could somehow use a regexp to insert ::
in the proper places, but I feel like this still doesn't cover the core issue. I know we call class_name
when the database table has a different name than what we're working with, but I'm having trouble trying to flesh out what would be a good model setup to make sure this part runs as desired.
rails g model
/Super Scaffolding combination is the most ideal to check this part of the code?child
given in the Transformer?Our Super Scaffolding system tests have been working up until now with these unless
statements, but it would definitely be better to have a firm grasp on this part in case we run into any related problems in the future.
Still, it's not an easy one so I think it'll take me some time to work on it.
We used to try and map these automatically, but honestly, I think it creates more confusion than benefit, so let's tell folks that they need to use field partial names and direct them to the field partials page in the documentation.
We should import the following files from Bullet Train's project repository and get them running as part of the test suite for this Ruby gem.
./test/lib/scaffolding/examples/*
./test/lib/scaffolding/routes_file_manipulator_test.rb
./test/lib/scaffolding/transformer_test.rb
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.