Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use SASS in Dart editor

Anyone have a canned solution for integrating SASS or another CSS preprocessor into the Dart editor? Seems to require a custom build.dart, which I would rather copy than code. Thanks.

like image 356
Jonathan Edwards Avatar asked Dec 16 '13 18:12

Jonathan Edwards


2 Answers

I stumbled upon this a few days ago

Sass integration for pub

like image 110
Günter Zöchbauer Avatar answered Sep 21 '22 16:09

Günter Zöchbauer


Here is a build.dart file with basic support for SASS:

import 'dart:io';

void main(List<String> args) {
  for (String arg in args) {
    if (arg.startsWith('--changed=')) {
      String file = arg.substring('--changed='.length);
      if (file.endsWith('.scss')) {
        var result = Process.runSync('sass',
            [ '--line-numbers', file,
              file.substring(0, file.length - '.scss'.length) + '.css']);
        if (result.exitCode != 0) {
          // report error (SASS seems to only report first error)
          // split error lines
          var lines = result.stderr.split('\n');
          // escape quotes in error message on first line
          var error = lines[0].replaceAll('"', r'\"');
          // extract line number from second line
          var numMatch = new RegExp(r'\d+').firstMatch(lines[1]);
          var lineNum = numMatch == null ? 1 : num.parse(numMatch.group(0));
          // Report error via JSON
          print('[{"method":"error","params":{"file":"$file","line":$lineNum,"message":"$error"}}]');
        }
      }
    }
  }
}
like image 42
Jonathan Edwards Avatar answered Sep 19 '22 16:09

Jonathan Edwards