You are here

function sweaver_drush_css_to_json in Sweaver 7

Same name and namespace in other branches
  1. 6 drush/sweaver.drush.inc \sweaver_drush_css_to_json()

Convert the stylesheet back to JSON format.

Parameters

$css: A stylesheet. $return $json_css

1 call to sweaver_drush_css_to_json()
sweaver_drush_edit_style in drush/sweaver.drush.inc
Edit a style.

File

drush/sweaver.drush.inc, line 409
Sweaver Drush functions.

Code

function sweaver_drush_css_to_json($css) {
  ctools_include('css');
  $json_css = new stdClass();
  $ctools_css = ctools_css_disassemble($css);
  $sweaver_properties = sweaver_object_load(NULL, 'property');
  foreach ($ctools_css as $selector => $properties) {
    foreach ($properties as $property => $value) {
      if (isset($sweaver_properties[$property])) {

        // Get the property.
        $sp = $sweaver_properties[$property];

        // Use str replaces to remove prefixes, suffixes and ;
        $new_value = str_replace(array(
          $sp->property_prefix,
          $sp->property_suffix,
          ';',
        ), '', $value);
        $json_css->{$selector}->{$property} = $new_value;
      }
    }
  }
  return json_encode($json_css);
}