Skip to content

Commit b7d969c

Browse files
authored
Merge pull request #194 from ConnectThink/master-1.5.2
Bump to version 1.5.2 of scssPHP
2 parents 39aa5fe + 59eb3ee commit b7d969c

48 files changed

Lines changed: 4627 additions & 1617 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

class/class-wp-scss.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,28 @@
55
use ScssPhp\ScssPhp\Compiler;
66

77
class Wp_Scss {
8-
/**
9-
* Compiling preferences properites
10-
*
11-
* @var string
12-
* @access private
13-
*/
14-
private $scss_dir, $css_dir, $compile_method, $scssc, $compile_errors, $sourcemaps, $cache;
158

169
/**
1710
* Set values for Wp_Scss::properties
1811
*
1912
* @param string scss_dir - path to source directory for scss files
2013
* @param string css_dir - path to output directory for css files
21-
* @param string method - type of compile (compressed, expanded, etc)
14+
* @param string compile_method - type of compile (compressed or expanded)
2215
*
2316
* @var object scssc - instantiate the compiling object.
2417
*
2518
* @var array compile_errors - catches errors from compile
2619
*/
2720
public function __construct ($scss_dir, $css_dir, $compile_method, $sourcemaps) {
28-
21+
2922
$this->scss_dir = $scss_dir;
3023
$this->css_dir = $css_dir;
31-
$this->compile_method = $compile_method;
3224
$this->compile_errors = array();
3325
$this->scssc = new Compiler();
3426

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

37-
$this->scssc->setFormatter( $compile_method );
29+
$this->scssc->setOutputStyle( $compile_method );
3830
$this->scssc->setImportPaths( $this->scss_dir );
3931

4032
$this->sourcemaps = $sourcemaps;
@@ -89,7 +81,7 @@ public function get_compile_errors() {
8981
* @access public
9082
*/
9183
public function compile() {
92-
84+
9385
$input_files = array();
9486

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

108-
$this->compiler($input, $output, $this);
100+
$this->compiler($input, $output);
109101
}
110102

111103
if (count($this->compile_errors) < 1) {
@@ -141,38 +133,39 @@ public function compile() {
141133
* Puts error in 'compile_errors' property
142134
* @access public
143135
*/
144-
private function compiler($in, $out, $instance) {
136+
private function compiler($in, $out) {
145137

146138
if (!file_exists($this->cache)) {
147139
mkdir($this->cache, 0644);
148140
}
149141
if (is_writable($this->cache)) {
150142
try {
151143
$map = basename($out) . '.map';
152-
$this->scssc->setSourceMap(constant('ScssPhp\ScssPhp\Compiler::' . $instance->sourcemaps));
144+
$this->scssc->setSourceMap(constant('ScssPhp\ScssPhp\Compiler::' . $this->sourcemaps));
153145
$this->scssc->setSourceMapOptions(array(
154-
'sourceMapWriteTo' => $instance->css_dir . $map, // absolute path to a file to write the map to
146+
'sourceMapWriteTo' => $this->css_dir . $map, // absolute path to a file to write the map to
155147
'sourceMapURL' => $map, // url of the map
156148
'sourceMapBasepath' => rtrim(ABSPATH, '/'), // base path for filename normalization
157149
'sourceRoot' => home_url('/'), // This value is prepended to the individual entries in the 'source' field.
158150
));
159151

160-
$css = $this->scssc->compile(file_get_contents($in), $in);
152+
$compilationResult = $this->scssc->compileString(file_get_contents($in), $in);
153+
$css = $compilationResult->getCss();
161154

162155
file_put_contents($this->cache . basename($out), $css);
163156
} catch (Exception $e) {
164157
$errors = array (
165158
'file' => basename($in),
166159
'message' => $e->getMessage(),
167160
);
168-
array_push($instance->compile_errors, $errors);
161+
array_push($this->compile_errors, $errors);
169162
}
170163
} else {
171164
$errors = array (
172165
'file' => $this->cache,
173166
'message' => "File Permission Error, permission denied. Please make the cache directory writable."
174167
);
175-
array_push($instance->compile_errors, $errors);
168+
array_push($this->compile_errors, $errors);
176169
}
177170
}
178171

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

284277
public function set_variables(array $variables) {
285278

286-
$this->scssc->setVariables($variables);
279+
$this->scssc->addVariables(array_map('ScssPhp\ScssPhp\ValueConverter::parseValue', $variables));
287280
}
288281
} // End Wp_Scss Class

options.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
2-
class Wp_Scss_Settings
3-
{
2+
3+
use ScssPhp\ScssPhp\OutputStyle;
4+
5+
class Wp_Scss_Settings {
46
/**
57
* Holds the values to be used in the fields callbacks
68
*/
@@ -9,17 +11,15 @@ class Wp_Scss_Settings
911
/**
1012
* Start up
1113
*/
12-
public function __construct()
13-
{
14+
public function __construct() {
1415
add_action( 'admin_menu', array( $this, 'add_plugin_page' ) );
1516
add_action( 'admin_init', array( $this, 'page_init' ) );
1617
}
1718

1819
/**
1920
* Add options page
2021
*/
21-
public function add_plugin_page()
22-
{
22+
public function add_plugin_page() {
2323
// This page will be under "Settings"
2424
add_options_page(
2525
'Settings Admin',
@@ -33,8 +33,7 @@ public function add_plugin_page()
3333
/**
3434
* Options page callback
3535
*/
36-
public function create_admin_page()
37-
{
36+
public function create_admin_page() {
3837
// Set class property
3938
$this->options = get_option( 'wpscss_options' );
4039
?>
@@ -62,8 +61,7 @@ public function create_admin_page()
6261
/**
6362
* Register and add settings
6463
*/
65-
public function page_init()
66-
{
64+
public function page_init() {
6765
register_setting(
6866
'wpscss_options_group', // Option group
6967
'wpscss_options', // Option name
@@ -137,12 +135,8 @@ public function page_init()
137135
'name' => 'compiling_options',
138136
'type' => apply_filters( 'wp_scss_compiling_modes',
139137
array(
140-
'ScssPhp\ScssPhp\Formatter\Expanded' => 'Expanded',
141-
'ScssPhp\ScssPhp\Formatter\Nested' => 'Nested',
142-
'ScssPhp\ScssPhp\Formatter\Compressed' => 'Compressed',
143-
'ScssPhp\ScssPhp\Formatter\Compact' => 'Compact',
144-
'ScssPhp\ScssPhp\Formatter\Crunched' => 'Crunched',
145-
'ScssPhp\ScssPhp\Formatter\Debug' => 'Debug'
138+
OutputStyle::COMPRESSED => ucfirst(OutputStyle::COMPRESSED),
139+
OutputStyle::EXPANDED => ucfirst(OutputStyle::EXPANDED),
146140
)
147141
)
148142
)

readme.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ Ideally you should setup a scss folder and a css folder within your theme. This
2424

2525
#### Compiling Mode
2626

27-
Compiling comes in five modes:
27+
Compiling comes in two modes:
2828

29+
- Compressed - More compressed css. Entire rule block on one line. No indentation.
2930
- Expanded - Full open css. One line per property. Brackets close on their own line.
31+
32+
**Removed** compiling modes
33+
3034
- Nested - Lightly compressed css. Brackets close with css block. Indents to match scss nesting.
31-
- Compressed - More compressed css. Entire rule block on one line. No indentation.
3235
- Compact - Removes all line breaks, unnecessary whitespace, and single-line comments.
3336
- Crunched - Same as Compressed, but also removes multi-line comments.
3437

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

105108
## Changelog
106109

110+
- 2.3.0
111+
- Update src to use [ScssPHP github repo at 1.5.2](https://github.com/scssphp/scssphp/releases/tag/1.5.2)
112+
- Update deprecated setFormatter to setOutputStyle and provide db migration [shadoath](https://github.com/ConnectThink/WP-SCSS/pull/195)
107113
- 2.2.0
108114
- Updates to allow compile() from outside the plugin [niaccurshi](https://github.com/ConnectThink/WP-SCSS/pull/190)
109115
- Update src to use [ScssPHP github repo at 1.2.1](https://github.com/scssphp/scssphp/releases/tag/1.2.1)

readme.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Plugin URI: https://github.com/ConnectThink/WP-SCSS
55
Requires at least: 3.0.1
66
Tested up to: 5.7.1
77
Requires PHP: 5.6
8-
Stable tag: 2.2.0
8+
Stable tag: 2.3.0
99
License: GPLv3 or later
1010
License URI: http://www.gnu.org/copyleft/gpl.html
1111

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

6262
This plugin will only work with .scss format.
6363

64-
64+
6565
= It's not updating my css, what's happening? =
6666

6767
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).
@@ -76,10 +76,14 @@ If you are having issues with the plugin, create an issue on [github](https://gi
7676

7777
== Changelog ==
7878

79+
= 2.3.0 =
80+
- Update src to use [ScssPHP github repo at 1.5.2](https://github.com/scssphp/scssphp/releases/tag/1.5.2)
81+
- Update deprecated setFormatter to setOutputStyle and provide db migration [shadoath](https://github.com/ConnectThink/WP-SCSS/pull/195)
82+
7983
= 2.2.0 =
8084
- Updates to allow compile() from outside the plugin [niaccurshi](https://github.com/ConnectThink/WP-SCSS/pull/190)
8185
- Update src to use [ScssPHP github repo at 1.2.1](https://github.com/scssphp/scssphp/releases/tag/1.2.1)
82-
86+
8387
= 2.1.6 =
8488
- 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)
8589
- Allow setting Base Directory to Parent theme folder. [Shadoath](https://github.com/ConnectThink/WP-SCSS/issues/178)

scssphp/LICENSE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2015 Leaf Corcoran, http://scssphp.github.io/scssphp
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

scssphp/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# scssphp
2+
### <https://scssphp.github.io/scssphp>
3+
4+
![Build](https://github.com/scssphp/scssphp/workflows/CI/badge.svg)
5+
[![License](https://poser.pugx.org/scssphp/scssphp/license)](https://packagist.org/packages/scssphp/scssphp)
6+
7+
`scssphp` is a compiler for SCSS written in PHP.
8+
9+
Checkout the homepage, <https://scssphp.github.io/scssphp>, for directions on how to use.
10+
11+
## Running Tests
12+
13+
`scssphp` uses [PHPUnit](https://github.com/sebastianbergmann/phpunit) for testing.
14+
15+
Run the following command from the root directory to run every test:
16+
17+
vendor/bin/phpunit tests
18+
19+
There are several tests in the `tests/` directory:
20+
21+
* `ApiTest.php` contains various unit tests that test the PHP interface.
22+
* `ExceptionTest.php` contains unit tests that test for exceptions thrown by the parser and compiler.
23+
* `FailingTest.php` contains tests reported in Github issues that demonstrate compatibility bugs.
24+
* `InputTest.php` compiles every `.scss` file in the `tests/inputs` directory
25+
then compares to the respective `.css` file in the `tests/outputs` directory.
26+
* `SassSpecTest.php` extracts tests from the `sass/sass-spec` repository.
27+
28+
When changing any of the tests in `tests/inputs`, the tests will most likely
29+
fail because the output has changed. Once you verify that the output is correct
30+
you can run the following command to rebuild all the tests:
31+
32+
BUILD=1 vendor/bin/phpunit tests
33+
34+
This will compile all the tests, and save results into `tests/outputs`. It also
35+
updates the list of excluded specs from sass-spec.
36+
37+
To enable the full `sass-spec` compatibility tests:
38+
39+
TEST_SASS_SPEC=1 vendor/bin/phpunit tests
40+
41+
## Coding Standard
42+
43+
`scssphp` source conforms to [PSR12](https://www.php-fig.org/psr/psr-12/).
44+
45+
Run the following command from the root directory to check the code for "sniffs".
46+
47+
vendor/bin/phpcs --standard=PSR12 --extensions=php bin src tests *.php
48+
49+
## Static Analysis
50+
51+
`scssphp` uses [phpstan](https://phpstan.org/) for static analysis.
52+
53+
Run the following command from the root directory to analyse the codebase:
54+
55+
make phpstan
56+
57+
As most of the codebase is composed of legacy code which cannot be type-checked
58+
fully, the setup contains a baseline file with all errors we want to ignore. In
59+
particular, we ignore all errors related to not specifying the types inside arrays
60+
when these arrays correspond to the representation of Sass values and Sass AST nodes
61+
in the parser and compiler.
62+
When contributing, the proper process to deal with static analysis is the following:
63+
64+
1. Make your change in the codebase
65+
2. Run `make phpstan`
66+
3. Fix errors reported by phpstan when possible
67+
4. Repeat step 2 and 3 until nothing gets fixed anymore at step 3
68+
5. Run `make phpstan-baseline` to regenerate the phpstan baseline
69+
70+
Additions to the baseline will be reviewed to avoid ignoring errors that should have
71+
been fixed.

0 commit comments

Comments
 (0)