aboutsummaryrefslogtreecommitdiffstats
path: root/util/generate-hooks-index/src/generate_hooks_index
diff options
context:
space:
mode:
authorken restivo <ken@restivo.org>2015-11-03 21:15:49 -0800
committerken restivo <ken@restivo.org>2015-11-03 21:15:49 -0800
commitd9c7b39b884511b38ca339d032f4688b86472af1 (patch)
tree5a17253a8a1c4965ac0bc4d643381a4966e93438 /util/generate-hooks-index/src/generate_hooks_index
parent380e3e64cb88c3456e279a9f55a65d5049859159 (diff)
downloadvolse-hubzilla-d9c7b39b884511b38ca339d032f4688b86472af1.tar.gz
volse-hubzilla-d9c7b39b884511b38ca339d032f4688b86472af1.tar.bz2
volse-hubzilla-d9c7b39b884511b38ca339d032f4688b86472af1.zip
Commit the tool used to generate the hooks docs.
Diffstat (limited to 'util/generate-hooks-index/src/generate_hooks_index')
-rw-r--r--util/generate-hooks-index/src/generate_hooks_index/core.clj82
1 files changed, 82 insertions, 0 deletions
diff --git a/util/generate-hooks-index/src/generate_hooks_index/core.clj b/util/generate-hooks-index/src/generate_hooks_index/core.clj
new file mode 100644
index 000000000..ac9e72f90
--- /dev/null
+++ b/util/generate-hooks-index/src/generate_hooks_index/core.clj
@@ -0,0 +1,82 @@
+(ns generate-hooks-index.core
+ (:require [clojure.string :as str]
+ [hiccup.core :as h]
+ [taoensso.timbre :as log]
+ [clojure.java.shell :as sh])
+ (:gen-class))
+
+(log/set-level! :info)
+
+(defn clean-fn-arg
+ [s]
+ (-> s
+ (str/replace #"'" "")
+ (str/replace #"\"" "")
+ str/trim))
+
+(defn check-fn-args
+ [xs]
+ (when (-> xs first empty?)
+ (throw (Exception. "empty function")))
+ (map clean-fn-arg xs))
+
+
+(defn get-fn-arg
+ [s]
+ (->> s
+ (re-matches #".*call_hooks\((.+)\,(.*)\).*")
+ rest
+ check-fn-args))
+
+
+
+(defn fix-path
+ [path file]
+ (str/replace file path ""))
+
+
+(defn show-hooks
+ [path]
+ (for [s (-> (sh/sh "rgrep" "call_hooks" path)
+ :out
+ str/split-lines)
+ :let [[file hook] (str/split s #"\t*:")]]
+ (try
+ (-> (zipmap [:function :arg] (get-fn-arg hook))
+ (assoc :file (fix-path path file)))
+ (catch Exception e
+ (log/debug e s file hook)))))
+
+
+
+(defn hiccupy
+ [path]
+ [:div
+ [:h3 "Hooks"]
+ [:p "Generated " (-> (java.util.Date.) str)]
+ [:table
+ [:tr (map #(vector :td %) ["Function" "Source File" "Arg"])]
+ (for [{:keys [function arg file]}
+ (->> path
+ show-hooks
+ (sort-by :function))]
+ [:tr (map #(vector :td (h/h %)) [function file arg])])]])
+
+
+(defn make-hook-docs
+ [path-to-hubzillla]
+ (->> path-to-hubzillla
+ hiccupy
+ h/html
+ (spit (str path-to-hubzillla "doc/hooks.html"))))
+
+
+(defn -main
+ [& args]
+ (log/info "Starting..")
+ (make-hook-docs (str (System/getProperty "user.dir") "/../../"))
+ (log/info "Done!")
+ (System/exit 0))
+
+
+