Installation is done via RubyGems:
gem install trivial
A new binary is created, trivialize
.
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.
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
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"
):
- 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.
- If a
- The
actions
folder is checked for two files:actions/application.inc
actions/about_us/contact.inc
Each found file is included into the program in that order, potentially modifying$content
or$layout
.
- 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
. A layout must exist or an error will occur.
- The value of
$content
is output to the visitor.
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>
The latest Blueprint CSS Framework 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.
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:
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
In your view, modify $global_head
as you would above.
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') ?>
Scripts/styles defined in the tag itself are loaded before $global_head
.