less_dart 0.2.0 copy "less_dart: ^0.2.0" to clipboard
less_dart: ^0.2.0 copied to clipboard

outdatedDart 1 only

Native Dart Less compiler/transformer to build .css files from .less files.

##Native Dart Less compiler/transformer to build .css files from .less files

Less-transformer for pub-serve, pub-build and Less-compiler for pub-run

This is a traslation from less 2.4.0 Javascript (over nodejs) to Dart. Is a pure Dart implementation for the server/developper side.

Use as Compiler or Transformer #

The package is a less compiler with wrappers for use in command line or as a dart transformer. Also, it could be used in other Dart programs.

pub-run usage #

If you get the full distribution (tar.gz file), the bin directory has the lessc.dart for use with pub run:

CMD> pub run lessc [args] file.less file.css

A working example: CMD> pub run lessc test/less/charsets.less

Error output example: CMD> pub run lessc --no-color test/less/errors/import-subfolder1.less

For help: CMD> pub run lessc --help

How to use in other dart programs #

You would need import the package, create the Less class and call the transform future. There is an example:

  import 'dart:io';
  import 'package:less_dart/less.dart';
  
  main() {
    List<String> args = [];
    Less less = new Less();
  
    args.add('-no-color');
    args.add('--strict-math=on');
    args.add('--strict-units=on');
    args.add('less/charsets.less');
    less.transform(args).then((exitCode){
      stderr.write(less.stderr.toString());
      stdout.writeln('\nstdout:');
      stdout.write(less.stdout.toString());
    });
  }

Use as a Dart Transformer with pub-build or pub-serve #

Simply add the following lines to your pubspec.yaml:

dependencies:
  less_dart: any
transformers:
  - less_dart:
  		entry_point: web/builder.less

After adding the transformer your entry_point .less file will be automatically transformed to corresponding .css file.

The power of Dart builder is chain transformers, so a less file will be converted to a css file and this could be the source for a polymer transformer, by example. Considerer to use the less transformer as the first in the chain.

Transformer Configuration

You can also pass options to less_dart if necessary:

transformers:
  - less_dart:
      entry_points: 
      	- path/to/builder.less
      	- or/other.less
      output: /path/to/builded.css
      include_path: /path/to/directory/for/less/includes
      cleancss: true or false
      compress: true or false
      build_mode: less, dart or mixed. (dart by default)
      other_flags:
        - to include in the lessc command line
  • entry_point - Is the ONLY option required. Normally is a builder file with "@import 'filexx.less'; ..." directives.
  • entry_points - Alternative to entry_point. Let process several .less input files.
  • output - Only works with one entry_point file. Is the .css file generated. If not supplied (or several entry_points) then input .less with .css extension changed is used.
  • include_path - see Less Documentation include_path.
  • cleancss - see Less Documentation clean-css.
  • compress - see Less Documentation compress.
  • build_mode -
    • less - command CMD> lessc --flags input.less output.css is used. (output.css is in the same directory as input.less)
      • dart - command CMD> lessc --flags - with stdin and stdout piped in the dart transformer process. See build folder for the css file.
      • mixed - command CMD> lessc --flags input.less with stdout managed by the dart transformer process. See build folder for the css file.
  • other_flags - Let add other flags such as (--source-map, ...) in the lessc command line.

Differences with official (js) version #

  • Javascript evaluation not supported.
    • If this is a problem use less_node
    • Alternatively you can use 'Custom Functions' (see test/custom_functions_test.dart') from your dart program.
  • Added option --banner=bannerfile.txt.

Known issues #

  • Pass the standard tests in windows (no tested in linux).
  • cleanCSS (as plugin) not implemented yet.
  • Error color output. Implemented, but not tested in linux. In windows cmd don't support the color commands.

License #

Copyright (c) 2009-2015 Alexis Sellier & The Core Less Team.

Copyright (c) 2014-2015 Adalberto Lacruz for dart translation.

Licensed under the Apache License.

1
likes
0
pub points
38%
popularity

Publisher

unverified uploader

Native Dart Less compiler/transformer to build .css files from .less files.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

barback, mime, path, source_maps, utf

More

Packages that depend on less_dart