-
-
Save devn/1224167 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns demo.gemstoclojure | |
(:require [ring.adapater.jetty :as jetty] | |
[clojure.contrib.io :as io] | |
[clojure.contrib.classpath :as cp]) | |
(:import [org.jruby.embed ScriptingContainer LocalContextScope])) | |
(def container (ScriptingContainer. LocalContextScope/THREADSAFE)) | |
(println (cp/classpath)) | |
(println (io/pwd)) | |
;; Using $LOAD_PATH to load haml gem | |
;(def gempath [(str (io/pwd) "/src/haml-3.1.2/gem")]) | |
;(. container setLoadPaths gempath) | |
;(. container runScriptlet "require 'rubygems'; require 'haml'") | |
;; Using classpath to load haml gem | |
(. container runScriptlet "require 'rubygems'; require 'haml-3.1.2/gem/haml'") | |
(def engineclass (. container runScriptlet "Haml::Engine")) | |
(def template | |
"%html | |
%head | |
%title | |
Hello Clojure! | |
%body | |
%h2 | |
Hello Clojure from Haml!") | |
(def engine (. container callMethod engineclass "new" template Object)) | |
(defn app [req] | |
{:status 200 | |
:headers {"Content-Type" "text/html"} | |
:body (. container callMethod engine "render" String)}) | |
(defn -main [] | |
(let [port (Integer/parseInt (System/getenv "PORT"))] | |
(jetty/run-jetty app {:port port}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment