Skip to content

Commit

Permalink
sass compiler for fields
Browse files Browse the repository at this point in the history
Signed-off-by:KProvance <[email protected]>
  • Loading branch information
kprovance committed Dec 12, 2014
1 parent 2620f64 commit e8d1bf2
Show file tree
Hide file tree
Showing 45 changed files with 6,518 additions and 220 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Redux Framework Changelog

## 3.3.9.16
* Added SASS compiler for fields.

## 3.3.9.16
* Updated: select2 3.5.2

Expand Down
43 changes: 35 additions & 8 deletions ReduxCore/framework.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@

// ThemeCheck checks
require_once( dirname( __FILE__ ) . '/inc/class.redux_themecheck.php' );

require_once( dirname( __FILE__ ) . '/inc/class.redux_sass.php' );

/**
* Main ReduxFramework class
Expand All @@ -68,7 +70,7 @@ class ReduxFramework {
// ATTENTION DEVS
// Please update the build number with each push, no matter how small.
// This will make for easier support when we ask users what version they are using.
public static $_version = '3.3.9.16';
public static $_version = '3.3.9.17';
public static $_dir;
public static $_url;
public static $_upload_dir;
Expand Down Expand Up @@ -171,7 +173,7 @@ public static function init() {
private $hidden_perm_sections = array(); // Hidden sections specified by 'permissions' arg.
public $typography_preview = array();
public $args = array();
public $filesystem = null;
public $filesystem = null;

/**
* Class Constructor. Defines the args for the theme options class
Expand Down Expand Up @@ -422,6 +424,8 @@ public function __construct( $sections = array(), $args = array(), $extra_tabs =
}
}

reduxSassCompiler::init($this);

/**
* Loaded hook
* action 'redux/loaded'
Expand Down Expand Up @@ -544,6 +548,8 @@ private function set_default_args() {
'dev_mode' => true,
'system_info' => false,
'disable_tracking' => false,
'use_sass' => true,
'output_sass' => false,
);
}

Expand Down Expand Up @@ -1775,13 +1781,22 @@ public function _enqueue() {
) )
) {

wp_enqueue_style(
redux_enqueue_style(
'redux-color-picker-css',
self::$_url . 'assets/css/color-picker/color-picker.css',
array( 'wp-color-picker' ),
filemtime( self::$_dir . 'assets/css/color-picker/color-picker.css' ),
'all'
);
ReduxFramework::$_url . 'assets/css/color-picker/color-picker.css',
ReduxFramework::$_dir . 'assets/css/color-picker',
array(),
time(),
false
);

// wp_enqueue_style(
// 'redux-color-picker-css',
// self::$_url . 'assets/css/color-picker/color-picker.css',
// array( 'wp-color-picker' ),
// filemtime( self::$_dir . 'assets/css/color-picker/color-picker.css' ),
// 'all'
// );

wp_enqueue_style( 'color-picker-css' );

Expand Down Expand Up @@ -1903,6 +1918,18 @@ public function _enqueue() {
}
}

if ($this->args['use_sass']) {
reduxSassCompiler::compile_sass();

wp_enqueue_style(
'redux-sass-compile-css',
ReduxFramework::$_upload_url . $this->args['opt_name'] . '-redux.css',
array(),
time(),
'all'
);
}

$this->localize_data['required'] = $this->required;
$this->localize_data['fonts'] = $this->fonts;
$this->localize_data['required_child'] = $this->required_child;
Expand Down
97 changes: 97 additions & 0 deletions ReduxCore/inc/class.redux_sass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?php

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

if (!class_exists('reduxSassCompiler')) {
class reduxSassCompiler {
public static $path = array();
public static $import = array();
public static $parent = null;

public static function init($parent){
self::$parent = $parent;
}

public static function add_path ($path) {
if (!in_array($path, self::$path)) {
array_push(self::$path, $path);
}
}

public static function add_import($import) {
if (!in_array($import, self::$import)) {
array_push (self::$import, $import);
}
}

public static function compile_sass() {
if (!empty(self::$path)) {
require( "scssphp/scss.inc.php" );

$scss = new scssc();

$scss->setImportPaths( self::$path );

if (self::$parent->args['dev_mode']) {
//$scss->setFormatter ( "scss_formatter_compressed" );
}

$new_css = '';
foreach (self::$import as $import) {
$new_css .= $scss->compile( $import );
}

if ($new_css != '') {
if (self::$parent->args['output_sass']) {
echo '<style type="text/css" id="redux_framework">' . $new_css . '</style>';
} else {
Redux_Functions::initWpFilesystem();

global $wp_filesystem;

$css_file = Redux_Helpers::cleanFilePath( ReduxFramework::$_upload_dir . self::$parent->args['opt_name'] . '-redux.css');
$ret_val = $wp_filesystem->put_contents($css_file, $new_css, FS_CHMOD_FILE);
}
}
}
}
}
}

if (!function_exists ( 'redux_enqueue_style')) {
/**
* Enqueues style for SASS comnpile or WP enqueue, depending on 'use_sass' arg.
*
* @since 3.3.9
* @access public
* @param string $handle Name of the stylesheet.
* @param string $css_src Path to the stylesheet from the root directory of WordPress. Example: '/css/mystyle.css'.
* @param string $scss_dir Directory path to SCSS file.
* @param array $deps An array of registered style handles this stylesheet depends on. Default empty array.
* @param string $ver String specifying the stylesheet version number, if it has one. This parameter is used to ensure that the correct version is sent to the client regardless of caching, and so should be included if a version number is available and makes sense for the stylesheet.
* @param string $media Optional. The media for which this stylesheet has been defined. Default 'all'. Accepts 'all', 'aural', 'braille', 'handheld', 'projection', 'print', 'screen', 'tty', or 'tv'.
* @return void
*/
function redux_enqueue_style ($handle, $css_src, $scss_dir, $deps = array(), $ver = '', $media = false){
if (reduxSassCompiler::$parent->args['use_sass']) {
$path_parts = pathinfo($css_src);

$filename = $path_parts['filename'];

//if (Redux_Helpers::isFieldInUse ( reduxSassCompiler::$parent, $filename )) {
reduxSassCompiler::add_path($scss_dir);
reduxSassCompiler::add_import('@import "' . $filename . '.scss"');
//}
} else {
wp_enqueue_style(
$handle,
$src,
$deps,
$ver,
$media
);
}
}
}
Loading

0 comments on commit e8d1bf2

Please sign in to comment.