Skip to content

Instantly share code, notes, and snippets.

@plexus
Created July 10, 2020 08:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plexus/603f8a5202df5ca10166fc19afde5f22 to your computer and use it in GitHub Desktop.
Save plexus/603f8a5202df5ca10166fc19afde5f22 to your computer and use it in GitHub Desktop.
(ns lambdaisland.project-discovery.layout
(:require [net.cgrand.enlive-html :as enlive-html]
[lambdaisland.ornament :as ornament]))
(defn default-layout [{:keys [title content]}]
[:html {:lang "en"}
[:head
[:meta {:charset "UTF-8"}]
[:title title]
[:meta {:name "viewport" :content "width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"}]
[:link {:rel "stylesheet" :href "/css/project_discovery.css"}]
[:link {:rel "stylesheet" :href "https://use.typekit.net/byu3igw.css"}]
[:style {:type "text/css"} (ornament/defined-styles)]] ;; TODO in production compile this to a file on disk
[:body
content
;; Figwheel compile target, mainly so we get CSS hot code reloading
[:script {:type "text/javascript" :src "/js/project_discovery.js"}]]])
(defn render [view view-data]
(let [content (view view-data)
layout (or (:layout view-data)
(:layout (meta content))
default-layout)
title (or (:title view-data)
(:title (meta content))
"Lambda Island")]
(enlive-html/html (layout (assoc view-data :content content :title title)))))
(ns lambdaisland.project-discovery.episode.routes
(:require [lambdaisland.episodes.data :as episode-data]
[lambdaisland.project-discovery.episode.views :as views]
[lambdaisland.project-discovery.layout :as layout]
[io.pedestal.log :as log]))
(defn GET-episode [req]
(let [{:keys [path-params]} req
{:keys [slug]} path-params
episode (episode-data/episode req slug)
view (if (:visible? episode)
views/episode-html
views/preview-html)]
{:html (layout/render view {:episode episode})}))
(ns lambdaisland.project-discovery.episode.views
(:require [clj-time.coerce :as coerce-time]
[lambdaisland.factories :as factories]
[lambdaisland.project-discovery.cards :refer [defcard]]
[lambdaisland.rubylibs.kramdown :as kramdown]
[lambdaisland.util :as util]))
(defn navigation []
[:a {:href ""} "Back"])
(defn screencast [embed-html]
(util/html->hiccup embed-html))
;; (defn parse-old-title [old-ep-name]
;; {:title ""
;; :ep-number 23
;; :collection 3
;; :part 2})
(defn about [created-on description name]
(let [last-updated (coerce-time/to-date created-on)]
[:article
[:header
[:h1.about-ep--title name]
[:span.about-ep--series-part "Part one on Interceptors"]] ;fix
[:p.about-ep--copy description]
[:footer.about-ep--details
[:small [:date last-updated]]]]))
#_(defn toc)
#_(defn external)
(defn collection []
[:section.series-nav
[:p.series-nav--title "Interceptors"]
[:ol
[:li.series-nav--thumbnail
(util/html->hiccup "<iframe width=\"888\" height=\"500\" src=\"https://www.youtube.com/embed/DWcJFNfaw9c\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>")]
[:li.series-nav--thumbnail
(util/html->hiccup "<iframe width=\"888\" height=\"500\" src=\"https://www.youtube.com/embed/DWcJFNfaw9c\" frameborder=\"0\" allow=\"accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen></iframe>")]]])
#_(defn namespaces)
#_(defn docstrings)
#_(defn cheat-sheet)
(defn notes [notes]
(kramdown/md->hiccup notes))
#_(defn transcript)
#_(defn comments)
(defn preview-html [{:keys [episode]}]
^{:layout/title "Preview"}
[:div
[:h1 "Preview..."]
[:pre (util/pprint-str episode)]])
(defn episode-html [{:keys [episode]}]
^{:layout/title "Episode"}
(let [{:keys [created-on description name show-notes video]} episode]
[:main
(navigation)
(screencast (:embed-html video))
(about episode)
(collection)
(notes show-notes)
[:pre (util/pprint-str episode)]]))
(defcard about-card
(about {:created-on #inst "2017-10-17T15:33:12.000Z"
:title "37. Datomic Quickstart part 2"
:description "Datomic is a database based on the same principles that
underly the design of Clojure itself. Learn "}))
(defcard about-long-title-card
(about {:created-on #inst "2017-10-17T15:33:12.000Z"
:title "37. Datomic Quickstart part 2 lfllfelwfl fwllfewlfwel fwelllwf"
:description "Datomic is a database based on the same principles that
underly the design of Clojure itself. Learn "}))
(defcard episode-card
(episode-html {:episode (factories/rand-episode)}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment