Git Product home page Git Product logo

sass-java's Introduction

Overview

Compile sass to css on-the-fly via a j2ee servlet filter

Usage

Add the dependency to pom.xml

<dependency>
    <groupId>com.darrinholst</groupId>
    <artifactId>sass-java</artifactId>
    <version>3.4.4</version>
</dependency>

Add the filter to web.xml

<filter>
    <filter-name>SassCompiler</filter-name>
    <filter-class>com.darrinholst.sass_java.SassCompilingFilter</filter-class>
</filter>

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

Create a WEB-INF/sass/config.rb

css_dir = "../../stylesheets"
sass_dir = "."

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

Versioning

The first 3 nodes of the version will match the version of sass that is being used. Current versions of sass and compass can be found in the Gemfile.

Configuring

Configuration is done through a combination of filter init parameters and the config.rb file. The following filter init parameters are available to control the execution of the filter:

  • configLocation - the location of the config.rb (default WEB-INF/sass/config.rb)
  • 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

A common practice is to turn sass generation off in production and precompile in your build process. An example of how to do this based off a system property is:

<filter>
    <filter-name>SassCompiler</filter-name>
    <filter-class>com.darrinholst.sass_java.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

See the compass config documentation to find out about all the wonderful things you can put in config.rb. For those config options that reference a file or directory, the working directory that compass will be executed in is the directory that contains config.rb.

Precompiling

Use the maven plugin

Development

The magic behind how this works comes from packaging up the sass gems into a jar that the filter can then use via jruby. The process to jar up the gems is described here. That process is mavenized here. So to change sass or compass versions All Ya Gotta Do™ is update the Gemfile and mvn clean install.

Releasing

First time? Read this
mvn release:prepare release:perform
That worked? Read this

Try it out

  1. git clone https://github.com/darrinholst/sass-java.git
  2. cd sass-java
  3. mvn install
  4. mvn jetty:run -pl sass-java
  5. open http://localhost:8080
  6. change src/test/sample-webapp/WEB-INF/sass/application.scss
  7. refresh

sass-java's People

Contributors

darrinholst avatar born2snipe avatar windgazer avatar magnyld avatar larsgrefer avatar digaobarbosa avatar bryant1410 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.