Php scss to css

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

SCSS compiler written in PHP

License

scssphp/scssphp

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

scssphp is a compiler for SCSS written in PHP.

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

scssphp uses PHPUnit for testing.

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

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 

scssphp source conforms to PSR12.

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 

scssphp uses phpstan for static analysis.

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

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.

Источник

scssphp

scssphp is a compiler for SCSS written in PHP.

SCSS is a CSS preprocessor language that adds many features like variables, mixins, imports, nesting, color manipulation, functions, and control directives.

scssphp is ready for inclusion in any project. It includes a command line tool for running the compiler from a terminal/shell or script.

Installing

You can always download the latest version here: scssphp-v1.11.0.tar.gz

You can also find the latest source online: https://github.com/scssphp/scssphp/

If you use Packagist for installing packages, then you can update your composer.json like so:

 "require":  "scssphp/scssphp": "^1.11.0" > > 

Note: git archives of stable versions no longer include the tests/ folder. To install the unit tests, download the complete package source using composer ’s —prefer-source option.

scssphp requires PHP version 5.6 (or above).

Language Reference

For a complete guide to the syntax of SCSS, consult the official documentation.

Note that scssphp is not fully compliant with the Sass specification yet. Sass modules are not implemented yet either.

Command Line Tool

A really basic command line tool is included for integration with scripts. It is called pscss . It reads SCSS from either a named input file or standard in, and returns the CSS to standard out.

Usage: bin/pscss [options] [input-file] [output-file]

Options

If passed the flag -h (or —help ), input is ignored and a summary of the command’s usage is returned.

If passed the flag -v (or —version ), input is ignored and the current version is returned.

The flag -s (or —style ) can be used to set the output style:

$ bin/pscss -s compressed styles.scss 

The flag -I (or —load_path ) can be used to set import paths for the loader. On Unix/Linux systems, the paths are colon separated. On Windows, they are separated by a semi-colon.

SCSSPHP Library Reference

To use the scssphp library either require scss.inc.php or use your composer generated auto-loader, and then invoke the \ScssPhp\ScssPhp\Compiler class:

require_once "scssphp/scss.inc.php"; use ScssPhp\ScssPhp\Compiler; $compiler = new Compiler(); echo $compiler->compileString(' $color: #abc; div < color: lighten($color, 20%); >')->getCss(); 

The compileString method takes the SCSS source code as a string and an optional path of the input file (to resolve relative imports), and returns a CompilationResult value object containing the CSS and some additional data. If there is an error when compiling, a \ScssPhp\ScssPhp\Exception\SassException is thrown with an appropriate message.

Issues

Please submit bug reports and feature requests to the the issue tracker. Pull requests are also welcome.

Any feature request about implementing new language feature will be rejected. They must be submitted to the upstream Sass project instead.

Changelog

For a list of scssphp changes, refer to the changelog.

Источник

scssphp v1.11.0 Documentation

The project can be loaded through the composer generated auto-loader.

Alternatively, the entire project can be loaded through a utility file. Just include it somewhere to start using it:

require_once 'scssphp/scss.inc.php'; 

Compiling

In order to manually compile code from PHP you must create an instance of the Compiler class. The typical flow is to create the instance, set any compile time options, then run the compiler with the compile method.

use ScssPhp\ScssPhp\Compiler; $compiler = new Compiler(); echo $compiler->compileString(' $color: #abc; div < color: lighten($color, 20%); >')->getCss(); 

compileString($scssCode, $path = null) will attempt to compile a string of SCSS code. If it succeeds, a \ScssPhp\ScssPhp\CompilationResult containing the CSS will be returned. If there is any error, a \ScssPhp\ScssPhp\Exception\SassException is thrown with an appropriate error message.

Import Paths

When you import a file using the @import directive, the import is resolved relatively to the current file. The input of compileString is considered to be in the provided path. If no path is provided, relative imports won’t be resolved. Imports paths will need to be used. In case you want to load files from other folders, there are two methods for manipulating the import path: addImportPath , and setImportPaths .

  • addImportPath($path) will append $path to the list of the import paths that are searched.
  • setImportPaths($pathArray) will replace the entire list of import paths with $pathArray . The value of $pathArray will be converted to an array if it isn’t one already.
use ScssPhp\ScssPhp\Compiler; $compiler = new Compiler(); $compiler->setImportPaths('assets/stylesheets/'); // will search for 'assets/stylesheets/mixins.scss' echo $compiler->compileString('@import "mixins.scss";')->getCss(); 

Besides adding static import paths, it’s also possible to add custom import functions.

A list of the included files can be retrieved using the getIncludedFiles method of the CompilationResult . The input file is not included in this list.

Output Formatting

The output formatting can be configured using the setOutputStyle method. 2 styles are provided: \ScssPhp\ScssPhp\OutputStyle::EXPANDED and \ScssPhp\ScssPhp\OutputStyle::COMPRESSED .

/*! Comment */ .navigation  ul  line-height: 20px; color: blue; a  color: red; > > > .footer  .copyright  color: silver; > > 

The output will look like that:

/*! Comment */ .navigation ul  line-height: 20px; color: blue; > .navigation ul a  color: red; > .footer .copyright  color: silver; > 
/* Comment*/.navigation ulline-height:20px;color:blue;>.navigation ul acolor:red;>.footer .copyrightcolor:silver;> 

Source Maps

Source Maps are useful in debugging compiled css files using browser developer tools.

To enable source maps, use the setSourceMap() and setSourceMapOptions() methods.

use ScssPhp\ScssPhp\Compiler; $compiler = new Compiler(); $compiler->setSourceMap(Compiler::SOURCE_MAP_FILE); $compiler->setSourceMapOptions([ // relative or full url to the above .map file 'sourceMapURL' => './my-style.map', // (optional) relative or full url to the .css file 'sourceMapFilename' => 'my-style.css', // partial path (server root) removed (normalized) to create a relative url 'sourceMapBasepath' => '/var/www/vhost', // (optional) prepended to 'source' field entries for relocating source files 'sourceRoot' => '/', ]); $result = $compiler->compileString('@import "sub.scss";'); file_put_contents('/var/www/vhost/my-style.map', $result->getSourceMap()); file_put_contents('/var/www/vhost/my-style.css', $result->getCss()); // use Compiler::SOURCE_MAP_INLINE for inline (comment-based) source maps 

Extending scssphp

The Compiler supports several extension points for advanced usages. They are documented in the documentation about extension points.

Security Considerations

If your web application compiles SCSS on-the-fly, you need to handle any potential exceptions thrown by the Compiler. This is especially important in a production environment where the content may be untrusted (e.g., user uploaded) because the exception stack trace may contain sensitive data.

use ScssPhp\ScssPhp\Compiler; try  $compiler = new Compiler(); echo $compiler->compileString($content)->getCss(); > catch (\Exception $e)  echo ''; syslog(LOG_ERR, 'scssphp: Unable to compile content'); > 

If your web application allows for arbitrary @import paths, you should tighten the open_basedir setting at run-time to mitigate vulnerability to local file inclusion (LFI) attack.

Источник

Читайте также:  Php вывод два знака
Оцените статью