本文整理汇总了PHP中Less_Parser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP Less_Parser::parse方法的具体用法?PHP Less_Parser::parse怎么用?PHP Less_Parser::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Less_Parser
的用法示例。
在下文中一共展示了Less_Parser::parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cupid_generate_less
/**
* Created by PhpStorm.
* User: duonglh
* Date: 8/23/14
* Time: 3:01 PM
*/
function cupid_generate_less()
{
require_once 'Less.php';
$cupid_data = of_get_options();
try {
$primary_color = $cupid_data['primary-color'];
$secondary_color = $cupid_data['secondary-color'];
$button_color = $cupid_data['button-color'];
$bullet_color = $cupid_data['bullet-color'];
$icon_box_color = $cupid_data['icon-box-color'];
$site_logo_url = $cupid_data['site-logo'];
$site_logo_white_url = $cupid_data['site-logo-white'];
$site_logo_url = str_replace(THEME_URL, '', $site_logo_url);
$site_logo_white_url = str_replace(THEME_URL, '', $site_logo_white_url);
$css = '@primary_color:' . $primary_color . ';';
$css .= '@secondary_color:' . $secondary_color . ';';
$css .= '@button_color:' . $button_color . ';';
$css .= '@bullet_color:' . $bullet_color . ';';
$css .= '@icon_box_color:' . $icon_box_color . ';';
$css .= "@logo_url : '" . $site_logo_url . "';@logo_white_url : '" . $site_logo_white_url . "';";
$css .= '@theme_url:"' . THEME_URL . '";';
$style = $css;
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once THEME_DIR . "lib/inc-generate-less/custom-css.php";
$custom_css = cupid_custom_css();
WP_Filesystem();
global $wp_filesystem;
$options = array('compress' => true);
$parser = new Less_Parser($options);
$parser->parse($css);
$parser->parseFile(THEME_DIR . 'assets/css/less/style.less');
$parser->parse($custom_css);
$css = $parser->getCss();
if (!$wp_filesystem->put_contents(THEME_DIR . "style.min.css", $css, FS_CHMOD_FILE)) {
echo __('Could not save file', 'cupid');
return '0';
}
/*$theme_info = $wp_filesystem->get_contents( THEME_DIR . "theme-info.txt" );
$parser = new Less_Parser();
$parser->parse($style);
$parser->parseFile(THEME_DIR . 'assets/css/less/style.less',THEME_URL);
$style = $parser->getCss();
$parser->parse($custom_css);
$style = $theme_info . "\n" . $style;
$style = str_replace("\r\n","\n", $style);
$wp_filesystem->put_contents( THEME_DIR. "style.css", $style, FS_CHMOD_FILE);*/
return '1';
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
return '0';
}
}
示例2: parse
/**
* Parse given css file with given vars.
*
* @param string $file
* @param array $vars
*
* @return string
*/
public function parse($file, array $vars, $custom)
{
$this->parser->parseFile($this->app['base_dir'] . '/assets/less/vendor/bootstrap/' . $file . '.less', $this->app['base_url']);
$this->parser->modifyVars($vars);
$css = $this->parser->getCss();
//parse custom less if any passed
if ($custom) {
$this->parser->reset();
$customCss = $this->parser->parse($custom)->getCss();
} else {
$customCss = '';
}
return $css . $customCss;
}
示例3: compile
public function compile($source, $pathname)
{
$less = new \Less_Parser();
$less->SetImportDirs(array(dirname($pathname) => './'));
$less->parse($source);
return $less->getCss();
}
示例4: CssPreprocessor
function CssPreprocessor($content, $type)
{
if ($type == 'css') {
} else {
if ($type == 'less') {
try {
$parser = new Less_Parser();
$parser->parse($content);
$content = $parser->getCss();
} catch (Exception $e) {
var_dump($e->getMessage());
}
} else {
if ($type == 'sass') {
$scss = new scssc();
$content = $scss->compile($content);
} else {
if ($type == 'stylus') {
$stylus = new Stylus();
$content = $stylus->fromString($content)->toString();
}
}
}
}
return $content;
}
示例5: compileFile
/**
* @param string $themeName
* @param string $lessFile
* @return string
*/
public function compileFile($themeName, $lessFile)
{
$model = Model::instance();
$theme = $model->getTheme($themeName);
$options = $theme->getOptionsAsArray();
$configModel = ConfigModel::instance();
$config = $configModel->getAllConfigValues($themeName);
$less = "@import '{$lessFile}';";
$less .= $this->generateLessVariables($options, $config);
$css = '';
try {
require_once ipFile('Ip/Lib/less.php/Less.php');
$themeDir = ipFile('Theme/' . $themeName . '/assets/');
$ipContentDir = ipFile('Ip/Internal/Core/assets/ipContent/');
// creating new context to pass theme assets directory dynamically to a static callback function
$context = $this;
$callback = function ($parseFile) use($context, $themeDir) {
return $context->overrideImportDirectory($themeDir, $parseFile);
};
$parserOptions = array('import_callback' => $callback, 'cache_dir' => ipFile('file/tmp/less/'), 'relativeUrls' => false, 'sourceMap' => true);
$parser = new \Less_Parser($parserOptions);
$directories = array($themeDir => '', $ipContentDir => '');
$parser->SetImportDirs($directories);
$parser->parse($less);
$css = $parser->getCss();
$css = "/* Edit {$lessFile}, not this file. */" . "\n" . $css;
} catch (\Exception $e) {
ipLog()->error('Less compilation error: Theme - ' . $e->getMessage());
}
return $css;
}
示例6: compile
public static function compile($source, $path, $todir, $importdirs)
{
$parser = new Less_Parser();
$parser->SetImportDirs($importdirs);
$parser->parse($source, CANVASLess::relativePath($todir, dirname($path)) . basename($path));
$output = $parser->getCss();
return $output;
}
示例7: compile
public static function compile($source, $importdirs)
{
$parser = new Less_Parser();
$parser->SetImportDirs($importdirs);
$parser->parse($source);
$output = $parser->getCss();
return $output;
}
示例8: wpless2csssavecss
public function wpless2csssavecss($creds)
{
$plugindir = plugin_dir_path(__FILE__);
if (!class_exists('Less_Parser')) {
require $plugindir . 'less-php/Less.php';
}
$options = array('compress' => true, 'credits' => $creds);
$parser = new Less_Parser($options);
WP_Filesystem($creds);
global $wp_filesystem;
if (!$wp_filesystem->exists($rootless = trailingslashit($wp_filesystem->wp_themes_dir()) . trailingslashit(get_stylesheet()) . 'wpless2css/wpless2css.less')) {
if (!$wp_filesystem->exists($rootless = trailingslashit($wp_filesystem->wp_themes_dir()) . trailingslashit(get_template()) . 'wpless2css/wpless2css.less')) {
if (!$wp_filesystem->exists($rootless = trailingslashit($wp_filesystem->wp_content_dir()) . 'wpless2css/wpless2css.less')) {
wp_die(__('<strong>wpless2css/wpless2css.less</strong> is missing', 'wpless2css'));
}
}
}
$parser->parseFile($rootless, '../');
$parser->parse(apply_filters('get_theme_mods', ''));
if ($extrafiles = apply_filters('add_extra_less_files', '')) {
foreach ($extrafiles as $extrafile) {
$parser->parseFile(trailingslashit(str_replace('wp-content/', '', $wp_filesystem->wp_content_dir())) . $extrafile);
}
}
$parser->parse(apply_filters('add_extra_less_code', ''));
$parser->parse(get_theme_mod('customlesscode'));
$css = $parser->getCss();
if (is_rtl()) {
$css = str_replace('navbar-left', 'navbar-l', $css);
$css = str_replace('navbar-right', 'navbar-r', $css);
$css = str_replace('left', 'wasleft', $css);
$css = str_replace('right', 'left', $css);
$css = str_replace('wasleft', 'right', $css);
$css = str_replace('navbar-l', 'navbar-left', $css);
$css = str_replace('navbar-r', 'navbar-right', $css);
$css .= ' body{direction: rtl; unicode-bidi: embed;}';
set_theme_mod('rtl_compiled', 1);
} else {
set_theme_mod('rtl_compiled', 0);
}
$folder = trailingslashit($wp_filesystem->wp_themes_dir()) . trailingslashit(get_stylesheet()) . '/';
if (!$wp_filesystem->put_contents($folder . $this->filename, $css, FS_CHMOD_FILE)) {
wp_die("error saving file!");
}
//file_put_contents( $this->folder.$this->filename, $css);
}
示例9: compile
/**
* Convert LESS to CSS
* @param string $string
* @return string
*/
public static function compile($string)
{
self::init();
$parser = new \Less_Parser();
$parser->SetOptions(['compress' => !Debugger::isEnabled()]);
$parser->parse($string);
return $parser->getCss();
}
示例10: alleycat_compiler
function alleycat_compiler()
{
$minimize_css = shoestrap_getVariable('minimize_css', true);
$options = $minimize_css == 1 ? array('compress' => true) : array('compress' => false);
$bootstrap_location = get_template_directory() . '/assets/less/';
$bootstrap_uri = '';
try {
$parser = new Less_Parser($options);
// AC LESS file
$parser->parseFile($bootstrap_location . 'alleycat.less', $bootstrap_uri);
// Our custom variables
$parser->parse(shoestrap_variables());
// Add a filter to the compiler
$parser->parse(apply_filters('shoestrap_compiler', ''));
$css = $parser->getCss();
} catch (Exception $e) {
$error_message = $e->getMessage();
error_log($error_message);
}
// Below is just an ugly hack
$css = str_replace('bootstrap/fonts/', '', $css);
$css = str_replace(get_template_directory_uri() . '/assets/', '../', $css);
return apply_filters('shoestrap_compiler_output', $css);
}
示例11: processSubmit
function processSubmit($mode)
{
$data = get_option('Lesser_APF');
$less = $data['lesser_' . $mode . '_less'];
$parser = new Less_Parser();
try {
$parser->parse($less);
$css = $parser->getCss();
$data['lesser_' . $mode . '_css'] = $css;
$data = apply_filters('lesser_before_' . $mode . '_save', $data);
update_option('Lesser_APF', $data);
} catch (Exception $e) {
$this->setSettingNotice('LESS parse error: ' . $e->getMessage());
}
}
示例12: parse_string
public function parse_string($template, $data = array(), $return = FALSE, $config = array())
{
if (!is_array($config)) {
$config = array();
}
$config = array_merge($this->config, $config);
$ci = $this->ci;
$is_mx = false;
if (!$return) {
list($ci, $is_mx) = $this->detect_mx();
}
$parser = new Less_Parser($config);
$parser->parse($template);
$template = $parser->getCss();
return $this->output($template, $return, $ci, $is_mx);
}
示例13: read
public function read()
{
parent::read();
if (!$this->is_cached()) {
if (class_exists('\\Less_Parser')) {
$parser = new \Less_Parser();
$parser->SetOptions(array('compress' => $this->minify));
try {
$parser->parse($this->content);
} catch (\Exception $e) {
throw new \System\Error\Format(sprintf('Error while parsing LESS styles: %s', $e->getMessage()));
}
$this->content = $parser->getCss();
} else {
throw new \System\Error\MissingDependency('Missing less parser. Please install oyejorge/less.php');
}
}
}
示例14: less
/**
* less compiler
* @link https://github.com/oyejorge/less.php
*
* @param string $file
* @return string
*/
protected function less($file)
{
if (!class_exists('\\Less_Parser')) {
return Result::errorMissingPackage($this, 'Less_Parser', 'oyejorge/less.php');
}
$lessCode = file_get_contents($file);
$parser = new \Less_Parser();
$parser->SetOptions($this->compilerOptions);
if (isset($this->compilerOptions['importDirs'])) {
$importDirs = [];
foreach ($this->compilerOptions['importDirs'] as $dir) {
$importDirs[$dir] = $dir;
}
$parser->SetImportDirs($importDirs);
}
$parser->parse($lessCode);
return $parser->getCss();
}
示例15: bootswatch_css
/**
* Adds inline CSS in header.
*/
function bootswatch_css()
{
$css = '';
/**
* Fix overlapping with WordPress admin bar.
*/
$css .= 'body.admin-bar .navbar-fixed-top{ top: 32px; }';
/**
* Fix overlapping with Bootstrap's fixed navbar.
*/
if (bootswatch_use('fixed_navbar')) {
$variables_path = bootswatch_get_option('theme') ? get_template_directory() . '/vendor/thomaspark/bootswatch/' . bootswatch_get_option('theme') . '/variables.less' : get_template_directory() . '/vendor/thomaspark/bootswatch/bower_components/bootstrap/less/variables.less';
$less_parser = new Less_Parser();
$less_parser->parseFile($variables_path, home_url());
$less_parser->parse('body { padding-top: (@navbar-height + @navbar-margin-bottom); }');
$css .= $less_parser->getCss();
}
printf('<style>%s</style>', $css);
// WPCS: xss ok.
}