Skip to content

Bridge to leafo's lessphp Compiler, which just returns the compiled and, if so, already cached CSS for HTML-Inclusion — mirrored from Bitbucket.

Notifications You must be signed in to change notification settings

sotastudio/PhpLessDemandBridge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP LESS Demand Bridge

What does it do and what is it good for?

Good question. Did you already know the lessphp project? It is all about lessphp and it depends on it, of course. Many of us don't want to care about LESS compilation - we just want to use it!

This project gives you the ability to get your compiled stylesheet based on LESS source files - on demand. If the LESS stuff already has been compiled, the Demand Bridge will pass through a cached version of it. Of course, this Bridge will also detect changes you may have recently made and compiles your LESS code again.

For this reason, it is simply called "Demand Bridge".

How to use it?

Clone/download this archive into your project

git clone [email protected]:andyhausmann/PhpLessDemandBridge.git

Clone/download lessphp into the lib folder

giit clone git://github.com/leafo/lessphp.git

Move the package contents to the desired directory in your project. You can put it, for example, in a css/engine/ directory to use the bridge through a simple HTML link-tag

<link rel="stylesheet" type="text/css" media="all"  href="css/engine/css.php?file=bootstrap.less" />

I give you a little example of a project structure and how to implement and configure the Demand Bridge:

/project root/
	public directory/
		css/
			engine/
				cache/
				lib/
				css.php
			bootstrap.less
			forms.less (imported by bootstrap.less)
			mixins.less (imported by bootstrap.less)
			patterns.less (imported by bootstrap.less)
			variables.less (imported by bootstrap.less)

To use it properly, you have to adjust the config file (config.php) depending to your needs and file storage. There are two important settings in the config file.

The LESS root file difinition is needed in every case. The whole Demand Bridge bases on it.

// LESS root file
// String: path/to/file.less, relative to css.php - can be overridden via GET var
'lessFile'		=> '../bootstrap.less',

The CSS compile dir is only needed when you want to compile - if not, just ignore it.

// Stylesheet compiling dir
// String: path/to/dir/ to put the compiled CSS in, relative to css.php
'compilePath' 	=> '../',

New: By activating the RecursiveChangeDetection, all files, imported by the LESS Bootstrap, will be checked for changes - if there are any, the Recompilier will be kicked.

// Boolean: Be aware of performance loss when activating!
'recursiveChangeDetection' => 1,

Caching system

Oh yeah, it's really the coolest feature. The Bridge's caching works on both sides: the server's and the client's.

If you're using it for the first time, the Bridge will compile everything through lessphp and saves the result as a cache file. Additional to the afterwards delivered css, the Bridge tells your Browser to cache it client-side which is being realized by some cache headers you can manipulate in the config file.

Changes detection

Of course, the Bridge will also detect recently made changes at LESS stuff. The next time anybody requests the css, the Bridge recompiles it and caches everything again.

Something's not clear enough? Wanna help me improving this app?

Please help me improving the quick start guide and code. It is not possible to consider every case of usage, to avoid bugs and so forth.

This project has the ability to get much stronger and faster - but only with your hints and reported bugs. Don't hesitate!

About

Bridge to leafo's lessphp Compiler, which just returns the compiled and, if so, already cached CSS for HTML-Inclusion — mirrored from Bitbucket.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages