Commit a2d32cda authored by Vlad Dumitru's avatar Vlad Dumitru
Browse files

First commit

Pipeline #4792 failed with stages
in 0 seconds
@import url(',wght@0,400;0,700;1,400&display=swap')
base-font-stack = 'Source Code Pro', monospace
base-font-weight = 400
bold-font-weight = 700
base-font-size = 18px
base-line-height = 1
base-fg = #333
base-bg = #fff
accent = #2274a5
accent-l = alpha(accent, 75%)
accent-ll = alpha(accent, 50%)
accent-d = darken(accent, 25%)
accent-dd = darken(accent, 50%)
box-sizing border-box
font-family base-font-stack
font-size base-font-size
font-weight base-font-weight
line-height base-line-height
color base-fg
background-color base-bg
width 100%
height 100%
height 100%
margin 2.5%
overflow hidden
width 95%
height 75%
display flex
flex-flow row nowrap
& > .column
flex-basis 50%
padding-left 12.5%
display flex
flex-flow row nowrap
height 100%
& > .side
flex-basis 50%
height 100%
& > .content
height 100%
overflow-y auto
scrollbar-color accent white
scrollbar-width thin
padding-left 25%
opacity 0.25
opacity 1
margin 0 0 0 25%
border none
height 1px
background-color accent
h1, h2, h3, h4
font-weight base-font-weight
margin 0
font-weight base-font-weight
text-decoration none
color accent
transition all 0.05s ease-in-out
color accent-dd
color base-bg
background-color accent-l
content 'ext'
position relative
font-size 0.66em
top -0.5rem
color base-fg
max-height 15%
display flex
flex-flow column nowrap
justify-content space-between
opacity 0.25
padding 0
transform rotate(180deg)
display flex
flex-flow column nowrap
& > .file:not(:last-child)
border-bottom 0.125rem dashed alpha(accent, 12.5%)
& > .file
display flex
flex-flow row nowrap
align-items baseline
justify-content space-between
padding 1rem 0
& > .name
font-size 1.25rem
& > .tags > span
font-size 0.75rem
border 0.125rem solid accent
color accent
padding 0.125rem
cursor pointer
position relative
margin 0.5rem 0 1rem 12.5%
color alpha(base-fg, 25%)
position absolute
left -2ch
content '>'
& > .active
color base-fg
.layers > span
font-size 0.75rem
border 0.125rem solid alpha(accent, 12.5%)
color accent
padding 0.125rem
cursor pointer
& > sup
color alpha(accent, 50%)
color alpha(base-fg, 50%)
margin-top 1.5rem
& > .fragment
display flex
flex-flow row nowrap
& > .id
flex-basis 15%
color accent-ll
text-align right
margin-right 1rem
& > .author
flex-basis 25%
& > .name
flex-basis 60%
h1.field > .name
flex-basis 12.5%
display flex
flex-flow row nowrap
margin 0.5rem 0
& > .name
flex-basis 25%
padding-right 1rem
text-align right
& > .value
flex-basis 75%
& > .header
display inline-block
margin-bottom 0.25rem
padding-bottom 0.25rem
border-bottom solid 1px accent-ll
& > .date-time
font-size 0.75em
& > .author
font-size 0.75em
& > .message
font-size 0.75rem
margin-bottom 0.5rem
font-size 0.75rem
line-height 1.5
& > h1, h2, h3
position relative
& > h1
left -1ch
& > h2
left -2ch
& > h1
font-size 1.5rem
margin-top 3rem
& > h2
font-size 1rem
& > h1::before
content '#'
left -1ch
& > h2::before
content '##'
left -2ch
& > h1::before, h2::before, h3::before
font-weight bold-font-weight
color accent
position relative
& ul
list-style-type none
list-style-position outside
padding 0
position relative
& > li
margin 0 0 0.5rem 0
& > ul
margin-left 2ch
margin-bottom 1rem
& > li::before
position absolute
left -2ch
content '-'
(ns konditorei.config
[cprop.core :refer [load-config]]
[cprop.source :as source]
[mount.core :refer [args defstate]]))
(defstate env
(ns konditorei.core
[konditorei.handler :as handler]
[konditorei.nrepl :as nrepl]
[luminus.http-server :as http]
[konditorei.config :refer [env]]
[ :refer [parse-opts]]
[ :as log]
[mount.core :as mount])
;; log uncaught exceptions in threads
(reify Thread$UncaughtExceptionHandler
(uncaughtException [_ thread ex]
(log/error {:what :uncaught-exception
:exception ex
:where (str "Uncaught exception on" (.getName thread))}))))
(def cli-options
[["-p" "--port PORT" "Port number"
:parse-fn #(Integer/parseInt %)]])
(mount/defstate ^{:on-reload :noop} http-server
(-> env
(update :io-threads #(or % (* 2 (.availableProcessors (Runtime/getRuntime)))))
(assoc :handler (handler/app))
(update :port #(or (-> env :options :port) %))
(select-keys [:handler :host :port])))
(http/stop http-server))
(mount/defstate ^{:on-reload :noop} repl-server
(when (env :nrepl-port)
(nrepl/start {:bind (env :nrepl-bind)
:port (env :nrepl-port)}))
(when repl-server
(nrepl/stop repl-server)))
(defn stop-app []
(doseq [component (:stopped (mount/stop))]
(log/info component "stopped"))
(defn start-app [args]
(doseq [component (-> args
(parse-opts cli-options)
(log/info component "started"))
(.addShutdownHook (Runtime/getRuntime) (Thread. stop-app)))
(defn -main [& args]
(start-app args))
(ns konditorei.handler
[konditorei.middleware :as middleware]
[konditorei.layout :refer [error-page]]
[konditorei.routes.bundle :refer [bundle-routes]]
[konditorei.routes.tree :refer [tree-routes]]
[reitit.ring :as ring]
[ring.middleware.content-type :refer [wrap-content-type]]
[ring.middleware.webjars :refer [wrap-webjars]]
[konditorei.env :refer [defaults]]
[mount.core :as mount]))
(mount/defstate init-app
:start ((or (:init defaults) (fn [])))
:stop ((or (:stop defaults) (fn []))))
(mount/defstate app-routes
[(bundle-routes) (tree-routes)])
{:path "/"})
(wrap-webjars (constantly nil)))
(constantly (error-page {:status 404, :title "404 - Page not found"}))
(constantly (error-page {:status 405, :title "405 - Not allowed"}))
(constantly (error-page {:status 406, :title "406 - Not acceptable"}))}))))
(defn app []
(middleware/wrap-base #'app-routes))
(ns konditorei.layout
[selmer.parser :as parser]
[selmer.filters :as filters]
[markdown.core :refer [md-to-html-string]]
[ring.util.http-response :refer [content-type ok]]
[ring.util.anti-forgery :refer [anti-forgery-field]]
[ring.middleware.anti-forgery :refer [*anti-forgery-token*]]
(parser/set-resource-path! ( "html"))
(parser/add-tag! :csrf-field (fn [_ _] (anti-forgery-field)))
(filters/add-filter! :markdown (fn [content] [:safe (md-to-html-string content)]))
(defn render
"renders the HTML template located relative to resources/html"
[request template & [params]]
(assoc params
:page template
:csrf-token *anti-forgery-token*)))
"text/html; charset=utf-8"))
(defn error-page
"error-details should be a map containing the following keys:
:status - error status
:title - error title (optional)
:message - detailed error message (optional)
returns a response map with the error page as the body
and the status specified by the status key"
{:status (:status error-details)
:headers {"Content-Type" "text/html; charset=utf-8"}
:body (parser/render-file "error.html" error-details)})
(ns konditorei.middleware
[konditorei.env :refer [defaults]]
[ :as log]
[konditorei.layout :refer [error-page]]
[ring.middleware.anti-forgery :refer [wrap-anti-forgery]]
[konditorei.middleware.formats :as formats]
[muuntaja.middleware :refer [wrap-format wrap-params]]
[konditorei.config :refer [env]]
[ring.middleware.flash :refer [wrap-flash]]
[ring.adapter.undertow.middleware.session :refer [wrap-session]]
[ring.middleware.defaults :refer [site-defaults wrap-defaults]])
(defn wrap-internal-error [handler]
(fn [req]
(handler req)
(catch Throwable t
(log/error t (.getMessage t))
(error-page {:status 500
:title "Something very bad has happened!"
:message "We've dispatched a team of highly trained gnomes to take care of the problem."})))))
(defn wrap-csrf [handler]
{:status 403
:title "Invalid anti-forgery token"})}))
(defn wrap-formats [handler]
(let [wrapped (-> handler wrap-params (wrap-format formats/instance))]
(fn [request]
;; disable wrap-formats for websockets
;; since they're not compatible with this middleware
((if (:websocket? request) handler wrapped) request))))
(defn wrap-base [handler]
(-> ((:middleware defaults) handler)
(wrap-session {:cookie-attrs {:http-only true}})
(-> site-defaults
(assoc-in [:security :anti-forgery] false)
(dissoc :session)))
(ns konditorei.middleware.formats
[luminus-transit.time :as time]
[muuntaja.core :as m]))
(def instance
(-> m/default-options
[:formats "application/transit+json" :decoder-opts]
(partial merge time/time-deserialization-handlers))
[:formats "application/transit+json" :encoder-opts]
(partial merge time/time-serialization-handlers)))))
(ns konditorei.nrepl
[nrepl.server :as nrepl]
[ :as log]))
(defn start
"Start a network repl for debugging on specified port followed by
an optional parameters map. The :bind, :transport-fn, :handler,
:ack-port and :greeting-fn will be forwarded to as they are."
[{:keys [port bind transport-fn handler ack-port greeting-fn]}]
(log/info "starting nREPL server on port" port)
(nrepl/start-server :port port
:bind bind
:transport-fn transport-fn
:handler handler
:ack-port ack-port
:greeting-fn greeting-fn)
(catch Throwable t
(log/error t "failed to start nREPL")
(throw t))))
(defn stop [server]
(nrepl/stop-server server)
(log/info "nREPL server stopped"))
(ns konditorei.routes.bundle
[konditorei.layout :as layout]
[ :as log]
[konditorei.middleware :as middleware]
[konditorei.speechcake :as speechcake]
[konditorei.util :as util]))
(defn- parse-history [h]
(let [[d a m] h]
{:date (java.util.Date. (* 1000 (Long/parseLong d)))
:author a
:message m}))
(defn render-bundle [request]
(let [key (-> request :path-params :key)
bundle (speechcake/bundle key)
layers (:layers bundle)
frags (:fragments bundle)
history (map parse-history (:history bundle))]
(log/debug key bundle (util/breadcrumbs-to key))
(layout/render request "bundle.html"
{:breadcrumbs (util/breadcrumbs-to key)
:name (:name bundle)
:layers layers
:fragments frags
:history history
:key key})))
(defn bundle-routes []
{:middleware [middleware/wrap-csrf
["*key" {:get render-bundle}]])
(ns konditorei.routes.tree
[konditorei.layout :as layout]
[ :as log]
[konditorei.middleware :as middleware]
[konditorei.speechcake :as speechcake]
[konditorei.util :as util]))
(defn render-tree [request]
(let [key (-> request :path-params :key)
tree (speechcake/tree key)
readme (speechcake/readme)]
(log/debug key tree (util/breadcrumbs-to key))
(layout/render request "tree.html"
{:breadcrumbs (util/breadcrumbs-to key)
:tree tree
:key key
:readme readme})))
(defn tree-routes []
{:middleware [middleware/wrap-csrf
["*key" {:get render-tree}]])
(ns konditorei.speechcake
(:require [clj-http.client :as client]
[clojure.string :as str]
[ :as json]))
(def SPEECHCAKE_URL "http://localhost:8080/")
(defn url [path]
(str SPEECHCAKE_URL (str/join "/" path)))
(defn- decode [req]
(json/read-str (:body req) :key-fn keyword))
(defn tree [key]
(-> (url ["tree" key]) client/get decode))
(defn bundle [key]
(-> (url ["bundle" key]) client/get decode))
(defn readme []
(-> (url ["readme"]) client/get :body))
(defn update-object [key data]
(-> (url ["update" key]) (client/post data) decode))
(ns konditorei.util
(:require [clojure.string :as str]))
(defn breadcrumbs-to [key]
(loop [xs (->> (str/split