本文整理汇总了PHP中Less_Parser::ModifyVars方法的典型用法代码示例。如果您正苦于以下问题:PHP Less_Parser::ModifyVars方法的具体用法?PHP Less_Parser::ModifyVars怎么用?PHP Less_Parser::ModifyVars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Less_Parser
的用法示例。
在下文中一共展示了Less_Parser::ModifyVars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _initCompiler
/**
* @return \Less_Parser
*/
protected function _initCompiler()
{
if ($this->_compiler) {
return $this->_compiler;
}
$options = array('compress' => false, 'strictUnits' => false, 'strictMath' => false, 'relativeUrls' => true, 'cache_method' => false, 'sourceMap' => false, 'indentation' => ' ');
if ($this->_isDebug()) {
$options['sourceMap'] = true;
$options['sourceMapRootpath'] = $this->_options->get('root_path');
$options['sourceMapBasepath'] = $this->_options->get('root_path');
}
// Create compilier
$this->_compiler = new \Less_Parser($options);
$this->_compiler->Reset();
// Global depends
$mixins = $this->_options->get('autoload');
foreach ($mixins as $mixin) {
$this->_compiler->parseFile($mixin);
}
// Add custom vars
$this->_compiler->ModifyVars((array) $this->_options->get('global_vars', []));
// Set paths
$importPaths = (array) $this->_options->get('import_paths', []);
foreach ($importPaths as $fullPath => $relPath) {
$this->setImportPath($fullPath, $relPath);
}
// Set cutsom functions
$functions = (array) $this->_options->get('functions', [], 'arr');
foreach ($functions as $name => $function) {
$this->_compiler->registerFunction($name, $function);
}
return $this->_compiler;
}
示例2: Compile
public function Compile($less_files, $out_name, $modify_vars = [], $bootstrap_less = "mixins", $mediawiki_less = "mixins")
{
$lessphp = new \Less_Parser($this->cache_dir);
switch ($bootstrap_less) {
case "mixins":
$lessphp->parseFile($this->bootstrap_dir . "/variables.less", "");
$lessphp->parseFile(__DIR__ . "/custom_variables.less", "");
$lessphp->parseFile($this->bootstrap_mixin, $this->bootstrap_mixin_url);
break;
case "full":
$lessphp->SetImportDirs([$this->bootstrap_dir]);
$lessphp->parseFile(__DIR__ . "/bootstrap.less", "");
break;
case "off":
break;
}
switch ($mediawiki_less) {
case "mixins":
$lessphp->parseFile($this->mediawiki_mixin, $this->mediawiki_mixin_url);
break;
case "off":
break;
}
foreach ($less_files as $less => $url) {
$lessphp->parseFile($less, $url);
}
if ($modify_vars) {
$lessphp->ModifyVars($modify_vars);
}
$css = $lessphp->getCss();
file_put_contents($out_name, $css);
}
示例3: makeCSS
/**
* Make a css file compiled from the LESS files collection
*
* @param array $lessFiles LESS files structures array
*
* @return array
*/
public function makeCSS($lessFiles)
{
$file = $this->makeLESSResourcePath($lessFiles);
$path = $this->getCSSResource($lessFiles);
$url = $this->getCSSResourceURL($path);
$data = array('file' => $path, 'media' => 'screen', 'url' => $url);
if ($this->needToCompileLessResource($lessFiles)) {
try {
$originalPath = $this->getCSSResource($lessFiles, true);
if ($path != $originalPath && $this->getLESSResourceHash($lessFiles, true) && $this->getLESSResourceHash($lessFiles, true) == $this->calcLESSResourceHash($lessFiles) && \Includes\Utils\FileManager::isFileReadable($originalPath)) {
$content = \Includes\Utils\FileManager::read($originalPath);
} else {
// Need recreate parser for every parseFile
$this->parser = new \Less_Parser($this->getLessParserOptions());
$this->parser->parseFile($file, '');
$this->parser->ModifyVars($this->getModifiedLESSVars($data));
$content = $this->prepareLESSContent($this->parser->getCss(), $path, $data);
$this->setLESSResourceHash($lessFiles);
}
\Includes\Utils\FileManager::mkdirRecursive(dirname($path));
\Includes\Utils\FileManager::write($path, $content);
} catch (\Exception $e) {
\XLite\Logger::getInstance()->registerException($e);
$data = null;
}
}
return $data;
}
示例4: getFormDynamicStyle
public function getFormDynamicStyle($id)
{
$this->lessParser->parseFile($this->getBaseDir() . '/assets/less/style.less');
$styleSettings = SCFP()->getSettings()->getStyleSettings();
$this->lessParser->ModifyVars(array('id' => $id, 'no_border' => !empty($styleSettings['no_border']) ? $styleSettings['no_border'] : '', 'border_size' => !empty($styleSettings['border_size']) ? $styleSettings['border_size'] : '', 'border_style' => !empty($styleSettings['border_style']) ? $styleSettings['border_style'] : '', 'border_color' => !empty($styleSettings['border_color']) ? $styleSettings['border_color'] : '', 'field_label_text_color' => !empty($styleSettings['field_label_text_color']) ? $styleSettings['field_label_text_color'] : '', 'field_label_marker_text_color' => !empty($styleSettings['field_label_marker_text_color']) ? $styleSettings['field_label_marker_text_color'] : '', 'field_text_color' => !empty($styleSettings['field_text_color']) ? $styleSettings['field_text_color'] : '', 'no_background' => !empty($styleSettings['no_background']) ? $styleSettings['no_background'] : '', 'background_color' => !empty($styleSettings['background_color']) ? $styleSettings['background_color'] : '', 'button_color' => !empty($styleSettings['button_color']) ? $styleSettings['button_color'] : '', 'text_color' => !empty($styleSettings['text_color']) ? $styleSettings['text_color'] : '', 'hover_button_color' => !empty($styleSettings['hover_button_color']) ? $styleSettings['hover_button_color'] : '', 'hover_text_color' => !empty($styleSettings['hover_text_color']) ? $styleSettings['hover_text_color'] : ''));
return '<style type="text/css" >' . $this->lessParser->getCss() . '</style>';
}
示例5: compileFile
public function compileFile($fname, $outFname = null)
{
if (!is_readable($fname)) {
throw new Exception('load error: failed to find ' . $fname);
}
$pi = pathinfo($fname);
$oldImport = $this->importDir;
$this->importDir = (array) $this->importDir;
$this->importDir[] = realpath($pi['dirname']) . '/';
$this->allParsedFiles = array();
$this->addParsedFile($fname);
$parser = new Less_Parser(array('sourceMap' => $this->sourceMap));
$parser->SetImportDirs($this->getImportDirs());
if (count($this->registeredVars)) {
$parser->ModifyVars($this->registeredVars);
}
foreach ($this->libFunctions as $name => $func) {
$parser->registerFunction($name, $func);
}
$parser->parseFile($fname);
$out = $parser->getCss();
$parsed = Less_Parser::AllParsedFiles();
foreach ($parsed as $file) {
$this->addParsedFile($file);
}
$this->importDir = $oldImport;
if ($outFname !== null) {
return file_put_contents($outFname, $out);
}
return $out;
}
示例6: compile
/**
* {@inheritdoc}
*/
public function compile($path, $relativePath)
{
$this->parsedFiles = array();
$parser = new \Less_Parser(array('compress' => true));
if (!empty($this->importDirs)) {
$parser->SetImportDirs($this->importDirs);
}
$parser->parseFile($path);
$parser->ModifyVars($this->variables);
$css = $parser->getCss();
$this->parsedFiles = $parser->allParsedFiles();
return $css;
}
示例7: _getInlineCSS
protected function _getInlineCSS()
{
require_once $this->_sDirPlugins . 'lessphp/Less.php';
$oLessParser = new Less_Parser();
$oConfigBase = new BxBaseConfig();
$oLessParser->ModifyVars($oConfigBase->aLessConfig);
foreach ($this->_aFilesCss as $sFile) {
if (substr($sFile, -5) !== '.less') {
continue;
}
$oLessParser->parseFile($this->_sPathCss . $sFile, $this->_sUrlCss);
}
return $oLessParser->getCss();
}
示例8: css
function css($file, $media = null)
{
/**
* Only initiate automatically if:
* - webiste is in dev mode
* - or a ?flush is called
*/
if (preg_match('/\\.less$/i', $file) || Director::isDev() || isset($_GET['flush'])) {
/* If file is CSS, check if there is a LESS file */
if (preg_match('/\\.css$/i', $file)) {
$less = preg_replace('/\\.css$/i', '.less', $file);
if (is_file(Director::getAbsFile($less))) {
$file = $less;
}
}
/* If less file exists, then check/compile it */
if (preg_match('/\\.less$/i', $file)) {
$out = preg_replace('/\\.less$/i', '.css', $file);
$css_file = Director::getAbsFile($out);
$options = array();
/* Automatically compress if in live mode */
if (Director::isLive()) {
$options['compress'] = true;
}
try {
/* Force recompile & only write to css if updated */
if (isset($_GET['flush']) || !Director::isLive()) {
/* Create instance */
$parser = new Less_Parser($options);
if (!empty(self::$variables)) {
$parser->ModifyVars(self::$variables);
}
/* calculate the LESS file's parent URL */
$css_dir = rtrim(Director::baseURL(), '/') . Director::makeRelative(dirname(Director::getAbsFile($file)) . '/');
$parser->parseFile(Director::getAbsFile($file), $css_dir);
$css = $parser->getCss();
if (!is_file($css_file) || md5_file($css_file) != md5($css)) {
file_put_contents($css_file, $css);
}
}
} catch (Exception $ex) {
trigger_error("Less.php fatal error: " . $ex->getMessage(), E_USER_ERROR);
}
$file = $out;
}
}
/* Return css path */
return parent::css($file, $media);
}
示例9: _initProcessor
/**
* @return Less_Parser
*/
protected function _initProcessor()
{
// lazy load
if (!class_exists('Less_Parser')) {
require_once dirname(__FILE__) . '/class.less.gpeasy.php';
}
$options = array('compress' => true, 'strictUnits' => false, 'strictMath' => false, 'numPrecision' => 4, 'cache_method' => false);
if ($this->_isDebug()) {
$options['compress'] = false;
}
$less = new Less_Parser($options);
// set paths
$less->SetImportDirs(array($this->_tpl->lessFull => $this->_tpl->baseurl));
// add custom vars
$less->ModifyVars(array());
return $less;
}
示例10: gen
/**
* @param string $destFile destination file path relative to server root (if null, parsed result is returned)
* @throws Exception
* @return mixed
*/
public function gen($destFile = null)
{
$fullTargetPath = DEFAULT_PUBDIR . DIRECTORY_SEPARATOR . $destFile;
$fullTargetDirname = dirname($fullTargetPath);
if (!is_dir($fullTargetDirname) && false === mkdir($fullTargetDirname, 0777, true)) {
throw new Exception("STY0005", "{$fullTargetDirname} dir could not be created for file {$destFile}");
}
$parser = new \Less_Parser($this->_options);
if (isset($this->_styleConfig["sty_const"]["less_var"])) {
$parser->ModifyVars($this->_styleConfig["sty_const"]["less_var"]);
}
foreach ($this->_srcFiles as $srcPath) {
$srcFullPath = DEFAULT_PUBDIR . DIRECTORY_SEPARATOR . $srcPath;
$parser->parseFile($srcFullPath);
}
$css = $parser->getCss();
if (false === file_put_contents($fullTargetPath, $css)) {
throw new Exception("STY0005", "{$fullTargetPath} could not be written for file {$destFile}");
}
}
示例11: _initProcessor
/**
* @return Less_Parser
*/
protected function _initProcessor()
{
// lazy load
if (!class_exists('Less_Parser')) {
require_once dirname(__FILE__) . '/class.less.gpeasy.php';
}
$options = array('compress' => 1, 'strictUnits' => 0, 'strictMath' => 0, 'relativeUrls' => 1, 'numPrecision' => 4, 'cache_method' => 0, 'sourceMap' => 0);
if ($this->_isDebug()) {
$options['compress'] = 0;
$options['sourceMap'] = 1;
$options['sourceMapRootpath'] = $this->_tpl->less;
$options['sourceMapBasepath'] = $path = JPath::clean($this->_tpl->lessFull, '/');
}
$less = new Less_Parser($options);
// set paths
$less->SetImportDirs(array($this->_tpl->lessFull => $this->_tpl->less));
// add custom vars
$less->ModifyVars($this->_getCustomVars());
return $less;
}
示例12: compiler
public function compiler()
{
global $ss_settings;
if (isset($ss_settings['minimize_css']) && $ss_settings['minimize_css'] == 1) {
$compress = true;
} else {
$compress = false;
}
$options = array('compress' => $compress);
$bootstrap_location = dirname(__FILE__) . '/assets/less/';
$webfont_location = get_template_directory() . '/assets/fonts/';
$bootstrap_uri = '';
$custom_less_file = get_stylesheet_directory() . '/assets/less/custom.less';
$css = '';
try {
$parser = new Less_Parser($options);
$parser->ModifyVars(array('assets-url' => '"' . STACHESTACK_ASSETS_URL . '"'));
// The main app.less file
$parser->parseFile($bootstrap_location . 'app.less', $bootstrap_uri);
// Include the Elusive Icons
$parser->parseFile($webfont_location . 'elusive-webfont.less', $bootstrap_uri);
// Enable gradients
if ($ss_settings['gradients_toggle'] == 1) {
$parser->parseFile($bootstrap_location . 'gradients.less', $bootstrap_uri);
}
// The custom.less file
if (is_writable($custom_less_file)) {
$parser->parseFile($bootstrap_location . 'custom.less', $bootstrap_uri);
}
// Parse any custom less added by the user
if (isset($ss_settings['user_less']) && !empty($ss_settings['user_less'])) {
$parser->parse($ss_settings['user_less']);
}
// Get the extra variables & imports
$extra_vars = do_action('ss_bootstrap_less_vars');
$parser->parse($extra_vars);
// Add a filter to the compiler
$parser->parse(apply_filters('stachestack_compiler', ''));
$css = $parser->getCss();
} catch (Exception $e) {
$error_message = $e->getMessage();
die($error_message);
}
// Below are just some ugly hacks.
$css = str_replace('../', get_template_directory_uri() . '/assets/', $css);
$css = preg_replace('|https?:\\/\\/([^\\/]+)|i', null, $css);
$css = str_replace('http:', '', $css);
$css = str_replace('https:', '', $css);
return apply_filters('stachestack_compiler_output', $css);
}
示例13: mkdir
/**
* Generate Options CSS
*
* @since penguin 6.0
*/
function penguin_generate_options_css()
{
$options_update_name = Penguin::$THEME_NAME . '_options_update';
//get theme update history
$options_update = get_option($options_update_name);
//get theme version
$theme_old_version = get_option($options_update_name . '-ver');
$theme_data = wp_get_theme();
if ($theme_data->Template != '') {
$theme_data = wp_get_theme($theme_data->Template);
}
if (!$theme_old_version) {
$theme_old_version = $theme_data['Version'];
update_option($options_update_name . '-ver', $theme_data['Version']);
}
/** Define some vars **/
$uploads = wp_upload_dir();
/** Save on different directory if on multisite **/
if (is_multisite()) {
$uploads_dir = $uploads['basedir'] . '/' . Penguin::$THEME_NAME . '/';
} else {
$uploads_dir = $uploads['basedir'] . '/' . Penguin::$THEME_NAME . '/';
}
if (!is_writable($uploads['basedir'])) {
echo 'Your upload can\'t write theme style files.';
return;
}
// Create necessary folders under /uploads
if (!file_exists($uploads_dir)) {
mkdir($uploads_dir, 0755);
}
if (isset($options_update['update'])) {
if ($options_update['update'] == 'yes') {
if (version_compare($theme_data['Version'], $theme_old_version, '>')) {
update_option($options_update_name . '-ver', $theme_data['Version']);
} else {
if (file_exists($uploads_dir . Penguin::$THEME_NAME . '-styles.css')) {
if (class_exists('woocommerce') && file_exists($uploads_dir . Penguin::$THEME_NAME . '-woocommerce.css')) {
return;
} else {
return;
}
}
}
}
$update_data = array('update' => 'yes', 'version' => intval($options_update['version']) + 1);
} else {
$update_data = array('update' => 'yes', 'version' => 0);
}
/** Capture CSS output **/
require_once 'tools/less.php/Less.php';
global $theme_customize_list, $woocommerce_customize_list;
$theme_customize_list = array();
$woocommerce_customize_list = array();
require get_template_directory() . '/customize/customize.php';
//theme
$parser = new Less_Parser();
$parser->parseFile(get_template_directory() . '/css/less/' . Penguin::$THEME_NAME . '.less', get_template_directory() . '/css/');
$parser->ModifyVars($theme_customize_list);
$css = $parser->getCss();
// background custom
ob_start();
require get_template_directory() . '/customize/customize-bg.php';
$css .= ob_get_clean();
/** Write to file **/
WP_Filesystem();
global $wp_filesystem;
if (!$wp_filesystem->put_contents($uploads_dir . Penguin::$THEME_NAME . '-styles.css', $css, 0644)) {
echo 'Write theme css error.';
return;
}
if (class_exists('woocommerce')) {
//woocommerce
$parser = new Less_Parser();
$parser->parseFile(get_template_directory() . '/woocommerce/assets/css/woocommerce.less', get_template_directory() . '/woocommerce/assets/css/');
$parser->ModifyVars($woocommerce_customize_list);
$css = $parser->getCss();
/** Write to file **/
if (!$wp_filesystem->put_contents($uploads_dir . Penguin::$THEME_NAME . '-woocommerce.css', $css, 0644)) {
echo 'Write woocommerce css error.';
return;
}
}
update_option($options_update_name, $update_data);
}
示例14: theme_snap_set_bootswatch
/**
* Add bootswatch CSS
*
* @param string $css The original CSS.
* @param array $variables The bootswatch variables
* @return string
* @see theme_snap_get_bootswatch_variables
*/
function theme_snap_set_bootswatch($css, array $variables)
{
global $CFG;
$tag = '[[setting:snap-user-bootswatch]]';
if (strpos($css, $tag) === false) {
return $css;
// Avoid doing work when tag is not present.
}
require_once __DIR__ . '/lessphp/Less.php';
try {
$parser = new Less_Parser();
$parser->parseFile(__DIR__ . '/less/bootswatch/snap-variables.less', $CFG->wwwroot . '/');
$parser->parseFile(__DIR__ . '/less/bootswatch/snap-user-bootswatch.less', $CFG->wwwroot . '/');
if (!empty($variables)) {
$parser->ModifyVars($variables);
}
$replacement = $parser->getCss();
} catch (Exception $e) {
add_to_log(get_site()->id, 'library', 'bootswatch', '', 'Failed to complile bootswatch: ' . $e->getMessage());
$replacement = '';
// Nothing we can do but remove the tag.
}
return str_replace($tag, $replacement, $css);
}
示例15: setVariables
/**
* Allows to set variables which can be used
* in the compiled less files.
*
* @param array $variables
*/
public function setVariables(array $variables)
{
$this->compiler->ModifyVars($variables);
}