Skip to content

Commit

Permalink
Adding the ninesixty theme's function ns().
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleAMathews committed Feb 2, 2011
1 parent 3270065 commit 4336833
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions template.php
Expand Up @@ -474,3 +474,43 @@ function dewey_render_node_body($nid) {
return $node->body;
}

/**
* Contextually adds 960 Grid System classes.
*
* The first parameter passed is the *default class*. All other parameters must
* be set in pairs like so: "$variable, 3". The variable can be anything available
* within a template file and the integer is the width set for the adjacent box
* containing that variable.
*
* class="<?php print ns('grid-16', $var_a, 6); ?>"
*
* If $var_a contains data, the next parameter (integer) will be subtracted from
* the default class. See the README.txt file.
*/
function ns() {
$args = func_get_args();
$default = array_shift($args);
// Get the type of class, i.e., 'grid', 'pull', 'push', etc.
// Also get the default unit for the type to be procesed and returned.
list($type, $return_unit) = explode('-', $default);

// Process the conditions.
$flip_states = array('var' => 'int', 'int' => 'var');
$state = 'var';
foreach ($args as $arg) {
if ($state == 'var') {
$var_state = !empty($arg);
}
elseif ($var_state) {
$return_unit = $return_unit - $arg;
}
$state = $flip_states[$state];
}

$output = '';
// Anything below a value of 1 is not needed.
if ($return_unit > 0) {
$output = $type . '-' . $return_unit;
}
return $output;
}

0 comments on commit 4336833

Please sign in to comment.