Code Monkey home page Code Monkey logo

dart-stylus's Introduction

Dart Stylus Compiler

Build Status

Stylus compiler wrapper for Dart.

Install

Just add to your pubspec.yaml:

dependencies:
  stylus: any

You also gonna need to have stylus command into your path. To install stylus, run (you must have Node and NPM installed before):

npm install -g stylus

Usage

Use StylusProcess to compile Stylus code into CSS, the easiest way to call is by using the [start] method:

import 'package:stylus/stylus.dart';

StylusProcess.start(new StylusOptions(path: 'file.styl')).pipe(new File('output.css').openWrite());

As you can see, the [start] returns a [Stream] that you can use to pipe strait on the result.

You can also compile from a [String]:

import 'dart:convert';
import 'package:stylus/stylus.dart';

var input = '''
  body
    .class
      .internal
        color: blue
''';

StylusProcess.start(new StylusOptions(input: input)).pipe(new File('output.css').openWrite());

And finally, a tip on how to get the compiled content as [String]

import 'dart:convert';
import 'package:stylus/stylus.dart';

StylusProcess.start(new StylusOptions(path: 'app.styl')).transform(ASCII.decoder).single.then((String css) {
  print(css); // body .class .internal { color: #00f; }
});

There are many other options that you can send to [StylusOptions] to configure the compilation, check the constructor arguments at [StylusOptions]

Compiler on Editor Build

We also provide a build helper if you wanna your .styl files to automatic compile to .css on save using Dart Editor, to setup that you gonna need to create a file called build.dart on your project root (if you don't have it already), having it, just base the setup on the following example:

import 'package:stylus/stylus.dart';

void main(List<String> args) {
  buildStylus(args);
}

You can provide custom options if you want:

import 'package:stylus/stylus.dart';

void main(List<String> args) {
  buildStylus(args, new StylusOptions(use: ['nib'], lineNumbers: true, includeCss: true, compress: true));
}

dart-stylus's People

Contributors

djalmaaraujo avatar wilkerlucio avatar

Watchers

 avatar  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.