2010-03-21 19:10:08 +00:00
# Trivial - the ultra-lightweight Web framework for PHP
## Installation
Installation is done via RubyGems:
`gem install trivial`
A new binary is created, `trivialize` .
## Creating a new site
`cd` to the directory where you want your new site and type:
`trivialize my-new-site`
A directory called `my-new-site` will be created with the site structure in place. An example `content/index.html` and `views/application.inc` will also be installed.
2010-04-02 15:47:26 +00:00
## Upgrading an existing site
Backup your existing site folder, `cd` to the site folder and type:
`trivialize --upgrade`
The following files will be overwritten:
* `lib/trivial.php`
* `styles/blueprint`
And if they don't exist, the following files will be created:
* `config/trivial.inc`
2010-03-21 19:10:08 +00:00
## The request process
When a request comes in to that directory for a file that doesn't exist, trivial
does the following (for the examples, the request was for `about_us/contact.html` and the default `$layout` value is `"application"` ):
2010-04-02 15:47:26 +00:00
* The `content` folder is checked for an `.html` or `.inc` file that matches the path (`content/about_us/contact.html`).
* If a `.html` file exists, the contents of the file are pulled into the global `$content` variable.
* If a `.inc` file exists, the file is include()d and the output is placed into the global `$content` variable.
2010-03-21 19:10:08 +00:00
* The `actions` folder is checked for two files:
* `actions/application.inc`
* `actions/about_us/contact.inc`
2010-04-02 15:47:26 +00:00
Each found file is included into the program in that order, potentially modifying `$content` or `$layout` .
2010-03-21 19:10:08 +00:00
* The `views` folder is checked for two files:
* `views/about_us/contact.inc`
* `views/application.inc`
Each found file is included into the program, including `$content` where specified and outputting back into `$content` .
2010-04-02 15:47:26 +00:00
A layout *must exist* or an error will occur.
2010-03-21 19:10:08 +00:00
* The value of `$content` is output to the visitor.
## Styles and scripts
2010-04-02 15:47:26 +00:00
By default, the provided `views/application.inc` file has three functions for including stylesheets and scripts:
< head >
<?php echo blueprint() ?>
<?php echo scripts() ?>
<?php echo styles() ?>
< / head >
### Blueprint
The latest [Blueprint CSS Framework ](http://blueprintcss.org/ ) comes with Trivial. It's included into the defaut application.inc layout
with the `blueprint()` function. Blueprint's licence can be found in the `styles/blueprint` directory.
### Other Styles and Scripts
The `scripts()` and `styles()` functions, by default, only search for files named `application.ext` and `name/of/request.ext` .
For the request `contact/about_us.html` , the following JavaScript and CSS files will be searched for, in this order:
* `scripts/application.js`
* `scripts/contact/about_us.js`
* `styles/application.css`
* `styles/contact/about_us.css`
You can incude other scripts and stylesheets in several ways:
#### Globally, before application- and page-specific includes
Inside of `config/trivial.inc` , add the following variable definition:
`$global_head = array('scripts' => array(), 'styles' => array());`
In the `scripts` and `styles` arrays, add the names of the other files to include, not including the extension:
`$global_head = array('scripts' => array('jquery-1.4.2.min'), 'styles' => array('client'));`
These scripts are loaded before the ones listed above, so the new search path becomes:
* `scripts/jquery-1.4.2.min.js`
* `scripts/application.js`
* `scripts/contact/about_us.js`
* `styles/client.css`
* `styles/application.css`
* `styles/contact/about_us.css`
#### Locally, via a view, before application- and page-specific includes
In your view, modify `$global_head` as you would above.
#### Within the layout, without adding new script() or style() tags
Adding additional parameters to the `scripts()` or `styles()` tag works the same as adding items to the `$global_head` :
`<?php echo scripts('jquery-1.4.2.min') ?>`
`<?php echo styles('client') ?>`
2010-04-02 14:40:13 +00:00
2010-04-02 15:47:26 +00:00
Scripts/styles defined in the tag itself are loaded before `$global_head` .
2010-04-02 14:40:13 +00:00