I have an app called StandardTheme that I use every time I create a new app to include the styling and some javascript common to most apps.
The StandardTheme app does nothing else that showing a form to test whether the css and the javascript works as expected.
When I create a new app I clone it to my computer, delete the theme folder, copy the theme folder from the StandardTheme app to the new app and push it. At this point the new app has colors, styles, spinner, etc. consistent with all the apps.
This little trick has been working well for a long time and still works well, but I am wondering if I risk to create apps that don’t work with new components introduced after I create my template app long time ago.
Are there best practices that allow me to keep using an old template app without risking to create new stale apps?
1 Like
That’s partly why I created my cookiecutter template. I inject my own stuff into a current app and I can update any of the component parts separately.
I wanted to ask this question for a long time. I asked it now because I saw your post about the cookiecutter and I started thinking about the difference between:
- having a template app and cloning it
- creating a new app and replacing the theme folder with the one from the StandardTheme app
- using a cookiecutter
I thought that all 3 ways would all carry files that slowly get stale.
For example standard-page.html
in my StandardTemplate has been completely butchered. I have modified it to include a footer with copyright information, the company logo, etc. and it still has this line that was there when I first created the original Anvil app:
<div anvil-slot-repeat="default"></div>
but now, when I create a new app, that line has one more class.
<div anvil-slot-repeat="default" class="anvil-measure-this"></div>
I guess the new class is used by new components or enables new behaviors that didn’t exist when I first created the StandardTheme app.
A cookiecutter has the benefit of being dynamic. It can replace texts on a predefined template, rename files and add or remove files. But I don’t think it can pick and choose what parts of a file to keep and what to change.
I had a quick look at your repository, and for what I understand it will replace the whole standard-page.html
file with whatever stale information was there when the cookiecutter was created. It will not try to merge the new with the template.
Or should I just learn how cookiecutters work?
Whilst it’s true that, right now, my template is doing as you say, that’s purely because I haven’t done anything with that particular file in any of my own code.
The template itself is just a git repo, so it can be versioned. Its content can be dynamic, just like my main form, and pre and post generation hook scripts (I have only one of those just now) can also get involved.
Just realised I may have misunderstood your question. Yes, a template only affects project creation. It does nothing for existing apps.
1 Like
I see the advantage of the cookiecutter over a static clone or copy and paste.
But my question was about how to make sure I keep the parts I need from my customized template/cookiecutter without missing on the improvements that are released over time by the Anvil team.
Do you think it is possible to create a new app, clone it to your computer, compare it to some sort of template that specifies what’s important and what can change, and:
- if nothing important has changed, then keep going with the cookiecutter job
- if something marked important inside a file has changed, then show a warning and stop
At this point I know whether I can trust the old cookiecutter or I should merge the old cookiecutter templates with the new file contents before proceeding.
If the standard theme were also published, that would become a whole lot easier…!
What do you think @meredydd? Could you see yourselves publishing the standard theme to a github repo using releases and version numbers?
That way, I could incorporate the latest version into my template (as I do for the other components now) and @stefano.menci could spot when updates occur and choose whether to patch those into existing projects.
1 Like