Skip to content

Commit

Permalink
integrate last build info into sidebar; fix #243
Browse files Browse the repository at this point in the history
this also includes a refactoring that opens up ways to pass data into
the main render functions without further diluting the meaning of the
cache bundle
  • Loading branch information
martinklepsch committed Apr 5, 2019
1 parent 468cb70 commit f044750
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 37 deletions.
43 changes: 20 additions & 23 deletions src/cljdoc/render.clj
Expand Up @@ -24,29 +24,29 @@
(format "%s not implemented, sorry" page-type))

(defmethod render :artifact/version
[_ route-params {:keys [version-entity] :as cache-bundle}]
(->> (layout/layout
;; TODO on mobile this will effectively be rendered as a blank page
;; We could instead show a message and the namespace tree.
{:top-bar (layout/top-bar version-entity (-> cache-bundle :version :scm :url))
:main-sidebar-contents (sidebar/sidebar-contents route-params cache-bundle)})
(layout/page {:title (str (util/clojars-id version-entity) " " (:version version-entity))
:description (layout/artifact-description
version-entity
(-> cache-bundle :version :pom :description))})))
[_ route-params {:keys [cache-bundle pom last-build]}]
(let [version-entity (:version-entity cache-bundle)]
(->> (layout/layout
;; TODO on mobile this will effectively be rendered as a blank page
;; We could instead show a message and the namespace tree.
{:top-bar (layout/top-bar version-entity (-> cache-bundle :version :scm :url))
:main-sidebar-contents (sidebar/sidebar-contents route-params cache-bundle last-build)})
(layout/page {:title (str (util/clojars-id version-entity) " " (:version version-entity))
:description (layout/artifact-description version-entity (:description pom))}))))

(defmethod render :artifact/doc
[_ route-params {:keys [version-entity] :as cache-bundle}]
[_ route-params {:keys [cache-bundle pom last-build]}]
(assert (:doc-slug-path route-params))
(let [doc-slug-path (:doc-slug-path route-params)
(let [version-entity (:version-entity cache-bundle)
doc-slug-path (:doc-slug-path route-params)
doc-tree (doctree/add-slug-path (-> cache-bundle :version :doc))
doc-p (->> doc-tree
doctree/flatten*
(filter #(= doc-slug-path (:slug-path (:attrs %))))
first)
[doc-type contents] (doctree/entry->type-and-content doc-p)
top-bar-component (layout/top-bar version-entity (-> cache-bundle :version :scm :url))
sidebar-contents (sidebar/sidebar-contents route-params cache-bundle)]
sidebar-contents (sidebar/sidebar-contents route-params cache-bundle last-build)]
;; If we can find an article for the provided `doc-slug-path` render that article,
;; if there's no article then the page should display a list of all child-pages
(->> (if doc-type
Expand All @@ -73,14 +73,13 @@
:canonical-url (some->> (bundle/more-recent-version cache-bundle)
(merge route-params)
(routes/url-for :artifact/doc :path-params))
:description (layout/artifact-description
version-entity
(-> cache-bundle :version :pom :description))}))))
:description (layout/artifact-description version-entity (:description pom))}))))

(defmethod render :artifact/namespace
[_ route-params {:keys [version-entity] :as cache-bundle}]
[_ route-params {:keys [cache-bundle pom last-build]}]
(assert (:namespace route-params))
(let [ns-emap route-params
(let [version-entity (:version-entity cache-bundle)
ns-emap route-params
defs (bundle/defs-for-ns-with-src-uri cache-bundle (:namespace ns-emap))
[[dominant-platf] :as platf-stats] (api/platform-stats defs)
ns-data (bundle/get-namespace cache-bundle (:namespace ns-emap))
Expand All @@ -89,7 +88,7 @@
(->> (if ns-data
(layout/layout
{:top-bar top-bar-component
:main-sidebar-contents (sidebar/sidebar-contents route-params cache-bundle)
:main-sidebar-contents (sidebar/sidebar-contents route-params cache-bundle last-build)
:vars-sidebar-contents (when (seq defs)
[(api/platform-support-note platf-stats)
(api/definitions-list ns-emap defs {:indicate-platforms-other-than dominant-platf})])
Expand All @@ -98,17 +97,15 @@
:defs defs})})
(layout/layout
{:top-bar top-bar-component
:main-sidebar-contents (sidebar/sidebar-contents route-params cache-bundle)
:main-sidebar-contents (sidebar/sidebar-contents route-params cache-bundle last-build)
:content (api/sub-namespace-overview-page {:ns-entity ns-emap
:namespaces (bundle/namespaces cache-bundle)
:defs (bundle/all-defs cache-bundle)})}))
(layout/page {:title (str (:namespace ns-emap) "" (util/clojars-id version-entity) " " (:version version-entity))
:canonical-url (some->> (bundle/more-recent-version cache-bundle)
(merge route-params)
(routes/url-for :artifact/namespace :path-params))
:description (layout/artifact-description
version-entity
(-> cache-bundle :version :pom :description))}))))
:description (layout/artifact-description version-entity (:description pom))}))))

