Skip to content

Commit

Permalink
Merge branch 'feature/func-args' into develop
Browse files Browse the repository at this point in the history
* feature/func-args:
  Document the ability to pass any non-x (bool, array) value for some default function arguments.
  Allow the user to enter any value for some function argument defaults, rather than remember that eg 'false' must be used.
  • Loading branch information
canton7 committed Jun 11, 2011
2 parents f7ba31d + b951dc1 commit c8b121c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 14 additions & 0 deletions classes/casset.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ public static function css($sheet, $sheet_min = false, $group = 'global')
*/
private static function add_asset($type, $script, $script_min, $group)
{
// Don't force the user to remember that 'false' is used when not supplying
// a pre-minified file.
if (!is_string($script_min))
$script_min = false;
if (!array_key_exists($group, static::$groups[$type]))
{
// Assume they want the group enabled
Expand Down Expand Up @@ -379,6 +383,11 @@ private static function add_asset_inline($type, $content)
*/
public function render_js($group = false, $inline = false, $attr = array(), $min = null)
{
// Don't force the user to remember that false is used for ommitted non-bool arguments
if (!is_string($group))
$group = false;
if (!is_array($attr))
$attr = array();
if ($min === null)
$min = static::$min;

Expand Down Expand Up @@ -435,6 +444,11 @@ public function render_js($group = false, $inline = false, $attr = array(), $min
*/
public function render_css($group = false, $inline = false, $attr = array(), $min = null)
{
// Don't force the user to remember that false is used for ommitted non-bool arguments
if (!is_string($group))
$group = false;
if (!is_array($attr))
$attr = array();
if ($min === null)
$min = static::$min;

Expand Down
6 changes: 5 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ Casset::js('myfile.js', 'myfile.min.js', 'group_name');
Casset::css('myfile.css', false, 'group_name');
```

(As an aside, you can pass any non-string value instead of 'false' in the second example, and Casset will behave the same: generate your minified file for you.)

Groups can also be declared on the fly, by specifying a group name which doesn't yet exist. The group is assumed to be enabled.
You can also use a slightly more involved syntax for creating groups, which allows you to specify multiple files and whether the group is enabled, as shown below:

Expand Down Expand Up @@ -213,9 +215,11 @@ Similarly, you can choose to put comments inside each minified file, saying whic
The following will minify the 'group_name' group, even if minification is turned off in the config file.

```php
echo Casset::render_js('group_name', false, array(), true);
echo Casset::render_js(false, false, array(), true);
```

(Again, you can pass any non-string value for the first argument, and any non-array value for the third, and Casset will treat them the same as if the default argument (false and array() respectively) had been passed.)

When minifying CSS files, urls are rewritten to take account of the fact that your css file has effectively moved into `public/assets/cache`.

With JS files, changing the order in which files were added to the group will re-generate the cache file, with the files in their new positions. However with CSS, it will not.
Expand Down

0 comments on commit c8b121c

Please sign in to comment.