added hierarchic sidbar-pages & refactored namesspace.

This commit is contained in:
Michael Jerger 2017-02-09 08:52:42 +01:00
parent d8f86e0414
commit 4f9ac917ae
3 changed files with 13 additions and 13 deletions

View file

@ -15,7 +15,7 @@
[cryogen-core.sitemap :as sitemap]
[clojure.inspector :as inspector]
[cryogen-core.toc :as toc]
[cryogen-core.navbar-model :as navbar-model])
[cryogen-core.hierarchic :as hierarchic])
(:import java.util.Locale))
(cache-off!)
@ -512,11 +512,11 @@
:latest-posts latest-posts
:navbar-pages (cond
(= navbar-model :flat) navbar-pages
(= navbar-model :hierarchic) (navbar-model/build-nav-map navbar-pages)
(= navbar-model :hierarchic) (hierarchic/build-hierarchic-map navbar-pages)
)
:sidebar-pages (cond
(= navbar-model :flat) sidebar-pages
;(= navbar-model :hierarchic) (build-nav-map navbar-pages)
(= navbar-model :hierarchic) (hierarchic/build-hierarchic-map sidebar-pages)
)
:home-page (if home-page
home-page

View file

@ -1,4 +1,4 @@
(ns cryogen-core.navbar-model
(ns cryogen-core.hierarchic
(:require
[clojure.string :as s]))
@ -18,7 +18,7 @@
(filter #(s/starts-with? (:uri %) clean-uri) pages))
)
(defn build-nav-map-level
(defn build-hierarchic-level
"builds one level of nav-map and recurs to next level."
[parent-uri pages]
(let [current-level (+ 1 (uri-level parent-uri))
@ -32,12 +32,12 @@
(if (empty? child-pages)
page-on-level
(merge page-on-level
{:children (build-nav-map-level (:uri page-on-level) child-pages)}))) pages-on-level))
{:children (build-hierarchic-level (:uri page-on-level) child-pages)}))) pages-on-level))
))
(defn build-nav-map
(defn build-hierarchic-map
"builds a nav-map from pages"
[pages]
(let [sorted-pages (sort-by :uri pages)]
(build-nav-map-level "/pages/" sorted-pages)
(build-hierarchic-level "/pages/" sorted-pages)
))

View file

@ -1,7 +1,7 @@
(ns cryogen-core.navbar-model-test
(ns cryogen-core.hierarchic-test
(:require
[clojure.test :refer :all]
[cryogen-core.navbar-model :as sut]))
[cryogen-core.hierarchic :as sut]))
(defn- page [uri page-index]
{:uri uri
@ -42,7 +42,7 @@
(is (= 6 (count (sut/filter-pages-for-uri "/pages/nav1.html" pages-dirty))))
))
(deftest test-navmap-pages
(deftest test-hierarchic-pages
(testing
"No pages or posts nothing to copy"
(let [expected-clean [(enhanced-page
@ -65,8 +65,8 @@
)]
]
(is (= expected-clean
(sut/build-nav-map pages-clean)))
(sut/build-hierarchic-map pages-clean)))
(is (= expected-dirty
(sut/build-nav-map pages-dirty)))
(sut/build-hierarchic-map pages-dirty)))
)
))