(comment

Expand Down
5 changes: 0 additions & 5 deletions src/cljdoc/render/layout.clj
Expand Up @@ -166,11 +166,6 @@
:else
[:a.f6.link.blue {:href (util/github-url :userguide/scm-faq)} "SCM info missing"])]])

(defn upgrade-notice [{:keys [version] :as version-map}]
[:a.link {:href (routes/url-for :artifact/version :path-params version-map)}
[:div.bg-washed-yellow.pa2.f7.mb4.dark-gray.lh-title
"A newer version " [:span.blue "(" version ")"] " for this library is available"]])

;; Responsive Layout -----------------------------------------------------------

(def r-main-container
Expand Down
34 changes: 32 additions & 2 deletions src/cljdoc/render/sidebar.clj
@@ -1,11 +1,38 @@
(ns cljdoc.render.sidebar
(:require [cljdoc.util :as util]
[cljdoc.doc-tree :as doctree]
[cljdoc.server.routes :as routes]
[cljdoc.server.build-log :as build-log]
[cljdoc.render.layout :as layout]
[cljdoc.render.articles :as articles]
[cljdoc.render.api :as api]
[cljdoc.bundle :as bundle]))

(defn upgrade-notice [{:keys [version] :as version-map}]
[:a.db.link.bg-washed-yellow.pa2.f7.mb3.dark-gray.lh-title
{:href (routes/url-for :artifact/version :path-params version-map)}
"A newer version " [:span.blue "(" version ")"] " for this library is available"])

(defn last-build-warning
"If the provided build had problems, render a warning and link to the respective build."
[build]
(assert build)
(let [render-error (fn render-buold-warning [msg]
[:a.db.mb3.pa2.bg-washed-red.br2.f7.red.b.lh-copy.link
{:href (str "/builds/" (:id build))}
msg " "
[:span.underline.nowrap "build #" (:id build)]])]
(cond
(and (not (build-log/api-import-successful? build))
(not (build-log/git-import-successful? build)))
(render-error "API & Git import failed in")

(not (build-log/api-import-successful? build))
(render-error "API import failed in")

(not (build-log/git-import-successful? build))
(render-error "Git import failed in"))))

(defn sidebar-contents
"Render a sidebar for a documentation page.
Expand All @@ -14,7 +41,7 @@
If articles or namespaces are missing for a project there will be little messages pointing
users to the relevant documentation or GitHub to open an issue."
[route-params {:keys [version-entity] :as cache-bundle}]
[route-params {:keys [version-entity] :as cache-bundle} last-build]
(let [doc-slug-path (:doc-slug-path route-params)
doc-tree (doctree/add-slug-path (-> cache-bundle :version :doc))
split-doc-tree ((juxt filter remove)
Expand All @@ -24,7 +51,10 @@
doc-tree-with-rest (second split-doc-tree)]
[;; Upgrade notice
(if-let [newer-v (bundle/more-recent-version cache-bundle)]
(layout/upgrade-notice newer-v))
(upgrade-notice newer-v))

(when last-build
(last-build-warning last-build))

;; Special documents (Readme & Changelog)
(when (seq readme-and-changelog)
Expand Down
11 changes: 4 additions & 7 deletions src/cljdoc/server/pedestal.clj
Expand Up @@ -62,7 +62,9 @@
(assoc ctx :response {:status 302, :headers {"Location" location}}))

(if cache-bundle
(pu/ok-html ctx (html/render page-type path-params cache-bundle))
(pu/ok-html ctx (html/render page-type path-params {:cache-bundle cache-bundle
:pom (::pom-info ctx)
:last-build (::last-build ctx)}))
(let [resp {:status 404
:headers {"Content-Type" "text/html"}
:body (str (render-build-req/request-build-page path-params))}]
Expand Down Expand Up @@ -111,12 +113,7 @@
bundle-params (assoc params :dependency-version-entities (:dependencies pom-data))]
(log/info "Loading artifact cache bundle for" params (:cache-bundle ctx))
(if (storage/exists? store params)
(-> ctx
(assoc :cache-bundle (storage/bundle-docs store bundle-params))
;; Injecting things into the cache bundle like this is a bit of a hack and really
;; we should have one entry point that takes care of all the data sources that
;; contribute to the cache bundle.
(assoc-in [:cache-bundle :version :pom] pom-data))
(assoc ctx :cache-bundle (storage/bundle-docs store bundle-params))
ctx)))})

(defn last-build-loader
Expand Down

0 comments on commit f044750

Please sign in to comment.