Skip to content

Commit

Permalink
Merge pull request #194 from ConnectThink/master-1.5.2
Browse files Browse the repository at this point in the history
Bump to version 1.5.2 of scssPHP
  • Loading branch information
shadoath authored Jun 16, 2021
2 parents 39aa5fe + 59eb3ee commit b7d969c
Show file tree
Hide file tree
Showing 48 changed files with 4,627 additions and 1,617 deletions.
33 changes: 13 additions & 20 deletions class/class-wp-scss.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,28 @@
use ScssPhp\ScssPhp\Compiler;

class Wp_Scss {
/**
* Compiling preferences properites
*
* @var string
* @access private
*/
private $scss_dir, $css_dir, $compile_method, $scssc, $compile_errors, $sourcemaps, $cache;

/**
* Set values for Wp_Scss::properties
*
* @param string scss_dir - path to source directory for scss files
* @param string css_dir - path to output directory for css files
* @param string method - type of compile (compressed, expanded, etc)
* @param string compile_method - type of compile (compressed or expanded)
*
* @var object scssc - instantiate the compiling object.
*
* @var array compile_errors - catches errors from compile
*/
public function __construct ($scss_dir, $css_dir, $compile_method, $sourcemaps) {

$this->scss_dir = $scss_dir;
$this->css_dir = $css_dir;
$this->compile_method = $compile_method;
$this->compile_errors = array();
$this->scssc = new Compiler();

$this->cache = WPSCSS_PLUGIN_DIR . '/cache/';

$this->scssc->setFormatter( $compile_method );
$this->scssc->setOutputStyle( $compile_method );
$this->scssc->setImportPaths( $this->scss_dir );

$this->sourcemaps = $sourcemaps;
Expand Down Expand Up @@ -89,7 +81,7 @@ public function get_compile_errors() {
* @access public
*/
public function compile() {

$input_files = array();

// Loop through directory and get .scss file that do not start with '_'
Expand All @@ -105,7 +97,7 @@ public function compile() {
$outputName = preg_replace("/\.[^$]*/", ".css", $scss_file);
$output = $this->css_dir . $outputName;

$this->compiler($input, $output, $this);
$this->compiler($input, $output);
}

if (count($this->compile_errors) < 1) {
Expand Down Expand Up @@ -141,38 +133,39 @@ public function compile() {
* Puts error in 'compile_errors' property
* @access public
*/
private function compiler($in, $out, $instance) {
private function compiler($in, $out) {

if (!file_exists($this->cache)) {
mkdir($this->cache, 0644);
}
if (is_writable($this->cache)) {
try {
$map = basename($out) . '.map';
$this->scssc->setSourceMap(constant('ScssPhp\ScssPhp\Compiler::' . $instance->sourcemaps));
$this->scssc->setSourceMap(constant('ScssPhp\ScssPhp\Compiler::' . $this->sourcemaps));
$this->scssc->setSourceMapOptions(array(
'sourceMapWriteTo' => $instance->css_dir . $map, // absolute path to a file to write the map to
'sourceMapWriteTo' => $this->css_dir . $map, // absolute path to a file to write the map to
'sourceMapURL' => $map, // url of the map
'sourceMapBasepath' => rtrim(ABSPATH, '/'), // base path for filename normalization
'sourceRoot' => home_url('/'), // This value is prepended to the individual entries in the 'source' field.
));

$css = $this->scssc->compile(file_get_contents($in), $in);
$compilationResult = $this->scssc->compileString(file_get_contents($in), $in);
$css = $compilationResult->getCss();

file_put_contents($this->cache . basename($out), $css);
} catch (Exception $e) {
$errors = array (
'file' => basename($in),
'message' => $e->getMessage(),
);
array_push($instance->compile_errors, $errors);
array_push($this->compile_errors, $errors);
}
} else {
$errors = array (
'file' => $this->cache,
'message' => "File Permission Error, permission denied. Please make the cache directory writable."
);
array_push($instance->compile_errors, $errors);
array_push($this->compile_errors, $errors);
}
}

Expand Down Expand Up @@ -283,6 +276,6 @@ public function enqueue_files($base_folder_path, $css_folder) {

public function set_variables(array $variables) {

$this->scssc->setVariables($variables);
$this->scssc->addVariables(array_map('ScssPhp\ScssPhp\ValueConverter::parseValue', $variables));
}
} // End Wp_Scss Class
26 changes: 10 additions & 16 deletions options.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
class Wp_Scss_Settings
{

use ScssPhp\ScssPhp\OutputStyle;

class Wp_Scss_Settings {
/**
* Holds the values to be used in the fields callbacks
*/
Expand All @@ -9,17 +11,15 @@ class Wp_Scss_Settings
/**
* Start up
*/
public function __construct()
{
public function __construct() {
add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
add_action( 'admin_init', array( $this, 'page_init' ) );
}

/**
* Add options page
*/
public function add_plugin_page()
{
public function add_plugin_page() {
// This page will be under "Settings"
add_options_page(
'Settings Admin',
Expand All @@ -33,8 +33,7 @@ public function add_plugin_page()
/**
* Options page callback
*/
public function create_admin_page()
{
public function create_admin_page() {
// Set class property
$this->options = get_option( 'wpscss_options' );
?>
Expand Down Expand Up @@ -62,8 +61,7 @@ public function create_admin_page()
/**
* Register and add settings
*/
public function page_init()
{
public function page_init() {
register_setting(
'wpscss_options_group', // Option group
'wpscss_options', // Option name
Expand Down Expand Up @@ -137,12 +135,8 @@ public function page_init()
'name' => 'compiling_options',
'type' => apply_filters( 'wp_scss_compiling_modes',
array(
'ScssPhp\ScssPhp\Formatter\Expanded' => 'Expanded',
'ScssPhp\ScssPhp\Formatter\Nested' => 'Nested',
'ScssPhp\ScssPhp\Formatter\Compressed' => 'Compressed',
'ScssPhp\ScssPhp\Formatter\Compact' => 'Compact',
'ScssPhp\ScssPhp\Formatter\Crunched' => 'Crunched',
'ScssPhp\ScssPhp\Formatter\Debug' => 'Debug'
OutputStyle::COMPRESSED => ucfirst(OutputStyle::COMPRESSED),
OutputStyle::EXPANDED => ucfirst(OutputStyle::EXPANDED),
)
)
)
Expand Down
10 changes: 8 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ Ideally you should setup a scss folder and a css folder within your theme. This

#### Compiling Mode

Compiling comes in five modes:
Compiling comes in two modes:

- Compressed - More compressed css. Entire rule block on one line. No indentation.
- Expanded - Full open css. One line per property. Brackets close on their own line.

**Removed** compiling modes

- Nested - Lightly compressed css. Brackets close with css block. Indents to match scss nesting.
- Compressed - More compressed css. Entire rule block on one line. No indentation.
- Compact - Removes all line breaks, unnecessary whitespace, and single-line comments.
- Crunched - Same as Compressed, but also removes multi-line comments.

Expand Down Expand Up @@ -104,6 +107,9 @@ This plugin will only work with .scss format.

## Changelog

- 2.3.0
- Update src to use [ScssPHP github repo at 1.5.2](https://github.com/scssphp/scssphp/releases/tag/1.5.2)
- Update deprecated setFormatter to setOutputStyle and provide db migration [shadoath](https://github.com/ConnectThink/WP-SCSS/pull/195)
- 2.2.0
- Updates to allow compile() from outside the plugin [niaccurshi](https://github.com/ConnectThink/WP-SCSS/pull/190)
- Update src to use [ScssPHP github repo at 1.2.1](https://github.com/scssphp/scssphp/releases/tag/1.2.1)
Expand Down
10 changes: 7 additions & 3 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Plugin URI: https://github.com/ConnectThink/WP-SCSS
Requires at least: 3.0.1
Tested up to: 5.7.1
Requires PHP: 5.6
Stable tag: 2.2.0
Stable tag: 2.3.0
License: GPLv3 or later
License URI: http://www.gnu.org/copyleft/gpl.html

Expand Down Expand Up @@ -61,7 +61,7 @@ Alternatively, you can include [Bourbon](https://github.com/thoughtbot/bourbon)

This plugin will only work with .scss format.


= It's not updating my css, what's happening? =

Do you have errors printing to the front end? If not, check your log file in your scss directory. The css will not be updated if there are errors in your sass file(s).
Expand All @@ -76,10 +76,14 @@ If you are having issues with the plugin, create an issue on [github](https://gi

== Changelog ==

= 2.3.0 =
- Update src to use [ScssPHP github repo at 1.5.2](https://github.com/scssphp/scssphp/releases/tag/1.5.2)
- Update deprecated setFormatter to setOutputStyle and provide db migration [shadoath](https://github.com/ConnectThink/WP-SCSS/pull/195)

= 2.2.0 =
- Updates to allow compile() from outside the plugin [niaccurshi](https://github.com/ConnectThink/WP-SCSS/pull/190)
- Update src to use [ScssPHP github repo at 1.2.1](https://github.com/scssphp/scssphp/releases/tag/1.2.1)

= 2.1.6 =
- When enqueueing CSS files Defer to WordPress for URLs instead of trying to guess them. Change by [mmcev106](https://github.com/ConnectThink/WP-SCSS/pull/185)
- Allow setting Base Directory to Parent theme folder. [Shadoath](https://github.com/ConnectThink/WP-SCSS/issues/178)
Expand Down
20 changes: 20 additions & 0 deletions scssphp/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2015 Leaf Corcoran, http://scssphp.github.io/scssphp

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71 changes: 71 additions & 0 deletions scssphp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# scssphp
### <https://scssphp.github.io/scssphp>

![Build](https://github.com/scssphp/scssphp/workflows/CI/badge.svg)
[![License](https://poser.pugx.org/scssphp/scssphp/license)](https://packagist.org/packages/scssphp/scssphp)

`scssphp` is a compiler for SCSS written in PHP.

Checkout the homepage, <https://scssphp.github.io/scssphp>, for directions on how to use.

## Running Tests

`scssphp` uses [PHPUnit](https://github.com/sebastianbergmann/phpunit) for testing.

Run the following command from the root directory to run every test:

vendor/bin/phpunit tests

There are several tests in the `tests/` directory:

* `ApiTest.php` contains various unit tests that test the PHP interface.
* `ExceptionTest.php` contains unit tests that test for exceptions thrown by the parser and compiler.
* `FailingTest.php` contains tests reported in Github issues that demonstrate compatibility bugs.
* `InputTest.php` compiles every `.scss` file in the `tests/inputs` directory
then compares to the respective `.css` file in the `tests/outputs` directory.
* `SassSpecTest.php` extracts tests from the `sass/sass-spec` repository.

When changing any of the tests in `tests/inputs`, the tests will most likely
fail because the output has changed. Once you verify that the output is correct
you can run the following command to rebuild all the tests:

BUILD=1 vendor/bin/phpunit tests

This will compile all the tests, and save results into `tests/outputs`. It also
updates the list of excluded specs from sass-spec.

To enable the full `sass-spec` compatibility tests:

TEST_SASS_SPEC=1 vendor/bin/phpunit tests

## Coding Standard

`scssphp` source conforms to [PSR12](https://www.php-fig.org/psr/psr-12/).

Run the following command from the root directory to check the code for "sniffs".

vendor/bin/phpcs --standard=PSR12 --extensions=php bin src tests *.php

## Static Analysis

`scssphp` uses [phpstan](https://phpstan.org/) for static analysis.

Run the following command from the root directory to analyse the codebase:

make phpstan

As most of the codebase is composed of legacy code which cannot be type-checked
fully, the setup contains a baseline file with all errors we want to ignore. In
particular, we ignore all errors related to not specifying the types inside arrays
when these arrays correspond to the representation of Sass values and Sass AST nodes
in the parser and compiler.
When contributing, the proper process to deal with static analysis is the following:

1. Make your change in the codebase
2. Run `make phpstan`
3. Fix errors reported by phpstan when possible
4. Repeat step 2 and 3 until nothing gets fixed anymore at step 3
5. Run `make phpstan-baseline` to regenerate the phpstan baseline

Additions to the baseline will be reviewed to avoid ignoring errors that should have
been fixed.
Loading

0 comments on commit b7d969c

Please sign in to comment.