Replace the default templates that Grails generates - grails

So, i am getting started with Grails and i just started using install-templates! And it is a pretty cool stuff.
I learned that i should modify the installed templates before using generate-all, generate-views or generate-controllers.
But what i couldn't figure out (and also i couldn't find in google) is how to make the changes i have made to the template permanent. A want to make the changes i have made to be used for all the projects i create from now on.
In a nutshell, How can i change the default templates Grails generates?

You have to modify the scaffolding-X.X.X.zip at grails-X-X-X\plugins (the place you installed it) so the generate goes for all the projects.

Go to src/templates/scaffolding and edit the files.

Related

Is it possible to override the create_migration template in Rails 6?

I tried placing my custom file in multiple locations inside the lib folder with no success.
I found a PR from 2017 to reactivate this behavior but wasn't merged.
https://github.com/rails/rails/pull/13972
I had a look at
https://github.com/rails/rails/blob/master/activerecord/lib/rails/generators/active_record/migration/migration_generator.rb#L17
and it looks like it's not implemented, but I don't know if just this file should change.
I´ve found resources on how to do it in older rails versions, but is there any way to override the Rails templates in Rails 6?
From this line of the documentation:
Since we want to customize Rails::Generators::HelperGenerator, we can do that by simply making a template copy inside lib/templates/rails/helper with the name helper.rb.
In the case for migrations, the template names should be specified as follows (here are the default templates for reference):
lib/templates/active_record/migration/create_table_migration.rb.tt
lib/templates/active_record/migration/migration.rb.tt

Editing UI of Samvera Hyrax

I wanted to customize the UI of Samvera Hyrax application and I've built a HTML template. Now, I want to replace the old UI with the content of my HTML files, when I say it on github I found view files where I can edit the application to implement my design. But after installing I could not find any files under views. Though I found application.html.erb.
I cannot figure out where <%= yeild %> has been pointing and when I replaced all the content with my home page code. It made no changes in the hyrax working.
Thanks in advance.
Assuming you followed the Hyrax installation procedure detailed on the github wiki here, what you'll notice looking at your routes in config/routes.rb is that Hyrax is mounted as a rails engine. So using the template you didn't clone Hyrax, but you created a new rails app that uses Hyrax as an Engine. If you haven't used Engines before, it may be worth reading up on them here. This is why you don't see all the views from the Hyrax project in the application you've generated using their template.
You can override views from the Engine by creating the view in your own project in the same path as it is in Hyrax. You may want to do some additional digging to determine if this is a path you really want to go down, as it can get complicated to maintain overridden views, and there may be alternative strategies that can accomplish some of what you want to do with CSS or themeing within Hyrax. It may depend on how much you want to override and how custom a theme you are trying to achieve.

Can a Rails application template include generator parameters?

When I start a new Rails application, I often use certain parameters to rails new like --skip-spring or --skip-turbolinks.
I understand I can put these in ~/.railsrc, but when using multiple dev computers, it can be a bit tedious to keep railsrc files in sync across all of them.
Can I use application templates to add these parameters to the generator? That would be great, because application templates can be referenced by a url and downloaded on the fly.
(Also I know I can use templates to make changes after the application is created, so I can remove spring or turbolinks or whatever, but it would be much nicer to never generate the app that way.)
To answer my own question after looking into how this works, I think the short answer is that it's not possible to add generator parameters from an application template to rails new itself. The reason is that the template code only runs when the application is already generated.

What is the app/templates directory for when using Yeoman?

As the title suggests I want to know what the app/templates directory is for when using Yeoman.
Thanks
Yeoman team member here.
It's simply meant to put your templates in. Like your Handlebar.js templates or Mustache, etc.
Nothing magic happens when you do, at least not yet. Just a best practice we wanted to enforce.

Change Rails Scaffold Naming Scheme

I'm a happy user of RoR but have one complaint. When I do script/generate scaffold it automatically generates all my files and places them in their proper folders. However, all the different scaffolds I've created name their view files the same.
I have a bunch of index.html.erb view files and when I have them open in my text editor, it's almost impossible to tell what controller they're related to.
I'd like to change the default naming scheme of the scaffold command to name the individual files to contain their view folder name. So, instead of index.html.erb, use index.home.html.
Is there a way to do this, or am I stuck? What solutions to the multiple files with the same name problem have you Rails developers discovered?
Thanks!
You're going to be fighting the Rails' conventions by going down that path and Rails works best when you work with it rather than against it. A core part of the philosophy of Rails is that there are a set of conventions that once learned make it easy to find your way around any Rails application.
Instead of trying to redefine how Rails works, I would recommend taking advantage of the features offered by your text editor or IDE for quickly navigating to the correct view template. For example, the Rails bundle within TextMate on the Mac lets you quickly open the view file associated with a particular model and there's a plugin for Vim that provides an equivalent feature.

Resources