14
How Midjournal Use Clojure? Presented by Asep Bagja Priandana Twitter: @bepituLaz

How Midjournal Use Clojure?

Embed Size (px)

Citation preview

Page 1: How Midjournal Use Clojure?

How Midjournal Use Clojure?Presented by Asep Bagja Priandana

Twitter: @bepituLaz

Page 2: How Midjournal Use Clojure?

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.

Page 3: How Midjournal Use Clojure?

Midjournal A Year Ago

Page 4: How Midjournal Use Clojure?

Midjournal Now(in Production)

Read Only (JSON)

Read and Write

Page 5: How Midjournal Use Clojure?

Midjournal Now (in Development)

Read and Write

Sync

Read Only

Page 6: How Midjournal Use Clojure?

Why Clojure?Functional programmingComposable (No need full stack framework)It’s LispOn top of JVMProject automation with LeiningenREPL

Page 7: How Midjournal Use Clojure?

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}

Page 8: How Midjournal Use Clojure?

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

Page 9: How Midjournal Use Clojure?

Let’s tear it down!

Page 10: How Midjournal Use Clojure?

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.

Page 11: How Midjournal Use Clojure?

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>

Page 12: How Midjournal Use Clojure?

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.

Page 13: How Midjournal Use Clojure?

Ring

HandlerRequestResponseMiddleware

Ring is a Clojure web applications library inspired by Python's WSGI and Ruby's Rack.

Page 14: How Midjournal Use Clojure?

How Do You Deploy The Application?