Giter VIP home page Giter VIP logo

php-sass-1's Introduction

PHP binding for libsass

You don't have to install ruby/Node.JS stack no more.

You need only to install the PHP and Compile .scss and .sass files using PHP.

php-sass provides a PHP interface to libsass, a fairly complete Sass compiler written in C++.

Usage

compile sass string.

<?php

$sass = new Sass();

$str = <<<'SASS'
div { 
    a { 
        color: black
      }
    }
div a {  
    color: black; 
    }
SASS;

$str = $sass->compile($str);
var_dump($str);

compile sass file and returing string.

<?php

$file = 'input.sass';

$sass = new Sass();

$css = $sass->compileFile($file);

var_dump($css);

compile sass file to css file.

<?php

$file = 'input.sass';

$sass = new Sass();

// saved 'css-output-dir/input.css'
$css = $sass->compileFile($file, 'css-output-dir');

var_dump($css);

set style

<?php

$file = 'input.sass';

$sass = new Sass();

$sass->setOutputStyle(Sass::STYLE_COMPRESSED);

// saved 'css-output-dir/input.css'
$css = $sass->compileFile($file, 'css-output-dir');

var_dump($css);

full features example.

<?php

$file = "input/base.scss";

$sass = new Sass();

//$sass->setVerboseLevel(Sass::VERBOSE_LEVEL_TRACE);

// Emit source map to 'map' dir
$sass->setSourceMapPath('map');

// STYLE_COMPRESSED, STYLE_COMPACT,STYLE_EXPANDED, STYLE_NESTED
$sass->setOutputStyle(Sass::STYLE_EXPANDED);

// Emit comments showing original line numbers.
$sass->setSourceComment(true);

// Omits the source map url comment.
$sass->setOmitSourceMapUrl(true);

// Set the precision for numbers.
$sass->setPrecision(5);

// Set Sass import path.
$sass->setLoadPath('include');

// Set path to autoload plugins.
$sass->setPluginPath('plugin');

// saved to 'css/base.css' and 'map/base.css.map'
$css = $sass->compileFile($file, 'css');

var_dump($css);

Installation

install from pre-built binary

  • download latest pre-built binary
  • extract it
tar zxvf php-sass.tar.gz
  • run install script as root.
sudo ./install.sh

build from source

Dependancy

  • gcc/g++ 4.8 or above(libsass requires gcc 4.8)
  • php 5.5 or above
  • php devel package(The package name is different for each distro.)
  • PHP-CPP
  • libsass

installation Pre-Requisite packages.

Ubuntu 16 LTS
sudo apt-get install gcc g++ php7.0-dev
Ubuntu 14 LTS
sudo apt-get install gcc g++ php5-dev
CentOS 7 with Webtatic package
yum install gcc gcc-c++ php70w-cli php70w-devel
Mac OS X

Mac OS X users need install gcc6.

brew install gcc6 --enable-cxx

compile from source

  1. checkout project

    git clone --recurse-submodules https://github.com/lesstif/php-sass
    cd php-sass
  2. build libsass

  3. change directory bash cd libsass

  4. check out stable version.

```bash
git checkout 3.3.6
```
  1. build libsass shared library.
```bash
BUILD="shared" make
```
  1. install libsass shared library to /usr/local/lib.
```bash
sudo BUILD="shared" make install
```
  1. build PHP-CPP

  2. change directory bash cd ../PHP-CPP

  3. Linux User

1. build PHP-CPP for PHP 5.6 or below (need v1.5.3 branch)

  ```bash
  git checkout v1.5.3
  make PHPCPP_15=1
  ```

1. PHP 7.0 or above users just run make.

  ```bash
  make
  ```
  1. Mac OS X User

    1. open the Makefile and change -soname option to -install_name .

    2. add LINKER_FLAGS*-undefined dynamic_lookup*

      LINKER_FLAGS = -shared -undefined dynamic_lookup
    3. run make

      make CXX=g++-6
  2. install PHP-CPP library to /usr/local/lib.

```bash
sudo make install
```
  1. build PHP-CPP (Mac OS X)

  2. appending below line to the shell config file(ex: .profile, .bash_profile) in your home directory; then log out and log in again.

    export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
    
  3. build php-sass module.

  4. change directory

```bash
cd ../
```
  1. build

make
```

if you are using RHEL derived distro, make with custom option.

```bash
make CENTOS=1
```

 if you are using Mac OS X, make with *CXX=g++-6* and *MACOS=1* option.

```bash
make CXX=g++-6
```
  1. install php-sass to PHP modules directory.

    sudo make install

check installation

php -r "phpinfo(INFO_MODULES);"|grep -i sass

Compatibility

  • Tested with below environments.

php-sass-1's People

Contributors

lesstif avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.