Git Product home page Git Product logo

sass-java's Introduction

Sass for Java

Don't let those ruby devs have all the fun, with a simple filter you can have sass in your java too.

Usage

Add this to your web.xml

<filter>
    <filter-name>SassCompiler</filter-name>
    <filter-class>com.sass_lang.SassCompilingFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>SassCompiler</filter-name>
    <url-pattern>*.css</url-pattern>
</filter-mapping>

Put your sass templates in WEB-INF/sass and each request for a css file will regenerate as needed.

Maven

Since getting stuff in central is a PITA, add the following to your pom.xml

<repositories>
    <repository>
        <id>sass-java</id>
        <url>http://sass-java.googlecode.com/svn/repo/</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.sass-lang</groupId>
        <artifactId>sass-java</artifactId>
        <version>3.1.1.4</version>
    </dependency>
</dependencies>

Ant

Download the jar with depenencies

##Config

Configuration is done through filter init parameters

  • templateLocation - the location where the sass templates will be found (default WEB-INF/sass)
  • cssLocation - the location where the sass templates will be compiled to (default stylesheets)
  • cacheLocation - the location that sass will use for compile caching (default WEB-INF/.sass-cache)
  • cache - turn caching on/off (default true)
  • onlyRunWhenKey - the system property or environment variable to check to see if sass compilation should run, use this to turn sass generation off in production
  • onlyRunWhenValue - the corresponding value to check to see if sass compilation should run

You probably only want the css generation to run in development mode and then commit the generated css to source control. This is achieved by the onlyRunWhenKey and onlyRunWhenValue filter init parameters.

<filter>
    <filter-name>SassCompiler</filter-name>
    <filter-class>com.sass_lang.SassCompilingFilter</filter-class>
    <init-param>
        <param-name>onlyRunWhenKey</param-name>
        <param-value>RUNTIME_ENVIRONMENT</param-value>
    </init-param>
    <init-param>
        <param-name>onlyRunWhenValue</param-name>
        <param-value>local</param-value>
    </init-param>
</filter>

With this configuration the filter will check a system property or environment variable called RUNTIME_ENVIRONMENT and only run the sass compilation if that value is equal to local

##Try it out

  1. git clone https://github.com/darrinholst/sass-java.git
  2. cd sass-java
  3. mvn jetty:run
  4. wait for maven to download the internet
  5. open http://localhost:8080/sass-java
  6. change src/test/sample-webapp/WEB-INF/sass/application.scss
  7. repeat step 5
  8. be amazed

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.