Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Commit

Permalink
Changing things to work with the new less plugin
Browse files Browse the repository at this point in the history
closes #1
  • Loading branch information
elboletaire committed Jan 12, 2015
1 parent 5187c83 commit 20b639e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 354 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
"license": "Apache-2.0",
"require": {
"php": ">=5.4.19",
"composer/installers": "*",
"oyejorge/less.php": "1.7.0.2"
"cakephp/plugin-installer": "*",
"elboletaire/less-cake-plugin": "*"
},
"extra": {
"installer-name": "Bootstrap"
"installer-name": "Bootstrap"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 4 additions & 0 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
use Cake\Core\Plugin;

Plugin::load('Less');
104 changes: 10 additions & 94 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ the latest `master HEAD` version.
After adding the plugin remember to load it in your `config/bootstrap.php` file:

```php
Plugin::load('Bootstrap');
Plugin::load('Bootstrap', ['bootstrap' => true]);
```

If, for any reason, the `psr-4` addition to the `composer.json` file does not
work, try setting `autoload` to `true` when loading the plugin:

```php
Plugin::load('Bootstrap', ['autoload' => true]);
Plugin::load('Bootstrap', ['autoload' => true, 'bootstrap' => true]);
```

### Configuration
Expand All @@ -61,7 +61,7 @@ After adding the plugin you can add the desired utilities:
```php
// AppController.php
public $helpers = [
'Bootstrap.Less',
'Less.Less', // required for parsing less files
'Bootstrap.Form'
];

Expand Down Expand Up @@ -136,13 +136,13 @@ Create a `styles.less` file on your `webroot/less` folder (also create
that folder if it does not exist) containing this line:

```less
@import '/bootstrap/less/bootstrap.less';
@import '../bootstrap/less/bootstrap.less';
```

Finally, load the less file from your view or layout:

```php
echo $this->Less->less('styles.less');
echo $this->Less->less('less/styles.less');
```

If you want to extend twitter bootstrap styles I recommend you to copy both
Expand Down Expand Up @@ -171,95 +171,11 @@ $this->Flash->danger('Fatal error', ['params' => ['close' => false]]);

### LessHelper

Used on your template or view to load the compressed CSS.

By default it will compress files using the php parser with cache enabled.
This will fill your `css` folder with a bunch of files starting with `lessphp_`
used for the cache. I recommend you adding these files to your `.gitignore` file
in order to prevent commiting them:

lessphp_*

Basically, you give the helper a less file to be loaded (from `/less` directory)
and it returns the html link tag to the compiled CSS:

```php
echo $this->Less->less('less/styles.less');
// will result in something like...
<link rel="stylesheet" href="/css/lessphp_8e07b9484a24787e27f9d71522ba53443d18bbd2.css" />
```

You can compile multiple files if you pass an array:

```php
echo $this->Less->less(['less/myreset.less', 'less/styles.less']);
// They will be compiled in the same file, so the result will be the same as the previous one
<link rel="stylesheet" href="/css/lessphp_e0ce907005730c33ca6ae810d15f57a4df76d330.css"/>
```

And you can pass any option to both lessjs and less.php parsers:

```php
echo $this->Less->less('less/styles.less', [
'js' => [
// options for lessjs (will be converted to a json object)
],
'parser' => [
// options for less.php parser
],
// The helper also has its own options
]);
```
Used on your template or view to parse and load the compressed CSS.

If you want to use the less.js parser directly, instead of a fallback, or you
want to use the
[#!watch](http://lesscss.org/usage/#using-less-in-the-browser-watch-mode) method,
you can do it so by setting the js parser to development:

```php
echo $this->Less->less('less/styles.less', ['js' => ['env' => 'development']]);
```

This will output all the links to the less files and the needed js files to
parse the content only using the less.js parser.

#### LessHelper Options

Beside the options for
[lessjs](http://lesscss.org/#client-side-usage-browser-options) and
[less.php](https://github.com/oyejorge/less.php#lessphp) parsers you can set
three options to the helper:

+ `cache`: default's to true. If disabled, the output will be raw CSS wrapped
with `<style>` tags.
+ `tag`: default's to true. Whether or not return the code with its proper tag
(with cache enabled will be a link tag, whilst without cache will be a style
tag).
+ `less`: default's to `/bootstrap/js/less.min`. You can use this var to set a
custom lessjs file.

```php
// Get the link to the resulting file after compressing
$css_link = $this->Less->less('less/styles.less', [
'tag' => false
]);

// Get the compiled CSS (raw)
$compiled_css = $this->Less->less('less/styles.less', [
'cache' => false,
'tag' => false
]);
```

As a default setting of the LessHelper, all the CSS generated by the less.php
parser is compresed. To override this set `compress` to `false` in the less.php
parser options:

```php
echo $this->Less->less('less/styles.less', [
'parser' => ['compress' => false]
]);
```
The LessHelper is part of the
[less cakephp plugin](https://github.com/elboletaire/less-cakephp). Check out
all its details there.

### FormHelper

Expand Down Expand Up @@ -289,7 +205,7 @@ Dependencies
License
-------

Copyright 2013-2014 Òscar Casajuana (a.k.a. elboletaire)
Copyright 2013-2015 Òscar Casajuana (a.k.a. elboletaire)

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 20b639e

Please sign in to comment.