Blade Generator

Links
Tech
  • WP-CLI
  • Laravel Blade
  • Roots

I’ve been using the Roots WordPress stack at work and for freelance for a few years now. I noticed someone on the Roots forums mention that it would be nice to have the capability to pre-render Blade templates on deploy instead of waiting for them to render on request, so I took decided now was a good time to learn how to write a WP-CLI plugin.

The plugin is intended to adhere to the UNIX philosophy of making a program do one thing and do it well. All it does is render templates, but it does it quietly and elegantly. To use it, all you need to do is run the following:

$ wp blade compile

This scans your active theme for any blade template files, and then renders them through Sage’s Blade interface. It finds template files wherever they are, and uses the cache location described in your theme’s Sage configuration, so it needs no configuration of its own. It doesn’t prompt the user, so it can easily be run on deploy without user input. If you find you only want to render a subset of your templates, it will limit its seach to a directory you pass to it:

$ wp blade compile --directory=path/to/files

Also, if your console supports it, the script uses emoji.