Skip to content

Commit

Permalink
assets: css autoprefixer fix #544
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Nov 6, 2016
1 parent 76b095a commit 5e04c8f
Show file tree
Hide file tree
Showing 8 changed files with 33,913 additions and 0 deletions.
83 changes: 83 additions & 0 deletions jooby-assets-autoprefixer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<parent>
<groupId>org.jooby</groupId>
<artifactId>jooby-project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
<artifactId>jooby-assets-autoprefixer</artifactId>

<name>autoprefixer module</name>

<build>
<plugins>
<!-- sure-fire -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.java</include>
<include>**/*Feature.java</include>
<include>**/Issue*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<!-- Jooby -->
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-assets-nodejs</artifactId>
<version>${project.version}</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<classifier>tests</classifier>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-easymock</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<scope>test</scope>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package org.jooby.assets;

import org.jooby.MediaType;

import com.typesafe.config.Config;

/**
* <h1>auto-prefixer</h1>
* <p>
* <a href="https://github.com/postcss/postcss">PostCSS</a> plugin to parse CSS and add vendor
* prefixes to CSS rules using values from <a href="http://caniuse.com">Can I Use</a>. It
* is recommended by Google and used in Twitter, and Taobao.
* </p>
*
* <h2>usage</h2>
*
* <pre>{@code
* assets {
* pipeline {
* dev: [auto-prefixer]
* dist: [auto-prefixer]
* }
* }
* }</pre>
*
* <p>
* Once configured, write your CSS rules without vendor prefixes (in fact, forget about them
* entirely):
* </p>
*
* <pre>{@code
* :fullscreen a {
* display: flex
* }
* }</pre>
*
* <p>Output:</p>
*
* <pre>{@code
* :-webkit-full-screen a {
* display: -webkit-box;
* display: flex
* }
* :-moz-full-screen a {
* display: flex
* }
* :-ms-fullscreen a {
* display: -ms-flexbox;
* display: flex
* }
* :fullscreen a {
* display: -webkit-box;
* display: -ms-flexbox;
* display: flex
* }
* }</pre>
*
* <h2>options</h2>
*
* <pre>{@code
* {
* auto-prefixer {
* browsers: ["> 1%", "IE 7"]
* cascade: true
* add: true
* remove: true
* supports: true
* flexbox: true
* grid: true
* stats: {}
* }
* }
* }</pre>
*
* <p>
* For complete documentation about available options, please refer to the <a href="https://github.com/postcss/autoprefixer">autoprefixer</a> site.
* </p>
* @author edgar
* @since 1.0.0
*/
public class AutoPrefixer extends AssetProcessor {

@Override
public boolean matches(final MediaType type) {
return MediaType.css.matches(type);
}

@Override
public String process(final String filename, final String source, final Config conf)
throws Exception {
return V8Context.run(v8 -> {
return v8.invoke("auto-prefixer.js", source, options(), filename);
});
}

}
29 changes: 29 additions & 0 deletions jooby-assets-autoprefixer/src/main/resources/auto-prefixer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var global = {};

(function (source, options) {
/** Source: https://raw.github.com/ai/autoprefixer-rails/master/vendor/autoprefixer.js */
assets.load('lib/autoprefixer.js');

var output;

try {
output = global.autoprefixer.process(source, options);
} catch (x) {
output.error = x.toString();
console.log(x);
}

output.warnings().forEach(function (warn) {
console.warn(warn.toString());
});

var errors = [];
if (output.error) {
errors.push(error);
}

return {
output: output.css,
errors: errors
};
});
Loading

0 comments on commit 5e04c8f

Please sign in to comment.