javascript-core

Core project for JavaScript Asset Pipeline processors

License

License

The Apache Software License, Version 2.0
Categories

Categories

JavaScript Languages
GroupId

GroupId

com.craigburke.asset
ArtifactId

ArtifactId

javascript-core
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

javascript-core
Core project for JavaScript Asset Pipeline processors
Project URL

Project URL

https://github.com/craigburke/javascript-core-asset-pipeline
Source Code Management

Source Code Management

https://github.com/craigburke/javascript-core-asset-pipeline

Download javascript-core

How to add to project

<!-- https://jarcasting.com/artifacts/com.craigburke.asset/javascript-core/ -->
<dependency>
    <groupId>com.craigburke.asset</groupId>
    <artifactId>javascript-core</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.craigburke.asset/javascript-core/
implementation 'com.craigburke.asset:javascript-core:0.3.0'
// https://jarcasting.com/artifacts/com.craigburke.asset/javascript-core/
implementation ("com.craigburke.asset:javascript-core:0.3.0")
'com.craigburke.asset:javascript-core:jar:0.3.0'
<dependency org="com.craigburke.asset" name="javascript-core" rev="0.3.0">
  <artifact name="javascript-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.craigburke.asset', module='javascript-core', version='0.3.0')
)
libraryDependencies += "com.craigburke.asset" % "javascript-core" % "0.3.0"
[com.craigburke.asset/javascript-core "0.3.0"]

Dependencies

provided (2)

Group / Artifact Type Version
com.bertramlabs.plugins : asset-pipeline-core jar 2.0.12
org.codehaus.groovy : groovy-all jar 2.0.8

runtime (1)

Group / Artifact Type Version
org.mozilla : rhino jar 1.7.7

Project Modules

There are no modules declared in this project.

JavaScript Core Asset Pipeline

This provides the JavaScriptProcessor base class for building Asset Pipeline processors that run JavaScript with caching, thread safety, and a nice DSL.

Note
The JavaScript is currently run using the Rhino engine. Nashorn support might be added at a later date.

Getting started

dependencies {
    compile 'com.craigburke.assets:javascript-core:0.2.4'
}

Example

import com.craigburke.asset.JavaScriptProcessor
import com.craigburke.asset.JavaScriptEngine

import groovy.transform.Synchronized

class ExampleProcessor extends JavaScriptProcessor {

    ExampleProcessor(AssetCompiler precompiler) {
        super(precompiler)
    }

    static JavaScriptEngine exampleEngine

    @Syncronized
    JavaScriptEngine getEngine() { // <1>
        exampleEngine = exampleEngine ?: new JavaScriptEngine('transform.js') // <2>
        exampleEngine
    }

    String process(String input, AssetFile file) {
        javaScript {
            var1 = input // <3>
            eval 'transformFunction(var1);' // <4>
        }
    }
}
  1. The getEngine method must be implemented, here we’re just returning a static JavaScriptEngine

  2. The JavaScriptEngine constructor can optionally load a file that’s contained on your classpath. Here the file transform.js is loaded

  3. This adds the variable var1 to your JavaScript context with the value of input.

  4. The eval method allows you to execute a JavaScript function (or arbitrary JavaScript). The result is returned as a String

Versions

Version
0.3.0
0.2.4
0.2.3
0.2.2
0.2.1
0.2.0
0.1.0