• Stars
    star
    124
  • Rank 288,207 (Top 6 %)
  • Language
    PHP
  • Created over 10 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Compiles SASS to CSS automatically with pure PHP. No ruby used. One line of code. Currently uses latest SCSS 3.2 syntax, imports and mixins. Compass can also be used.

php-sass

Automatic SASS-to-CSS compiling (while being in development, you'll for sure not do this in production). Every time you run your app (hitting index.php for example) php-sass will automatically compile all .scss files in your scss folder to .css files in your css folder. Supports 3.2 version features of SASS (scss syntax) and mixins. Boom! You can also use Compass, but you'll add an older version of Compass's files (as the latest Compass is for SASS 3.3, not 3.2) to your scss folder manually.

Installation & Usage

In your project's composer.json, add these dependencies. If you are not using Composer, then go into the corner and be very very very ashamed of yourself. And then, after standing there for 2-3 hours, watch some tutorials on how to use Composer, it's super-easy and a common minimum-standard in PHP development these days.

Please note that this is a require-dev, not a normal require. This divides real dependencies from ones you only need for local development.

"require-dev": {
    "panique/php-sass": "1.0"
}

Install or update your Composer dependencies to add php-sass by doing composer install or composer update. Composer automatically installs everything in require-dev by default.

IMPORTANT: When you later deploy your application and don't want to install the require-dev stuff, then do composer install --no-dev (or composer update --no-dev).

In your application, add this line into your index.php (or wherever you want to compile SASS to CSS). If you use this inside common frameworks, make sure you add this before the final application call, so in Laravel add it before $app->run(); (some frameworks do stuff like exit(); or caching, so the SASS compiler would never be called).

SassCompiler::run("scss/", "css/");

The first parameter is the relative path to your scss folder (create one) and the second parameter is the relative path to your css folder. Make sure PHP can write into the css folder. For local development, a hardcore sudo chmod -R 777 public/css (when being in /var/www) is totally okay (remember, SASS compiling only happens locally, for production you'll deploy compiled .css files for sure).

To use the very latest features of SASS:

Currently php-sass fetches v0.1.1 (August 2014) of leafo/scssphp as a compiler. For latest features you might want a newer version, so have a look here https://github.com/leafo/scssphp/releases and edit the composer.json accordingly.

[optional] Good way to use it only in development, not on production

To prevent using the SASS compiler in production, use an environment switch. Nearly all framework have something like this (google for "YOURFRAMEWORK environment"). For native usage: In your Apache vhost config, add a SetEnv variable, depending on what the server is (development, testing, production, etc):

<VirtualHost *:80>
    ...
    SetEnv APPLICATION_ENV production
    ...
<VirtualHost/>

and in PHP ask for your environment like this:

if (getenv('APPLICATION_ENV') == 'development') {
    SassCompiler::run("scss/", "css/");
}

Optional features

There's an optional third parameter for SassCompiler::run() that expects one of the strings explained on http://leafo.net/scssphp/docs/#output_formatting. This defines the desired output. scss_formatter is the standard laravel-sass uses, choose scss_formatter_compressed if you need a minimized css file. scss_formatter_nested is for nested output, optimized for readability.

How @import works

The @import of sass rules from other files works perfectly. Make sure to import the files like it should be: If the file is called _colors.scss and is in the basic scss folder:

@import 'colors';

If the file is called _colors.scss and is in the subfolder modules of the basic scss folder:

@import 'modules/colors';

Read the official docs for more.

Used scripts

This tool uses the excellent scssphp SASS compiler. scssphp supports the latest SCSS syntax (3.2.12).

Other projects

License

Licensed under MIT. Totally free for private or commercial projects.

Support

If you think this script is useful, then think about supporting the project by renting your next server at Host1Plus or DigitalOcean. Thanks!

More Repositories

1

huge

Simple user-authentication solution, embedded into a small framework.
PHP
2,142
star
2

mini

Just an extremely simple naked PHP application, useful for small projects and quick prototypes. Some might call it a micro framework :)
PHP
1,342
star
3

php-login-minimal

An extremely minimal login / register script in pure PHP.
PHP
601
star
4

php-long-polling

An extremely simple example of a "real-time" self-updating page using long-polling.
PHP
425
star
5

mini2

Just an extremely simple naked PHP application, useful for small projects and quick prototypes.
PHP
414
star
6

mini3

Just an extremely simple naked PHP application, useful for small projects and quick prototypes.
PHP
273
star
7

php-login-one-file

PHP
219
star
8

vagrant-lamp-bootstrap

A super-simple Vagrantfile / bootstrap.sh to setup a LAMP stack inside Vagrant 100% automatically
Shell
132
star
9

tiny

TINY is an extremely simple naked demo PHP application that runs nearly config-free everywhere.
PHP
80
star
10

laravel-sass

Automatic SASS-to-CSS compiling for Laravel 4 (and any other framework too), config-free, in pure PHP, works with latest SASS 3.2 .scss syntax, imports and mixins
PHP
71
star
11

pdo-debug

Emulates the SQL query constructed by PDO. The magic behind: A simple function that combines your parameters and the raw query. Not perfect, but does the job.
PHP
69
star
12

html5-video

A simple copy&paste solution for crossbrowser-safe HTML5 video with a flash fallback. 100% free and open-source. Works on all browsers. All.
HTML
58
star
13

php-login-styles

THIS PROJECT IS DEPRECATED AND HAS REACHED END OF LIFE
44
star
14

php-sass-watcher

One simple PHP file that "watches" your SASS file folder and compiles all .scss automatically every X seconds. Sounds weird, but works perfectly. Automatic SASS compiling with 100% PHP. No Ruby used.
PHP
28
star
15

simple-php-api

An extremely simple API (with authentication) example, written in PHP (server) and JS (client), using JSON
PHP
24
star
16

phpstorm-theme-github-remixed

Get GitHub's syntax highlighting / colours and fonts within PHPStorm
19
star
17

simple-php-api-client

A PHP client for using a JSON based API
Shell
13
star
18

phpstorm-theme-github-remixed-2

Get GitHub's 2014 style syntax highlighting (colours and fonts) within PHPStorm
13
star
19

php-logo

This repo tries to professionalize the current PHP logo, offering versions that fit print / web / broadcast standards, containing vector-, pixel- and css-based versions.
11
star