diff --git a/docs/dev/design/bootstrap-theme.html b/docs/dev/design/bootstrap-theme.html index a0451c6..e3b0df5 100644 --- a/docs/dev/design/bootstrap-theme.html +++ b/docs/dev/design/bootstrap-theme.html @@ -1340,5 +1340,3 @@ - - diff --git a/docs/dev/design/example-2-column.html b/docs/dev/design/example-2-column.html index ed9f512..e344b19 100644 --- a/docs/dev/design/example-2-column.html +++ b/docs/dev/design/example-2-column.html @@ -230,5 +230,3 @@

- - diff --git a/docs/dev/index.html b/docs/dev/index.html index 417248d..c7e3017 100644 --- a/docs/dev/index.html +++ b/docs/dev/index.html @@ -303,5 +303,3 @@

Community

- - diff --git a/priv/make/gen.mk b/priv/make/gen.mk index e0c3fdc..7f9a680 100644 --- a/priv/make/gen.mk +++ b/priv/make/gen.mk @@ -53,7 +53,7 @@ serve-header: @echo serve-only: - @ERL_LIBS=$(ERL_LIBS) erl -s docs-cli httpd -noshell + @ERL_LIBS=$(ERL_LIBS) erl -s docs-cli start-httpd -noshell serve: compile serve-header serve-only diff --git a/rebar.config b/rebar.config index c56e452..cb667a6 100644 --- a/rebar.config +++ b/rebar.config @@ -15,9 +15,9 @@ {deps, [ {lfe, {git, "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/rvirding/lfe.git", {branch, "develop"}}}, {poise, {git, "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/lfex/poise.git", {branch, "master"}}}, - {logjam, {git, "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/lfex/logjam.git", {tag, "0.5.0-rc2"}}}, + {logjam, {git, "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/lfex/logjam.git", {tag, "0.5.0-rc3"}}}, {erlydtl, {git, "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/erlydtl/erlydtl.git", {tag, "0.12.1"}}}, - {lcfg, {git, "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/lfex/lcfg.git", {tag, "0.5.0-rc2"}}}, + {lcfg, {git, "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/lfex/lcfg.git", {tag, "0.5.0-rc3"}}}, {barista, {git, "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/lfe-mug/barista.git", {tag, "0.2.2"}}}, {inotify, {git, "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/erlsci/inotify.git", {branch, "master"}}}, {ltest, {git, "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/lfex/ltest.git", {tag, "0.10.0-rc6"}}} @@ -27,7 +27,7 @@ {'lfe-compile', {git, "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/lfe-rebar3/compile.git", {tag, "0.8.0-rc3"}}}, {rebar3_erlydtl_plugin, {git, "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/tsloughter/rebar3_erlydtl_plugin.git", {branch, "master"}}}, - {'lfe-test', {git, "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/lfe-rebar3/test.git", {tag, "0.4.0-rc2"}}} + {'lfe-test', {git, "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/lfe-rebar3/test.git", {tag, "0.4.0-rc4"}}} ]}. {provider_hooks, [{pre, [{compile, {lfe, compile}}, diff --git a/src/docs-cli.lfe b/src/docs-cli.lfe index 8d895ea..6728171 100644 --- a/src/docs-cli.lfe +++ b/src/docs-cli.lfe @@ -7,22 +7,19 @@ (docs:stop)) (defun gen-stable () - (do-cmd #'docs:gen/0)) + (do-cmd #'docs-gen:run-stable/0)) (defun gen-dev () - (do-cmd #'docs:gen-dev/0)) + (do-cmd #'docs-gen:run-dev/0)) -(defun httpd () - (do-cmd #'docs:httpd/0)) +(defun start-httpd () + (do-cmd #'docs-httpd:start/0)) (defun gen-dev-httpd () (do-cmd (lambda () - (docs:gen-dev) - (docs:httpd)))) + (docs-gen:run-dev) + (docs-httpd:start)))) (defun gen-dev-watch () - (do-cmd - (lambda () - (docs:gen-dev) - (docs-watcher:start)))) + (docs-watcher:start)) diff --git a/src/docs-compiler.lfe b/src/docs-compiler.lfe new file mode 100644 index 0000000..82f55d8 --- /dev/null +++ b/src/docs-compiler.lfe @@ -0,0 +1,102 @@ +(defmodule docs-compiler + (export all)) + +(defun lfe-compile (path file) + (let ((outdir (get-ebin-dir file)) + (mod-name (get-module-name file)) + (filename (filename:join path file))) + (code:purge mod-name) + (logjam:info "Recompiling LFE file ~p ..." `(,filename)) + (case (lfe_comp:file filename `(#(outdir ,outdir))) + (`#(ok ,_) + (logjam:debug "Success.") + (logjam:debug "Reloading module ~p ..." `(,mod-name)) + (case (code:load_file mod-name) + (`#(module ,_) (logjam:debug "Success.")) + (err (logjam:debug "Couldn't reload module: ~p" `(,err))))) + (err (logjam:error "Couldn't compile file: ~p" `(,err)))))) + +(defun lfe + ((_ "docs.app.src" _) + 'skipping) + ((path file `#(,source-dir ,watcher)) + (inotify:unwatch source-dir) + (lfe-compile path file) + (inotify:watch source-dir watcher))) + +(defun erlydtl-compile (path file) + (let* ((opts (get-erlydtl-opts)) + (outdir (get-ebin-dir file opts)) + (all-opts (++ opts `(#(out_dir ,outdir)))) + (suffix (get-tmpl-suffix opts)) + (mod-name (get-module-name file opts)) + (filename (filename:join path file))) + (code:purge mod-name) + (logjam:debug "Recompiling ErlyDTL file: ~p" `(,filename)) + (logjam:debug "All compile opts: ~p~n" `(,all-opts)) + (case (erlydtl:compile_file filename mod-name all-opts) + (`#(ok ,_mod ,_msgs) + (logjam:debug "Success.") + (logjam:debug "Reloading module ~p ..." `(,mod-name)) + ;; Reloads are noisy with logs, so let's shutdown the logger until + ;; we've finished + (logjam:set-level 'critical) + (case (code:load_file mod-name) + (`#(module ,_) (logjam:debug "Success.")) + (err (logjam:debug "Couldn't reload module: ~p" `(,err)))) + (logjam:set-level 'info)) + (err (logjam:error "Couldn't compile file: ~p" `(,err)))))) + +(defun erlydtl + ((path file `#(,template-dir ,watcher)) + (let ((filename (filename:join path file)) + (wildcard (filename:join path "*.html"))) + (inotify:unwatch template-dir) + (erlydtl-compile path file) + ;; Now let's compile all the othter templates, since they might + ;; depend upon the once that's just changed + (lists:map + (lambda (filename) + (erlydtl-compile path (filename:basename filename))) + (lists:subtract (filelib:wildcard wildcard) `(,filename))) + ;; Finally, re-render the pages with the recompiled templates + (logjam:info "Re-rendering pages ...") + (docs-gen:run-dev) + (inotify:watch template-dir watcher) + (docs-httpd:restart)))) + +(defun get-module-name (filename) + (clj:-> filename + (filename:rootname) + (list_to_atom))) + +(defun get-module-name (filename opts) + (clj:->> opts + (get-tmpl-suffix) + (++ (filename:rootname filename)) + (list_to_atom))) + +(defun get-ebin-dir (filename) + (case (clj:-> filename + (get-module-name) + (code:which) + (filename:dirname)) + ("." (get-ebin-dir "docs.lfe")) + (dir dir))) + +(defun get-ebin-dir (filename opts) + (case (clj:->> opts + (get-module-name filename) + (code:get_object_code) + (element 3) + (filename:dirname)) + ("." (get-ebin-dir "docs.lfe" opts)) + (dir dir))) + +(defun get-erlydtl-opts () + (case (file:consult "rebar.config") + (`#(ok ,data) + (proplists:get_value 'erlydtl_opts data)))) + +(defun get-tmpl-suffix (opts) + (proplists:get_value 'module_ext opts)) diff --git a/src/docs-dev.lfe b/src/docs-dev.lfe deleted file mode 100644 index 54b558a..0000000 --- a/src/docs-dev.lfe +++ /dev/null @@ -1,19 +0,0 @@ -(defmodule docs-dev - (export all)) - -(defun handler (request) - (logjam:info "Handling request for: ~s" - `(,(element 8 request))) - request) - -(defun serve () - (logjam:info "Starting HTTP server ...") - (barista:start #'handler/1)) - -(defun stop-server () - (logjam:warn "Stopping HTTP server ...") - (barista:stop)) - -(defun restart-server () - (stop-server) - (serve)) diff --git a/src/docs-gen.lfe b/src/docs-gen.lfe index c106d47..b7576b6 100644 --- a/src/docs-gen.lfe +++ b/src/docs-gen.lfe @@ -1,7 +1,7 @@ (defmodule docs-gen (export all)) -(defun run () +(defun run-stable () (poise:generate (docs-routes:site))) (defun run-dev () diff --git a/src/docs-httpd.lfe b/src/docs-httpd.lfe new file mode 100644 index 0000000..fa9c445 --- /dev/null +++ b/src/docs-httpd.lfe @@ -0,0 +1,30 @@ +(defmodule docs-httpd + (export all)) + +(defun handler (request) + (logjam:info "Handling request for: ~s" + `(,(element 8 request))) + request) + +(defun -start () + (application:ensure_all_started 'inets) + (barista:start #'handler/1)) + +(defun -stop () + (barista:stop) + ;; XXX update barista to do the following + (erlang:unregister 'lmug-handler) + (application:stop 'inets)) + +(defun start () + (logjam:info "Starting HTTP server ...") + (-start)) + +(defun stop () + (logjam:info "Stopping HTTP server ...") + (-stop)) + +(defun restart () + (logjam:info "Restarting HTTP server ...") + (-stop) + (-start)) diff --git a/src/docs-watcher.lfe b/src/docs-watcher.lfe index 1d14af6..fadaf36 100644 --- a/src/docs-watcher.lfe +++ b/src/docs-watcher.lfe @@ -2,71 +2,54 @@ (export all)) (defun source-data () - `#("src" ,#'lfe-watcher/1)) + `#("src" ,#'docs-watcher:lfe-watcher/1)) -(defun templates-data () - `#("priv/templates" ,#'erlydtl-watcher/1)) +(defun template-data () + `#("priv/templates" ,#'docs-watcher:erlydtl-watcher/1)) (defun default-watch-data () - `(,(templates-data) - ,(source-data))) - -(defun lfe-compiler (path file) - (let ((`#(,source-dir ,watcher) (source-data)) - (outdir (get-ebin-dir file)) - (mod-name (get-module-name file)) - (filename (filename:join path file))) - (inotify:unwatch source-dir) - (code:purge mod-name) - (logjam:info "Recompiling LFE file ~p ..." `(,filename)) - (case (lfe_comp:file filename `(#(outdir ,outdir))) - (`#(ok ,_) - (logjam:info "Success.") - (logjam:info "Reloading module ~p ..." `(,mod-name)) - (case (code:load_file mod-name) - (`#(module ,_) (logjam:info "Success.")) - (err (logjam:error "Couldn't reload module: ~p" `(,err))))) - (err (logjam:error "Couldn't compile file: ~p" `(,err)))) - (inotify:watch source-dir watcher))) - -(defun erlydtl-compiler (filename) - (logjam:info "Recompiling ErlyDTL file: ~p" `(,filename)) - (docs:httpd-restart)) + `(,(source-data) + ,(template-data))) (defun lfe-watcher ((`#(,path file close_write ,fd ,file)) - (lfe-compiler path file)) + (docs-compiler:lfe path file (source-data))) ((args) - (logjam:debug "LFE watcher event: ~p" `(,args)))) + (logjam:debug "Unhandled LFE watcher event: ~p" `(,args)))) (defun erlydtl-watcher ((`#(,path file close_write ,fd ,file)) - (erlydtl-compiler (filename:join path file))) + (docs-compiler:erlydtl path file (template-data))) ((args) - (logjam:debug "ErlyDTL watcher event: ~p" `(,args)))) + (logjam:debug "Unhandled ErlyDTL watcher event: ~p" `(,args)))) (defun start () (start (default-watch-data))) (defun start (watch-data) - (docs:start) - (docs:httpd) + (logjam:start) + (docs-gen:run-dev) + (docs-httpd:start) (application:ensure_all_started 'inotify) + (application:ensure_all_started 'docs) + (docs:start-gen-server) (case (lists:map (match-lambda ((`#(,path ,func)) - (logjam:debug "Watching path: ~p with function: ~p" + (logjam:info "Watching path: ~p with function: ~p" `(,path ,func)) (inotify:watch path func))) watch-data) ('(ok ok) 'ok) (err (logjam:error err)))) -(defun get-module-name (filename) - (clj:-> filename - (filename:rootname) - (list_to_atom))) - -(defun get-ebin-dir (filename) - (clj:-> filename - (get-module-name) - (code:which) - (filename:dirname))) +(defun stop () + (docs:stop-gen-server) + (application:stop 'docs) + (application:stop 'ets_manager) + (application:stop 'inotify) + (docs-httpd:stop) + (logjam:stop)) + +(defun restart () + (stop) + (timer:sleep 500) + (start)) diff --git a/src/docs.app.src b/src/docs.app.src index 48bd959..4f6e45f 100644 --- a/src/docs.app.src +++ b/src/docs.app.src @@ -1,6 +1,5 @@ %% -*- erlang -*- -{application, docs, - [ +{application, docs, [ %% A quick description of the application. {description, "Documentation source for Lisp Flavoured Erlang."}, @@ -8,13 +7,13 @@ {vsn, "3.1.0-dev"}, %% All modules used by the application. - {modules, - [ + {modules, [ docs, 'docs-cfg', 'docs-cli', + 'docs-compiler', 'docs-data', - 'docs-dev', + 'docs-httpd', 'docs-gen', 'docs-pages', 'docs-routes' @@ -26,12 +25,10 @@ %% Applications that are to be started prior to this one. This can be ignored %% leave it alone unless you understand it well and let the .rel files in %% your release handle this. - {applications, - [ + {applications, [ kernel, stdlib, - inets, - barista + inets ]}, %% OTP application loader will load, but not start, included apps. Again @@ -42,5 +39,4 @@ %% configuration parameters similar to those in the config file specified %% on the command line. can be fetched with gas:get_env {env, []} - ] -}. +]}. diff --git a/src/docs.lfe b/src/docs.lfe index ac2a822..06f5a7b 100644 --- a/src/docs.lfe +++ b/src/docs.lfe @@ -3,6 +3,8 @@ (export ;; gen_server implementation (start 0) + (start-gen-server 0) + (start-gen-server 1) (stop 0) ;; callback implementation (init 1) @@ -10,13 +12,7 @@ (handle_cast 2) (handle_info 2) (terminate 2) - (code_change 3) - ;; server API - (gen 0) - (gen-dev 0) - (httpd 0) - (httpd-restart 0) - (httpd-stop 0))) + (code_change 3))) ;;; config functions @@ -30,17 +26,44 @@ ;;; gen_server implementation (defun start () + (start "Starting docs gen-server ...")) + +(defun start (msg) + (start #'logjam:info/1 msg)) + +(defun start (log-fn log-msg) (logjam:start) - (let ((cfg (initial-state))) - (logjam:info "Starting docs gen-server ...") - (gen_server:start (register-name) - (callback-module) - cfg - (genserver-opts)))) + (application:ensure_all_started 'docs) + (funcall log-fn `(,log-msg)) + (start-gen-server)) + +(defun start-gen-server () + (start-gen-server (initial-state))) + +(defun start-gen-server (cfg) + (gen_server:start (register-name) + (callback-module) + cfg + (genserver-opts))) (defun stop () - (logjam:info "Stopping docs gen-server ...") - (gen_server:call (server-name) 'stop)) + (stop "Stopping docs gen-server ...")) + +(defun stop (msg) + (stop #'logjam:info/1 msg)) + +(defun stop (log-fn log-msg) + (funcall log-fn `(,log-msg)) + (stop-gen-server) + (application:stop 'docs)) + +(defun stop-gen-server () + (gen_server:call (server-name) 'stop) + (gen_server:stop (server-name))) + +(defun restart () + (stop (lambda (x) x) "") + (start "Restarting docs gen-server ...")) ;;; callback implementation @@ -48,18 +71,12 @@ `#(ok ,initial-state)) (defun handle_cast - (('gen state-data) - `#(noreply ,(docs-gen:run))) - (('gen-dev state-data) - `#(noreply ,(docs-gen:run-dev))) - (('httpd state-data) - `#(noreply ,(docs-dev:serve))) - (('httpd-restart state-data) - `#(noreply ,(docs-dev:restart-server))) - (('httpd-stop state-data) - `#(noreply ,(docs-dev:stop-server)))) + ((message state-data) + `#(reply ,(unknown-command) ,state-data))) (defun handle_call + (('stop caller state-data) + `#(reply stopping ,state-data)) ((message _caller state-data) `#(reply ,(unknown-command) ,state-data))) @@ -78,20 +95,3 @@ (defun code_change (_old-version state _extra) `#(ok ,state)) - -;;; our server API - -(defun gen () - (gen_server:cast (server-name) 'gen)) - -(defun gen-dev () - (gen_server:cast (server-name) 'gen-dev)) - -(defun httpd () - (gen_server:cast (server-name) 'httpd)) - -(defun httpd-restart () - (gen_server:cast (server-name) 'httpd-restart)) - -(defun httpd-stop () - (gen_server:cast (server-name) 'httpd-stop))