add plugin

This commit is contained in:
jem 2019-11-23 12:43:57 +01:00
parent f1ff72ecb5
commit 254b19cd00
4 changed files with 107 additions and 0 deletions

8
src/cryogen/core.clj Normal file
View file

@ -0,0 +1,8 @@
(ns cryogen.core
(:require [cryogen-core.compiler :refer [compile-assets-timed]]
[cryogen-core.plugins :refer [load-plugins]]))
(defn -main []
(load-plugins)
(compile-assets-timed)
(System/exit 0))

54
src/cryogen/server.clj Normal file
View file

@ -0,0 +1,54 @@
(ns cryogen.server
(:require [compojure.core :refer [GET defroutes]]
[compojure.route :as route]
[ring.util.response :refer [redirect resource-response]]
[ring.util.codec :refer [url-decode]]
[cryogen-core.watcher :refer [start-watcher!]]
[cryogen-core.plugins :refer [load-plugins]]
[cryogen-core.compiler :refer [compile-assets-timed read-config]]
[cryogen-core.io :refer [path]]))
(defn init []
(load-plugins)
(compile-assets-timed)
(let [ignored-files (-> (read-config) :ignored-files)]
(start-watcher! "resources/templates" ignored-files compile-assets-timed)))
(defn wrap-subdirectories
[handler]
(fn [request]
(let [req-uri (.substring (url-decode (:uri request)) 1)
res-path (path req-uri (when (:clean-urls? (read-config)) "index.html"))]
(or (resource-response res-path {:root "public"})
(handler request)))))
(defroutes routes
(GET "/" [] (redirect (let [config (read-config)]
(path (:blog-prefix config) "/"
(when-not (:clean-urls? config) "index.html")))))
(route/resources "/")
(route/not-found "Page not found"))
(def handler (wrap-subdirectories routes))
;the following 2 function will create scripts for:
; checkout repository
; cronjob for pulling from repository and copying to document root
(defn pull-script-setup
[document-root user repository-url git-directory source-files-location]
(let [copy-command (str "cp -pr " git-directory source-files-location " " document-root)]
["#!/bin/bash"
(str "git clone -C " git-directory " " repository-url)
(str "echo " (str "0 * * * * " user " " "git pull -C " repository-url) " && " copy-command " > /etc/crontab")
]
))
;(defn pull-script-setup-stevedore
; [document-root user repository-url git-directory source-files-location]
; (let [copy-command (str "cp -pr " git-directory source-files-location " " document-root)]
; (stevedore/with-script-language :pallet.stevedore.bash/bash
; (stevedore/with-source-line-comments false
; (stevedore/script
; ("git clone -C" ~git-directory ~repository-url)
; (str "echo " (str "0 * * * * " ~user " " "git pull -C " ~repository-url) " && " ~copy-command " > /etc/crontab")
; )))))

25
src/dda/filter_plugin.clj Normal file
View file

@ -0,0 +1,25 @@
(ns dda.filter-plugin
(:require
[selmer.filters :as filters]
[clojure.string :as s]))
(defn filter-feature [pages]
(let [result (filter #(:feature? %) pages)]
(sort-by :page-index result)))
(defn filter-navbar [pages]
(let [result (filter #(:navbar? %) pages)]
(sort-by :page-index result)))
(defn filter-sidebar [pages]
(let [result (filter #(not (:navbar? %)) pages)]
(sort-by :page-index result)))
(defn filter-even [number]
(even? number))
(defn init []
(filters/add-filter! "filter-feature" filter-feature)
(filters/add-filter! "filter-navbar" filter-navbar)
(filters/add-filter! "filter-sidebar" filter-sidebar)
(filters/add-filter! "even?" filter-even))

View file

@ -0,0 +1,20 @@
(ns dda.filter-plugin-test
(:require
[clojure.test :refer :all]
[dda.filter-plugin :as sut]))
(deftest test-filter-flat
(testing
(is (= 1
(count (sut/filter-sidebar '({})))
))
(is (= 1
(count (sut/filter-sidebar '({:other true})))
))
(is (= 1
(count (sut/filter-sidebar '({:navbar? false})))
))
(is (= 0
(count (sut/filter-sidebar '({:navbar? true})))
))
))