Jump to content

Create Wireframe folder structure via API


Ivan Gretsky
 Share

Recommended Posts

Good day @teppo!

How is it going? I am using Wireframe as a basis for almost all sites I work with. So really hope you're doing fine) Are there any new great plans for this module?

There is a function to create Wireframe folder structure from admin. I was wondering could it be done via API? Need this for a setup script. I know it is not hard to create folders in cli, but a one liner using API would be just neat.

Link to comment
Share on other sites

  • 2 weeks later...

Hey @Ivan Gretsky

Going fine, just been busy and all — so nothing new really 🙂

I don't have new features in the works right now, mostly because for the type of projects I've been working on recently I've felt that it's more about the stuff that's outside Wireframe than in the scope of it that needs work. But since you asked, there are some ideas I've been thinking of adding. Either as a part of the framework, or as a stand-alone things. One of these is Composers, likely similar to what they've got in the Sage theme for WordPress: https://roots.io/sage/docs/composers/.

Honestly still not sure how good an idea that one, but I can see some benefits, and it might be fun to experiment on 🙂

Quote

There is a function to create Wireframe folder structure from admin. I was wondering could it be done via API? Need this for a setup script. I know it is not hard to create folders in cli, but a one liner using API would be just neat.

Makes sense to me, so I've added a new method for that. Usage looks like this:

$wireframe = $modules->get('Wireframe');
$wireframe->initOnce();

// pass in an array of Wireframe dir names, or null to create all; defaults to null,
// default value is an array with dir names as keys and disk paths as values
$dirs = $wireframe->createDirectories([
	'lib',
	'views',
	'layouts',
	'partials',
	'resources',
	'components',
	'controllers',
	'dist',
	'resources',
]);

Note that this is not well tested, and there may be situations I've not accounted for 🙂

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
On 12/1/2024 at 1:37 PM, teppo said:

One of these is Composers, likely similar to what they've got in the Sage theme for WordPress: https://roots.io/sage/docs/composers/.

Thanks for sharing. I am still wrapping my head around the concept. I it passing variables to a specific view... seems like it. But I am not sure I quite understand what problem does it solve. If you would like to discuss it, a real-world example would help)

Link to comment
Share on other sites

Quote

passing variables to a specific view

Exactly.

Composers are useful for cases where we need to share data among different views, or certain types of views. Say, you want all your component views, partials, or perhaps field specific render files to have access to some shared data. Or you have a set of "conceptually related" templates and/or views that all need same variables.

In the context of WordPress / Sage I've used this for things like shared settings, details about current session (such as user specific content, or some stats that I don't want to fetch/calculate multiple times, or in multiple locations), blocks of data that all events or news/articles share (such as a list of latest news/events), etc.

You can achieve similar results via the bootstrap file (e.g. /site/templates/wireframe.php), and for some use cases it works very well. Especially when combined with utility classes or feature modules. But if there are a lot of "if template is x then..." type if-statements there, it can get a bit out of hand. Not to mention that some things are not automatically passed to all views.

Anyway, the main reason I've not jumped right into this is that I'm also debating whether it truly makes sense. I do like the concept and it "feels right", and could potentially be beneficial outside of Wireframe as well. But at the same time I'm not too keen to introduce new concepts just because they sound fun 😄

Link to comment
Share on other sites

Ok. Now I got it better, I think. Now I have _init.php prepending wireframe.php that generates settings array, that I then pass to wireframe->render(). Some absolutely general settings I pass down with setting() function.

If we had composers, we could move all my code in _init.php and wireframe.php to a dedicated class.

Where would these composers be in places if file structure? How would we access data from them in views?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...