Skip to content

Commit

Permalink
Adding support for magic slug builds, and making the default builds m…
Browse files Browse the repository at this point in the history
…agic slug builds, so people can think less :). Refs #28
  • Loading branch information
markstory committed Nov 23, 2010
1 parent f84f8df commit 85aac62
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
32 changes: 29 additions & 3 deletions tests/cases/helpers/asset_compress.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function testCssOrderPreserving() {
'link' => array(
'type' => 'text/css',
'rel' => 'stylesheet',
'href' => '/asset_compress/css_files/get/default.css?file[]=base&file[]=reset'
'href' => '/asset_compress/css_files/get/base_reset.css?file[]=base&file[]=reset'
)
);
$this->assertTags($result, $expected);
Expand All @@ -78,13 +78,39 @@ function testScriptOrderPreserving() {
$expected = array(
'script' => array(
'type' => 'text/javascript',
'src' => '/asset_compress/js_files/get/default.js?file[]=libraries&file[]=thing'
'src' => '/asset_compress/js_files/get/libraries_thing.js?file[]=libraries&file[]=thing'
),
'/script'
);
$this->assertTags($result, $expected);
}

/**
* test that magic slug builds work.
*
* @return void
*/
function testScriptMagicSlugs() {
$this->Helper->script('libraries', ':slug-default');
$this->Helper->script('thing', ':slug-default');
$this->Helper->script('jquery.js', ':slug-jquery');
$this->Helper->script('jquery-ui.js', ':slug-jquery');

$result = $this->Helper->includeAssets();
$expected = array(
array('script' => array(
'type' => 'text/javascript',
'src' => '/asset_compress/js_files/get/libraries_thing.js?file[]=libraries&file[]=thing'
)),
'/script',
array('script' => array(
'type' => 'text/javascript',
'src' => '/asset_compress/js_files/get/jquery_js_jquery_ui_js.js?file[]=jquery.js&file[]=jquery-ui.js'
)),
'/script'
);
$this->assertTags($result, $expected);
}

/**
* test generating two script files.
Expand Down Expand Up @@ -221,7 +247,7 @@ function testConfig() {
*/
function testBaseUrl() {
$this->Helper->config('General.baseUrl', 'http://cdn.example.com');
$this->Helper->script('jquery');
$this->Helper->script('jquery', 'default');
$result = $this->Helper->includeJs();
$expected = array(
array('script' => array(
Expand Down
12 changes: 8 additions & 4 deletions views/helpers/asset_compress.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,14 @@ protected function _genericInclude($files, $property, $urlKey) {
if (empty($this->{$property}[$destination])) {
continue;
}
$build = $destination;
if (strpos($destination, ':slug') === 0) {
$build = Inflector::slug(implode('_', $this->{$property}[$destination]));
}
$output[] = $this->_generateAsset(
$property, $destination, $this->{$property}[$destination], $this->options[$urlKey]
$property, $build, $this->{$property}[$destination], $this->options[$urlKey]
);
unset($this->{$property}[$destination]);
unset($this->{$property}[$build]);
}
return implode("\n", $output);
}
Expand Down Expand Up @@ -313,7 +317,7 @@ protected function _timestampFile($name) {
* @param string $destination Name of file that $file should be compacted into.
* @return void
*/
public function script($file, $destination = 'default') {
public function script($file, $destination = ':slug-default') {
if (empty($this->_scripts[$destination])) {
$this->_scripts[$destination] = array();
}
Expand All @@ -328,7 +332,7 @@ public function script($file, $destination = 'default') {
* @param string $destination Name of file that $file should be compacted into.
* @return void
*/
public function css($file, $destination = 'default') {
public function css($file, $destination = ':slug-default') {
if (empty($this->_css[$destination])) {
$this->_css[$destination] = array();
}
Expand Down

0 comments on commit 85aac62

Please sign in to comment.