Creating build kits

From The Smartest Wiki
Jump to: navigation, search

PLEASE NOTE: This page or section refers to an aspect of Smartest, or a library on which it is dependent, that has not yet been fully implemented.

Build kits are pre-packaged sets of instructions that can create models, pages, or entire websites in Smartest in one click.

As distinct from the system of themes in other systems, build kits stay true to the Smartest ethos of not interfering in how you run your website, whilst making it easier to get started quickly by not requiring all users to start with nothing.

Build kit contents

Build kits contain a number of important components:

  • configure.yml (required)
  • setup_* .php files, which do the actual building (required)
  • Resources/ folder (optional)

Configuration file

PHP setup files

Your PHP setup files can either be separate files, one for each phase of the build kit's execution:

  • setup_content.function.php
  • setup_data_structures.function.php
  • setup_page_structures.function.php
  • setup_templates.function.php

Or the contents of all these files (each contains a PHP function) can be combined in one file, setup_functions.php

Resources folder

Build kit operation

The basic operation of a build kit is relatively simple. The process is as follows:

  1. Present any configuration options to the user as a form
  2. Record and validate responses from options form
  3. Separate relevant options into each phase
  4. Run first phase - content, if enabled, and either required by build kit or selected by user
  5. Run second phase - templates, as above
  6. Run third phase - data structures, as above
  7. Run fourth phase - page structures, as above
  8. Enter the newly created site and present the user with editing and preview options

Phase 1 - installing content

This phase is contained in a function called buildkit_BUILDKITNAME_setup_content(), where BUILDKITNAME is the short name of your build kit, as defined in configure.yml (see above). So a build kit with a short name of 'basic_blog' would have this function called buildkit_basic_blog_setup_content().

In this phase, the build kit can install any non-essential files, including movies, images, CSS, text content or otherwise. Much of this is done with the create_file() function, which takes as its three arguments:

  • the file on disk from which the file is being created,
  • a label for the file, and
  • the type code for the file. If this is omitted, Smartest will attempt to guess the file type from the file's dot suffix, e.g. sample-image.jpg => SM_ASSETTYPE_JPEG_IMAGE

The function will return the asset that has been created as a SmartestAsset object.

Example:

create_file('banner1.jpg', "Top banner image");
$blog_post_text = create_file('first blog post.html', "First Blog Post Text", 'SM_ASSETTYPE_RICH_TEXT');

You can also create file groups and galleries with the create_file_group and create_file_gallery functions.

Phase 2 - installing templates

Phase 3 - installing data structures

Phase 4 - installing page structures