Skip to end of metadata
Go to start of metadata

Description

The Clojure plugin enables compiling and running Clojure code on your Griffon application. This plugin is heavily influenced by its Grails counterpart, even borrows some of its code.

Installation

The current version of griffon-clojure-plugin is 0.8
To install just issue the following command

Usage

You must place all Clojure code under $appdir/src/clojure, it will be compiled first before any sources available on griffon-app or src/main which means you can't reference any of those sources from your Clojure code, while the Groovy sources can. You will be able to use the LangBridge Plugin facilities to communicate with other JVM languages.

Sources placed under $appdir/src/clojure will generate Java classes using macros provided by Clojure, for example

$appdir/src/clojure/griffon/clojure/Greet.clj

This will generate a Java class named griffon.clojure.Greet, which can be used inside any Griffon artifact, for example a Controller

Starting from version 0.2 you will be able to load clojure scripts at any time. By default all scripts placed at $basedir/griffon-app/resources/clj will be loaded when the application bootstraps itself. For example griffon-app/resources/clj/demo.clj might look like this:

With that code in place, the add_numbers function may be executed as a method call on a dynamic property named clj from a Griffon controller. See below:

The dynamic property will be named clj by default. The name of the property may be set explicitly in griffon-app/conf/Config.groovy by assigning a value to the griffon.clojure.dynamicPropertyName property.

For most applications, the default name of clj should be fine. You can also alter in which artifacts the property gets injected, by default only controllers will have that property. See griffon-app/conf/Config.groovy and look for the following entry

Finally, you can load any Clojure script by calling cljLoad(String path) where path will be resolved using Spring's PathMatchingResourcePatternResolver. The default path used during bootstrap is "classpath*:/clj/*/.clj". It is also worth mentioning that this method will be injected to all artifacts controlled by griffon.clojure.injectInto and that the prefix clj will be affected by griffon.clojure.dynamicPropertyName.

Scripts

  • create-clojure-script - creates a new Clojure script in $basedir/griffon-app/resources/clj.
  • create-clojure-class - creates a new Clojure (macro based) class in $basedir/src/clojure.
  • clojure-repl - executes a Clojure REPL with the application's classpath fully configured.

History

Version

Date

Notes

0.8

09-26-11

Release sync with Griffon 0.9.3, Upgraded to Clojure 1.3.0

0.7

04-01-11

Release sync with Griffon 0.9.2

0.6

08-24-10

Release sync with Griffon 0.9, Upgraded to Clojure 1.2.0

0.5.1

03-05-10

Fixed GRIFFON-150

0.5

03-01-10

Upgraded to Griffon 0.3

0.4

01-01-10

Upgraded to Clojure 1.1

0.3

11-15-09

Added fixes from grails-clojure-plugin. Added repl and create-script/class scripts

0.2

09-10-09

Enable loading of clojure scripts at any time. Check timestamp of compiled sources to decide if recompile is needed

0.1

07-28-09

Initial release

  • No labels