Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Preprocessor script/library for Stylus?

Tags:

css

php

stylus

Is there a parser/library for "css stylus" available for php?

If not please suggest something similar, if not better. Possibly a light weight library that makes your life coding css, easier in php.

Stylus syntax strips away all colons, semicolons, brackets and most parentheses from regular CSS script. The stark simplicity and elegance of it reminds me of Lisp. What's more amazing is that Stylus will also accept regular CSS syntax in the same file, reducing possible friction between multiple contributers.

like image 694
Amanpreet Avatar asked Apr 24 '12 20:04

Amanpreet


4 Answers

I too was looking for a Stylus parser for PHP. After finding none, I created a basic one and put it up on GitHub for others to use / improve upon.

Current Features 3/20/2013:

  • Omit braces
  • Omit colons
  • Omit semi-colons
  • Custom functions
  • Importing other files
  • '&' parent reference
  • Mixins
  • Interpolation
  • Variables
like image 99
Aust Avatar answered Nov 20 '22 05:11

Aust


Bump. It seems that there still isn't an easy to use method of incorporating stylus into php. Here's my workaround (linux only, local development only). It is inspired by my other recent question about FAM.

install incron and stylus, under ubuntu this would be

sudo apt-get install incron
sudo npm install stylus -g

access incron watch table

incrontab -e

and add the following with suitable modifications:

/var/www/css/my.styl IN_MODIFY /usr/local/bin/stylus /var/www/css/my.styl

which basically means recompile my.styl into my.css on file change.

add resulting css to html header

<link href="path/tom/my.css" rel="stylesheet" type="text/css" />

Whenever you save the .styl file, your .css will be recompiled in the background. Skip the styus file in deployment, use the recompiled one.

like image 45
bartekbrak Avatar answered Nov 20 '22 05:11

bartekbrak


No. But there are plenty alternatives that you could look in to, like LESS, Sass, HSS. Maybe there's a PHP parser for one of these.

like image 2
Jonathan Avatar answered Nov 20 '22 05:11

Jonathan


Why not just use the original Node.js implementation?

exec will work just fine, but you should only use it in a development environment.

<?php exec('/path/to/stylus stylesheet.styl'); ?>

In production you should precompile your Stylus for sake of both performance and security.

like image 2
Roshambo Avatar answered Nov 20 '22 06:11

Roshambo