Example #1
0
/**
 * Process CSS file and return CSS as text wrapped in html style tags.
 *
 * @see docs/api/functions.md
 */
function csscrush_inline($file, $options = array(), $tag_attributes = array())
{
    if (!is_array($options)) {
        $options = array();
    }
    if (!isset($options['boilerplate'])) {
        $options['boilerplate'] = false;
    }
    $file = csscrush_file($file, $options);
    if ($file && $file->path) {
        $tagOpen = '';
        $tagClose = '';
        if (is_array($tag_attributes)) {
            $attrs = CssCrush\Util::htmlAttributes($tag_attributes);
            $tagOpen = "<style{$attrs}>";
            $tagClose = '</style>';
        }
        return $tagOpen . file_get_contents($file->path) . $tagClose . "\n";
    }
}
Example #2
0
 /**
  * Deprecated.
  *
  * @see csscrush_file().
  */
 public static function file($file, $options = array())
 {
     return csscrush_file($file, $options);
 }
Example #3
0
 public function getViewCss($options, $paetteKey)
 {
     $contents = $this->entities['content']->getData();
     $settings = $this->entities['setting']->getData();
     $return = array();
     foreach ($contents as $content) {
         if (isset($content['templateCss']) && (is_array($content['templateCss']) && $content['templateCss'])) {
             foreach ($content['templateCss'] as $key => $cssTemplateSource) {
                 $cssTemplateSource = $this->getCssTemplateDir() . '/' . $cssTemplateSource;
                 if (file_exists($cssTemplateSource)) {
                     // echo $cssTemplateSource;
                     $cssTemplate = $this->getProfileDir() . '/' . $settings['userId'] . '/pages/' . $settings['page'] . '/assets/css/' . $content['id'] . '.' . $key . '.template.css';
                     copy($cssTemplateSource, $cssTemplate);
                     $outputDir = $this->getProfileDir() . '/' . $settings['userId'] . '/pages/' . $settings['page'] . '/assets/css/';
                     $assetDir = $this->getProfileDir() . '/' . $settings['userId'] . '/pages/' . $settings['page'] . '/assets/img/';
                     $options['output_dir'] = $outputDir;
                     $options['asset_dir'] = $assetDir;
                     $options['output_file'] = $content['id'] . '.' . $key . '_' . $paetteKey . '.style.css';
                     // $options['rewrite_import_urls'] = false;
                     // print_r($options);
                     $return[] = csscrush_file($cssTemplate, $options);
                 }
             }
         }
     }
     // csscrush_file($file
     return $return;
 }
Example #4
0
 public function getCss($cssTemplate, $options, $user, $page)
 {
     $outputDir = $this->get('kernel')->getRootDir() . '/../web/profile/' . $user . '/pages/' . $page . '/assets/css/';
     $assetDir = $this->get('kernel')->getRootDir() . '/../web/profile/' . $user . '/pages/' . $page . '/assets/img/';
     $options['output_dir'] = $outputDir;
     $options['asset_dir'] = $assetDir;
     $options['output_file'] = 'style.css';
     // $options['rewrite_import_urls'] = false;
     return csscrush_file($cssTemplate, $options);
     // csscrush_file($file
 }
Example #5
0
            $outstandingErrors = false;
            stderr(message(fmt_fileinfo($stats, 'output'), array('type' => 'write')));
        }
        if (($showErrors || $changed) && $warnings) {
            stderr(message($warnings, array('type' => 'warning')));
        }
        if ($changed && $args->stats) {
            stderr(message($stats, array('type' => 'stats')));
        }
        sleep(1);
    }
} else {
    $stdOutput = null;
    if ($args->input_file && isset($options['output_dir'])) {
        $options['cache'] = false;
        csscrush_file($args->input_file, $options);
    } else {
        $stdOutput = csscrush_string($input, $options);
    }
    $stats = csscrush_stat();
    $errors = $stats['errors'];
    $warnings = $stats['warnings'];
    if ($errors) {
        stderr(message($errors, array('type' => 'error')));
        exit(STATUS_ERROR);
    } elseif ($args->input_file && !empty($stats['output_filename'])) {
        stderr(message(fmt_fileinfo($stats, 'output'), array('type' => 'write')));
    }
    if ($warnings) {
        stderr(message($warnings, array('type' => 'warning')));
    }