Git Product home page Git Product logo

griffon-clojure-plugin's Introduction

Brings the Clojure language compiler and libraries

Plugin page: http://artifacts.griffon-framework.org/plugin/clojure

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.

Usage

You must place all Clojure code under $appdir/src/clojure, it will be compiled first before any sources available in 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

    (ns griffon.clojure.Greet
        (:gen-class
         :methods [[greet [String] String]]))
    (defn -greet
      ([this greetee]
         (str "Hello " greetee "!")))
    (defn -main
      [greetee]
      (println (.greet (griffon.clojure.Greet.) greetee)))

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

    import griffon.clojure.Greet
    class MyController {
       def action = { evt = null ->
          def greeter = new Greet()
          def output = greeter.greet('Griffon')
          // do something with output
       }
    }

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:

    (ns griffon)
    (defn add_numbers [a b] (+ a b))

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:

    class FooController {
        def addNumbers = { evt = null ->
            // invoke the function as a method on the
            // clj dynamic property...
            model.z = clj.add_numbers(model.x, model.y)
        }
    }

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.

    griffon.clojure.dynamicPropertyName = 'clojurePropertyName'

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

    griffon.clojure.injectInto = ["controller"]

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.

griffon-clojure-plugin's People

Contributors

aalmiray avatar

Watchers

James Cloos 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.