Upload
asep-bagja
View
448
Download
0
Embed Size (px)
Citation preview
How Midjournal Use Clojure?Presented by Asep Bagja Priandana
Twitter: @bepituLaz
What is Midjournal?We are a new form of media company that embrace long form journalism for Indonesia middle-class.Everyone can be a writer, but your writing will be curated by our editor.
Midjournal A Year Ago
Midjournal Now(in Production)
Read Only (JSON)
Read and Write
Midjournal Now (in Development)
Read and Write
Sync
Read Only
Why Clojure?Functional programmingComposable (No need full stack framework)It’s LispOn top of JVMProject automation with LeiningenREPL
Clojure is Still Not For Geniuses (Like Me)
(function argument argument and-argument whatever-argument)
That syntax above covers a solid 90% Clojure code. A few more things for writingClojure code are:
; a comment
‘a-symbol
:a-keyword
“a string”
[a vector]
{:a map}
Library in Our Clojure Application
Compojure is a routing libraryEnlive is a selector-based templating libraryMidpress is our open-sourced libraryRing is HTTP server abstraction library
Let’s tear it down!
CompojureIt's a small HTTP routing library for Ring that allows web applications to be composed of small, independent parts.
Sample routing:
(GET “/user/:id” [id] (str “<h1>Hello ” id “</h1>”))
Compojure supports GET, POST, PUT, DELETE, OPTIONS, PATCH, and HEAD.
EnliveThe magical templating library.
The HTML from front-end developer:
<h2 class="title">The Dummy Title</h2>
The Clojure code to transform the above HTML code:
(deftemplate tpl-home "home.html” [home-data] [:h2.title] (content (:title home-data)))
It will render on the front-end
<h2 class="title">The Title From Database</h2>
MidpressOur open-sourced library for interacting with WordPress WP-API(https://github.com/Midjournal/midpress)
Sample code:(the-loop {:url "http://yourdomain.com/wp-json"})
It will transform JSON string from WP-API into Clojure's vector and map data structure.
Ring
HandlerRequestResponseMiddleware
Ring is a Clojure web applications library inspired by Python's WSGI and Ruby's Rack.
How Do You Deploy The Application?