One of the chief benefits of a Dojo module layer is that it
facilitates the creation of a custom build.
Zend_Dojo_BuildLayer has functionality for
generate build profiles.
The simplest use case is to utilize the
generateBuildProfile() method and send the
output to a file:
<?php
$build = new Zend_Dojo_BuildLayer(array(
'view' => $view,
'layerName' => 'custom.main',
));
$profile = $build->generateBuildProfile();
$filename = APPLICATION_PATH . '/../misc/scripts/custom.profile.js';
file_put_contents($filename, $profile);
Just like generating layers, you may want to automate this via a
dispatchLoopShutdown() plugin hook; you
could even simply modify the one shown for generating layers to read
as follows:
<?php
class App_Plugin_DojoLayer extends Zend_Controller_Plugin_Abstract
{
public $layerScript = APPLICATION_PATH
. '/../public/js/custom/main.js';
public $buildProfile = APPLICATION_PATH
. '/../misc/scripts/custom.profile.js';
protected $_build;
public function dispatchLoopShutdown()
{
if (!file_exists($this->layerScript)) {
$this->generateDojoLayer();
}
if (!file_exists($this->buildProfile)) {
$this->generateBuildProfile();
}
}
public function generateDojoLayer() { /* ... */ }
public function generateBuildProfile()
{
$profile = $this->getBuild()->generateBuildProfile();
file_put_contents($this->buildProfile, $profile);
}
}
As noted, with module layers, you should only create the file once.
The above functionality will suffice for most situations. The only way to customize build profile generation is to provide additional build profile options to utilize.
As an example, you may want to specify what type of optimizations should be performed, whether or not to optimize CSS files in the layer, whether or not to copy tests into the build, etc. For a listing of available options, you should read the Dojo Build documentation and accompanying documentation.
Setting these options is trivial: use the
addProfileOption(),
addProfileOptions(), or
setProfileOptions() methods. The first
method adds a single key and value option pair, the second will add
several, and the third will overwrite any options with the list
of key and value pairs provided.
By default, the following options are set:
{
action: "release",
optimize: "shrinksafe",
layerOptimize: "shrinksafe",
copyTests: false,
loader: "default",
cssOptimize: "comments"
}
You can pass in whatever key and value pairs you want; the Dojo build script will ignore those it does not understand.
As an example of setting options:
<?php
// A single option:
$build->addProfileOption('version', 'zend-1.3.1');
// Several options:
$build->addProfileOptions(array(
'loader' => 'xdomain',
'optimize' => 'packer',
));
// Or overwrite options:
$build->setProfileOptions(array(
'version' => 'custom-1.3.1',
'loader' => 'shrinksafe',
'optimize' => 'shrinksafe',
));




