2017 © Pedro Peláez
 

silverstripe-module silverstripe-lesscompiler

A simple less compiler that runs on Silverstripe execution

image

i-lateral/silverstripe-lesscompiler

A simple less compiler that runs on Silverstripe execution

  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 5 % Grown

The README.md

Silverstripe Lesscompiler Module

A module that compiles defined less files on execution and exportes them to a defined CSS file., (*1)

Currently this is a proof of concept and has lots of possible options for expansion., (*2)

This module uses the "less.php" module to compile less files. If not installing via composer you will need this installed to your path., (*3)

Installation via Composer

composer require i-lateral/silverstripe-lesscompiler 0.*

Operation

This module checks for updates to defined less files before controller initilisaton. If there are changes then new CSS is compiled and saved to the defined output path., (*4)

This process is only run on dev (as to not detrimentally effect performance on live sites) and all cache files are stored in the default Silverstripe temp directory., (*5)

Basic usage

Start off by setting the file_mappings config variable on LessCompilerConfig. This should be a list of less files to convert with their equivilent export file, eg:, (*6)

config.yml, (*7)

LessCompilerConfig:
  file_mappings:
    "styles.less": "styles.css"
    "typography.less": "typography.css"

_config.php, (*8)

LessCompilerConfig::config()->file_mappings = array(
    "styles.less" => "styles.css",
    "typography.less" => "typography.css"
);

If you do not include a path to the less/css files then the module assumes that you are using the default theme directory and using folders named "less" and "css" respectively., (*9)

Custom file paths

You can define custom less and css file paths but using the following:, (*10)

config.yml LessCompilerConfig: file_mappings: "themes/themename/less/styles.less": "themes/themename/css/styles.css" "themes/themename/less/typography.less": "themes/themename/css/typography.css", (*11)

_config.php, (*12)

LessCompilerConfig::config()->file_mappings = array(
    "themes/themename/less/styles.less" => "themes/themename/css/styles.css",
    "themes/themename/less/typography.less" => "themes/themename/css/typography.css"
);

Compressing output

By default all output is compressed, this can be disabled using the "compress" config variable, EG:, (*13)

config.yml, (*14)

LessCompilerConfig:
  compress: false

_config.php, (*15)

LessCompilerConfig::config()->compress = false;

Relative image URLS

The compiler attempts converts all relative image URLs to be prefixed prefixed with ../ (this assumes that the output css will be in a seperate folder to the images, but with a common root). This can be altered using the "root_path" config variable, (*16)

config.yml, (*17)

LessCompilerConfig:
  root_path: "../../imports"

_config.php, (*18)

LessCompilerConfig::config()->root_path = "../../imports";

Before and After Compile extensions

If you need to perform custom functions just before or after Less Compiler runs you can do this using the onBeforeLessCompiler and onAfterLessCompiler extension calls., (*19)

NOTE These calls are added to controller, so rather than adding an extension to LessCompiler itself, you only need to add your custom code to an extension to Controller. EG:, (*20)

app/code/extensions/AppControllerExtension.php, (*21)

<?php

class AppControllerExtension extends Extension
{    
    public function onBeforeLessCompiler()
    {
        // pre compiler code goes here
    }

    public function onAfterLessCompiler()
    {
        // post compiler code goes here
    }
}

app/_config/config.yml, (*22)

---
Name: app
After: 'framework/*','cms/*'
---
# YAML configuration for SilverStripe
# See http://doc.silverstripe.org/framework/en/topics/configuration
# Caution: Indentation through two spaces, not tabs
SSViewer:
  theme: 'simple'

# Extensions
Controller:
  extensions:
    - AppControllerExtension

The Versions

12/04 2017

dev-master

9999999-dev http://github.com/i-lateral/silverstripe-lesscompiler

A simple less compiler that runs on Silverstripe execution

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe less compiler

12/04 2017

0.2

0.2.0.0 http://github.com/i-lateral/silverstripe-lesscompiler

A simple less compiler that runs on Silverstripe execution

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe less compiler

19/05 2016

0.1

0.1.0.0 http://github.com/i-lateral/silverstripe-lesscompiler

A simple less compiler that runs on Silverstripe execution

  Sources   Download

BSD-3-Clause

The Requires

 

silverstripe less compiler