Git Product home page Git Product logo

lessphp's Introduction

lessphp v0.3.9

Build Status

lessphp is a compiler for LESS written in PHP. The documentation is great, so check it out: http://leafo.net/lessphp/docs/.

Here's a quick tutorial:

How to use in your PHP project

The only file required is lessc.inc.php, so copy that to your include directory.

The typical flow of lessphp is to create a new instance of lessc, configure it how you like, then tell it to compile something using one built in compile methods.

The compile method compiles a string of LESS code to CSS.

<?php
require "lessc.inc.php";

$less = new lessc;
echo $less->compile(".block { padding: 3 + 4px }");

The compileFile method reads and compiles a file. It will either return the result or write it to the path specified by an optional second argument.

<?php
echo $less->compileFile("input.less");

The compileChecked method is like compileFile, but it only compiles if the output file doesn't exist or it's older than the input file:

<?php
$less->checkedCompile("input.less", "output.css");

If there any problem compiling your code, an exception is thrown with a helpful message:

<?php
try {
  $less->compile("invalid LESS } {");
} catch (exception $e) {
  echo "fatal error: " . $e->getMessage();
}

The lessc object can be configured through an assortment of instance methods. Some possible configuration options include changing the output format, setting variables from PHP, and controlling the preservation of comments, writing custom functions and much more. It's all described in the documentation.

How to use from the command line

An additional script has been included to use the compiler from the command line. In the simplest invocation, you specify an input file and the compiled css is written to standard out:

$ plessc input.less > output.css

Using the -r flag, you can specify LESS code directly as an argument or, if the argument is left off, from standard in:

$ plessc -r "my less code here"

Finally, by using the -w flag you can watch a specified input file and have it compile as needed to the output file:

$ plessc -w input-file output-file

Errors from watch mode are written to standard out.

The -f flag sets the output formatter. For example, to compress the output run this:

$ plessc -f=compressed myfile.less

For more help, run plessc --help

lessphp's People

Contributors

leafo avatar gerhobbelt avatar simensen avatar nyordanov avatar anhnhan avatar drloboto avatar xdissent avatar everzet avatar andergmartins avatar andrewtch avatar aredridel avatar barryvdh avatar igorw avatar lopo avatar mythril avatar marat-tanalin avatar peterknight avatar pevik avatar robloach avatar siwinski avatar timwolla avatar anqqa avatar quasipickle avatar scribu avatar shnhrrsn avatar

Watchers

James Cloos avatar Rafique 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.