Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Building Websites In Clojure

High level overview of how websites are built using the Clojure programming language.
by

Dave Moore

on 13 January 2012

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Building Websites In Clojure

Web Server
Adapter
Application
Middleware
Routing
App Logic
Views
Frameworks
Joodo
Gaeshi
Noir
Conjure
Webjure
Weld
Websites With Clojure
Request
Response
Request
Response
Useful Libraries
Persistence
Validation
Authentication
Web Services
Testing
Cascade
Ring
About
Adapter
Interface
Utility
Interface
Adapter
Utility
Response
Request
Abstracts HTTP details like what Rack does for Ruby
:server-port
:server-name
:remote-addr
:uri
:query-string
:scheme
:request-method
:content-type
:character-encoding
:headers
:body
Standard Keys
Accepted Keys
:status
:headers
:body
-String
-Sequence
-File
-InputStream
Custom Keys
Created by middleware
Runs with Jetty
-or-
Runs as a servlet
Brief Overview of Clojure
Dialect of Lisp
Functional Programming Language
Built on JVM
Designed for Concurrency
Gaining in Popularity
Clojure Code
(* 3 (+ 1 1))

Will equal 6
(defn create-email [account]
(str account "@me.bro"))

(create-email "come")

Will equal "come@me.bro"
More Code
Speclj.com
Cleancoders.com
Documented Joodo
Joodoweb.com
My Experience
Modular
Why Do I Build Web
Apps In Clojure?
Concise
Accessible
Fast
Data Manipulation
Middleware
Handlers
App logic container
Takes in request map
Returns response map
Adds functionality to Handlers
Takes in a Handler
Returns a modified handler
Example of Middleware
wrap-cookies
Parses the cookies in the request map, then assocs the resulting map
to the :cookies key on the request.
Apply Selected
Custom Middleware
Your Code Goes Here
Compojure
Moustache
defroutes
context
Defines a Ring handler
Contains all routes
First matching route evaluates
(defroutes my-routes
(GET "/route" [] (response "What's up?"))
(ANY "/route" [] (response "Hello!")))
Prefixes nested routes
(defroutes my-routes
(context "/route" []
(GET "/nested-route" [] (response "What's up?"))
(ANY "/nested-route" [] (response "Hello!"))))
Binding
Sets variable to portion of route
(defroutes my-routes
(POST "/user/:id" [id] (update-user id)))
app
Defines a Ring handler
(def app-handler
(app ["/route"] {:get ["Get request on /route"]
:post ["Post request on /route"]}))
(def app-handler
(app ["/route" nested-route]
{:get ["Get request on /route" nested-route]
:post ["Post request on /route" nested-route]}))
Hiccup
Enlive
Hiccup is a simple parser
clojure data -> string of html
Examples:
(html [:p "Good Morning"])
<p>Good Morning</p>

(html [:p {:class "bright"} "Good Morning"])
<p class=\"bright\">Good Morning</p>

(html [:p.bright "Good Morning"])
<p class=\"bright\">Good Morning</p>

(html [:p#bright "Good Morning"])
<p id=\"bright\">Good Morning</p>

(html [:a#message.bright {:href "/route"} "Good Morning"])
"<a class=\"bright\" href=\"/route\" id=\"message\">Good Morning</a>"
Enlive uses real html elements
Selects and changes elements
Examples:
template.html

Before
<p id="message"></p>

After
<p id="message">Message text</p>
template.clj

(deftemplate index "template.html" [data]
[:p#message] (content data))

(ring/response (index "Message text"))
Hiccup Form Helpers
http://weavejester.github.com/hiccup/api-index.html
(text-field "name" "value")

[:input {:type "text", :name "name", :id "name", :value "value"}]



(drop-down "name" ["option1" "option2"] "option1")

[:select {:name "name", :id "name"}
[:option {:selected true} "option1"]
[:option {:selected false} "option2"]]



(include-css "abc.css" "reset.css")

[:link {:type "text/css", :href "abc.css", :rel "stylesheet"}]
[:link {:type "text/css", :href "reset.css", :rel "stylesheet"}]
*Note, doesn't actually change the html file. Changes the html loaded in the response map.
Full transcript