/** * The pre-processing function occurs after the importing, * but before any real processing. This is usually the stage * where we set variables and the like, getting the css ready * for processing. * * @author Anthony Short * @param $css */ public static function parse_grid() { # Find the @grid - this returns an array of 'groups' and 'values' if ($settings = CSS::find_at_group('grid')) { # All the @grids $groups = $settings['groups']; # Store it so it's easier to grab $settings = $settings['values']; # Make sure none of the required options are missing foreach (array('column-count', 'column-width') as $option) { if (!isset($settings[$option])) { throw new Scaffold_Exception('Layout.missing_option', $option); } } # Remove it from the css CSS::replace($groups, array()); # The number of columns, baseline and unit $cc = $settings['column-count']; $unit = isset($settings['unit']) ? $settings['unit'] : 'px'; $bl = isset($settings['baseline']) ? $settings['baseline'] : 18; $cw = $settings['column-width']; # Get the gutters $lgw = isset($settings['left-gutter-width']) ? $settings['left-gutter-width'] : 0; $rgw = isset($settings['right-gutter-width']) ? $settings['right-gutter-width'] : 0; # Get the total gutter width $gw = $settings['gutter-width'] = $lgw + $rgw; # The total grid width $grid = ($cw + $gw) * $cc; $grid_settings = array('column-count' => $cc, 'column-width' => $cw . $unit, 'gutter-width' => $gw . $unit, 'left-gutter-width' => $lgw . $unit, 'right-gutter-width' => $rgw . $unit, 'grid-width' => $grid . $unit, 'baseline' => $bl . $unit); # Set them as constants we can use in the css foreach ($grid_settings as $key => $value) { Constants::set($key, $value); } # Make a directory in the cache just for this plugin if (!is_readable(CACHEPATH . 'Layout')) { mkdir(CACHEPATH . 'Layout'); } # Path to the image $img = CACHEPATH . "Layout/{$lgw}_{$cw}_{$rgw}_{$bl}_grid.png"; # Generate the grid.png self::create_grid_image($cw, $bl, $lgw, $rgw, $img); $img = str_replace(DOCROOT, '/', $img); CSS::append(".showgrid{background:url('" . $img . "');}"); # Round to baselines self::round_to_baseline($bl); # Make each of the column variables a member variable self::$column_count = $cc; self::$column_width = $cw; self::$gutter_width = $gw; self::$left_gutter_width = $lgw; self::$right_gutter_width = $rgw; self::$grid_width = $grid; self::$baseline = $bl; } }
/** * The pre-processing function occurs after the importing, * but before any real processing. This is usually the stage * where we set variables and the like, getting the css ready * for processing. * * @author Anthony Short * @param $css */ public static function parse() { # Find the constants group and values $found = CSS::find_at_group('constants'); # Set the global constants foreach (CSScaffold::config('core.constants') as $key => $value) { self::set($key, $value); } # If there are some constants, let do it. if ($found !== false) { # Sort the constants by length uksort($found['values'], array('self', 'sortByLength')); # Create our template style constants foreach ($found['values'] as $key => $value) { unset(self::$constants[$key]); self::set($key, $value); } # Remove the @constants groups CSS::replace($found['groups'], array()); } }