Skip to content

a chauffeur for scala patrons in the less css compilation party

License

Notifications You must be signed in to change notification settings

softprops/lesst

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lesst

Build Status

a chauffeur for scala patrons in the less css compilation party.

install

Via the copy and paste method

resolvers += "softprops-maven" at "http://dl.bintray.com/content/softprops/maven"

libraryDependencies += "me.lessis" %% "lesst" % "0.1.2"

Via a more civilized method which will do the same without all the manual work.

> ls-install lesst

Note If you are a bintray-sbt user you can optionally specify the resolver as

resolvers += bintray.Opts.resolver.repo("softprops", "maven")

usage

This library provides a scala interface for compiling beautiful less css source files into slightly less beauitful css files, lest you actually like repeating your self over and over in css. In which case, this library may not be for you.

Input sources

To compile less source code, you apply a lesst.InputSource[T] to the lesst.Compile object. There are currently two out-of-the-box InputSources available which are implicitly resolved.

You can provide a fileName and less source code.

lesst.Compile()(fileName, lessSourceCode)

A filename is required to resolve relative paths to less @imports, otherwise they won't work.

You can also provide a java.net.URL representing the .less file resource.

lesst.Compile()(getClass().getResource(fileName))

An InputSource is a simple type class defined as

trait InputSource[T] {
  def filename: String
  def src: String
}

Compile will implicitly resolve an instance of this for type T when compiling less sources.

Compile options

You can optionally minify the generated css if you like "skinny" output. The default is to not minify output.

import lesst.{ Compile, Options }
Compile(Options(mini = true))(fileName, lessSourceCode)

You can also store a reference to Compiler an call method which return a new compile with updated options

lesst.Compile().minify(true)(fileName, lessSource)

Compilation results

The compilation results in a scala.Either[CompilationError, StyleSheet] which provides access the compiled css and a list of file imports included in the StyleSheet or a CompilationError containing information about what happened and where.

Error reporting

Unless you are Chuck Norris, you probably will stumble on a syntax error on occasion when writing less css. Lesst keeps that in mind and provides good error reporting with formatted CompilationErrors.

errors

Future is full of choices

This library does not make choices for you in regard to your choice of asynchronicity. You can make them yourself.

Got other stuff to do? Why wait? Put a scala.concurrent.Future on it.

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import lesst.{ Compile, StyleSheet }

Future(Compile()(file, lessSourceCode)).map {
  _.fold(println, {
    case StyleSheet(css, _) =>
      Thread.sleep(1000)
      println(css)
  })
}
println("compiling scala...")

references and notes

  • see the lesscss docs for more information on less
  • this version of lesst uses a the 1.4.1 version of the less compiler "under the hood"
  • historians will look back on one day realized this code was extracted from less-sbt for the greater good. If you are doing greater good with lesst. You should let me know about.

Doug Tangren (softprops) 2013

About

a chauffeur for scala patrons in the less css compilation party

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published