Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SCSS Plugin
#1
SCSS plugin:

This plugin helps you to use SCSS to write your style sheets instead of CSS.
(see http://leafo.net/scssphp/ for information on the compiler and here for the syntax of SCSS)
The performance impact is minimal, as CSS files are generated when first needed and afterwards served directly to the site user.

Just write a SCSS file (e.g. background.scss here with a parameter color) in your template directory:
Code:
body { background-color: param(color); }
Of course your file will probably be longer and use each parameter multiple times.

Then you can use this file within your template:
  • Either your SCSS file is recompiled every time it or the parameters change, which makes sense, if you want to keep your CSS file untouched and just set the variables in your template file (or from some other site-wide setting):
Code:
<link rel="stylesheet" type="text/css" href="<?php get_scss_css('background.scss', array('color'=>'green')); ?>" />
  • Or you want to set the parameters depending on the page (or time of date, etc.), thus using multiple CSS files generated from one SCSS file at the same time. The following example shows, how to set the background color based on a custom field color in the page (white as default, note the last parameter true):
Code:
<link rel="stylesheet" type="text/css" href="<?php get_scss_css('background.scss', array('color'=>return_custom_field('color', 'white')), true); ?>" />

API:
Code:
function return_scss_css($themeRelativeScssFile, $params=null, $multipleCSS=false)
Compiles a SCSS file to a CSS file, if the SCSS file is newer or the parameters have changed ($multipleCSS = false).
Compiles a SCSS file to a parameter specific CSS file, if the SCSS file is newer ($multipleCSS = true).
The first parameter is the name of the SCSS file, e.g. "default.scss" (if it's directly in the theme directory) or "css/default.scss".
The second parameter is an associative array with the parameters for the SCSS file and the last parameter must be true, if for each parameter set a new CSS file should be compiled and all these CSS files should be available at the same time.
Returns the full URL of the generated CSS file.

Code:
function get_scss_css($themeRelativeScssFile, $params=null, $multipleCSS=false) {
The same as above but outputs the CSS file URL.

For yet another CSS like syntax see the Less plugin.
I18N, I18N Search, I18N Gallery, I18N Special Pages - essential plugins for multi-language sites.
Reply


Messages In This Thread
SCSS Plugin - by mvlcek - 2014-04-05, 01:06:25
RE: SCSS Plugin - by Oleg06 - 2014-04-05, 05:10:49
RE: SCSS Plugin - by ryunp - 2014-07-18, 08:17:37
RE: SCSS Plugin - by pavel9 - 2014-11-03, 05:07:22
RE: SCSS Plugin - by tuxy - 2014-12-04, 08:09:36
RE: SCSS Plugin - by mvlcek - 2014-12-05, 05:25:11
RE: SCSS Plugin - by shawn_a - 2014-12-04, 08:23:33
RE: SCSS Plugin - by tuxy - 2014-12-05, 05:57:59
RE: SCSS Plugin - by cvrglj - 2015-07-12, 02:56:44
RE: SCSS Plugin - by Oleg06 - 2016-06-06, 00:36:22
RE: SCSS Plugin - by Knobbles - 2023-11-25, 22:14:41



Users browsing this thread: 1 Guest(s)