PHP Preprocessor script/library for Stylus?
Asked Answered
S

5

5

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.

Scandium answered 24/4, 2012 at 20:26 Comment(4)
I particularly like LESS, but again, it's just another way to write CSS, I don't understand how these helpers fit under the "php parser" category. Do you want to write them in a php file (to have it rendered dynamically) ? Then you don't need to "parse" it, just generate it directly the way you want (regular CSS, stripped-down CSS, or whatever)Malley
And instead of copying "extra useless description" (which resembles SPAM, by the way), you could have added extra useful informations, i.e. what you really need, what you're after, what does the parser need to do (parse an already made css stylus sheet?), etc.Malley
i clearly stated what i really need please read the question carefully and then answer.Scandium
@DamienPirsy he is wanting a PHP script that can parse Stylus code and output normal CSS. As pointed out in the other answer, there are similar tools for LESS and SASS/SCSS. He was simply looking for a preprocessor tool for Stylus that uses PHP. Not sure why you would downvote this or vote to close it.Matronize
S
2

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.

Shing answered 24/4, 2012 at 20:34 Comment(1)
Sass is a nice alternative thanks, but i guess not as good as stylus i think ill have to write a parser from scratch, thanks again thoughScandium
S
8

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
Soapstone answered 14/3, 2013 at 20:39 Comment(0)
W
3

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.

Waterbuck answered 21/10, 2012 at 13:21 Comment(2)
This works as long as the file is static, now say the css is version specific and generated via PHP we have an issue then... also "incron" will handle file system events but with PHP's dynamic content I am not so sure if it would work. Thanks for the tip though, was/is worth looking into.Scandium
Why not just stylus --watch path/to/stylus/file.styl? Stylus has watch functionality built right in.Doti
S
2

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.

Shing answered 24/4, 2012 at 20:34 Comment(1)
Sass is a nice alternative thanks, but i guess not as good as stylus i think ill have to write a parser from scratch, thanks again thoughScandium
D
2

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.

Doti answered 26/3, 2013 at 20:47 Comment(0)
A
0

This doesn't necessarily answer your question, but i think some people could find real value on this. There are implementations of the SCSS (Sass) and Less compilers in PHP:

https://github.com/oyejorge/scssphp

https://github.com/oyejorge/less.php

The Less.js implementation is used in October CMS to compile assets, and it works very well, you don't have to pre-compiled or watch. However, it lacks better error logging.

These could work as a foundation to implement a Stylus PHP compiler, perhaps?

Apologist answered 6/1, 2019 at 16:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.