Skip to content

Commit

Permalink
Minor tidying up in the examples.
Browse files Browse the repository at this point in the history
Remove non-Leiningen install instructions. It's a start. The whole
README needs updating / replacing since the classpath issue is best
addressed a different way altogether now.
  • Loading branch information
seancorfield committed Apr 16, 2012
1 parent 9f43da4 commit fa50b9f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 29 deletions.
24 changes: 6 additions & 18 deletions README.md
Expand Up @@ -2,9 +2,12 @@

To use cfmljure, you need the Clojure libraries. I think the easiest way to do that is with Leiningen, the Clojure build tool.

**Note: cfmljure.cfc requires Adobe ColdFusion 9.0.1 or Railo 3.2.2**
**Note: cfmljure.cfc requires Adobe ColdFusion 9.0.1 or Railo 3.2.2;
Because of the way Adobe ColdFusion deals with arrays of numbers,
many of the examples do not run as-is - but they run fine on Railo
so I'd recommend you try Railo if you want to play with cfmljure.**

## Installation with Leiningen
## Installation (with Leiningen)

Install the **lein** script from http://github.com/technomancy/leiningen
(download the **lein** script, make it executable, run **lein self-install** to complete
Expand All @@ -27,21 +30,6 @@ In your **WEB-INF** folder, create a **classes** folder and copy **clj/cfml**
and **clj/task** to that **classes** folder. Restart your CFML engine.
Now go hit the cfmljure **index.cfm** file in your browser!

## Installation without Leiningen

If you really don't want to mess with Leiningen, you can install Clojure manually. However, without Leiningen
you're not going to be able to run the tests and build JAR files etc so I strongly recommend the first installation
approach above.

Download the Clojure libraries from here: http://clojure.org/downloads

Download both Clojure and Clojure Contrib and unzip them. Copy **clojure.jar** (from the clojure-1.2.0.zip)
and **clojure-contrib-1.2.0.jar** (from the target subfolder of clojure-contrib-1.2.0.zip) to your classpath.
I put them in **{tomcat}/lib** - and restart your CFML engine. You can ignore the rest of those ZIP files.

Copy the **clj/** folder contents from the cfmljure project to your server's **WEB-INF/classes** folder (or create a symbolic link)
and restart your CFML engine. Now go hit the cfmljure **index.cfm** file in your browser!

# Your Clojure Code

Your Clojure code also needs to be on your classpath.
Expand Down Expand Up @@ -165,4 +153,4 @@ variable via the **.\_()** API. Calling **_reference_.\_()** will return the und

If you have a reference to a namespace, you also can get an underlying Clojure entity by name via the **\_()** API or *_name()* implicit function.
Calling **_namespace_.\_( _name_ )** or **_namespace_.\__name_()** is identical to calling **_namespace_.get( _name_ ).\_()** so this is the more convenient API when you're
working with namespaces or an installed Clojure configuration.
working with namespaces or an installed Clojure configuration.
4 changes: 2 additions & 2 deletions advanced/index.cfm
Expand Up @@ -12,11 +12,11 @@
(times_2 42) = #cfml.examples.times_2( 42 )#<br />

<!--- call built-in Clojure function, passing raw definition of times_2 function: --->
<cfset list = clojure.core.map( cfml.examples._( 'times_2' ), [ 4, 5, 6 ] ) />
<cfset list = clojure.core.map( cfml.examples._times_2(), [ 4, 5, 6 ] ) />
(map times_2 [ 4 5 6 ]) = <cfloop index="n" array="#list#">#n# </cfloop><br />

<!--- loop over raw Clojure object (a list) in CFML: --->
<cfset x = cfml.examples._( 'x' ) />
<cfset x = cfml.examples._x() />
x = <cfloop item="n" collection="#x#">#n# </cfloop><br />
<cfset end = getTickCount() />

Expand Down
21 changes: 12 additions & 9 deletions basic/index.cfm
Expand Up @@ -64,31 +64,34 @@
(times_2 42) = #cfml.examples.times_2( 42 )#<br />

<!--- call built-in Clojure function, passing raw definition of times_2 function: --->
<cfset list = clojure.core.map( times_2._(), [ 4, 5, 6 ] ) />
<cfset list = clojure.core.map( cfml.examples._times_2(), [ 4, 5, 6 ] ) />
(map times_2 [ 4 5 6 ]) = <cfloop index="n" array="#list#">#n# </cfloop><br />

<!--- loop over raw Clojure object (a list) in CFML: --->
<cfset x = cfml.examples._( 'x' ) />
<cfset x = cfml.examples._x() />
x = <cfloop item="n" collection="#x#">#n# </cfloop><br />
<cfset end = getTickCount() />

Time taken: #end - start#ms.<br />

<cfset start = getTickCount() />
</cfoutput>
<cfscript>
// 3. Call Clojure by configuration and installation:
start = getTickCount();
namespaces = 'cfml.examples, clojure.core';
target = { }; // normally you'd target a scope - this is just an example
// install the configuration to the target 'scope':
clj.install( namespaces, target );
end = getTickCount();
writeOutput( '<h1>Calls via implicit method lookup after installation to a target scope</h1>' );
writeOutput( 'Time taken for install: #end - start#ms.<br /><br />' );
start = getTickCount();
</cfscript>
<cfoutput>
<h1>Calls via implicit method lookup after installation to a target scope</h1>

(greet "World") = #target.cfml.examples.greet( 'World' )#<br />

<!--- pass CFML array to Clojure and loop over Clojure sequence that comes back: --->
Expand All @@ -99,13 +102,13 @@
(times_2 42) = #target.cfml.examples.times_2( 42 )#<br />

<!--- call built-in Clojure function, passing raw definition of times_2 function: --->
<cfset list = target.clojure.core.map( times_2._(), [ 4, 5, 6 ] ) />
<cfset list = target.clojure.core.map( target.cfml.examples._times_2(), [ 4, 5, 6 ] ) />
(map times_2 [ 4 5 6 ]) = <cfloop index="n" array="#list#">#n# </cfloop><br />

<!--- loop over raw Clojure object (a list) in CFML: --->
<cfset x = target.cfml.examples._( 'x' ) />
<cfset x = target.cfml.examples._x() />
x = <cfloop item="n" collection="#x#">#n# </cfloop><br />
<cfset end = getTickCount() />

Time taken: #end - start#ms.<br />
</cfoutput>
</cfoutput>

0 comments on commit fa50b9f

Please sign in to comment.