Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PROJECT = docs
ROOT_DIR = $(shell pwd)
REPO = $(shell git config --get remote.origin.url)
LFE = _build/dev/lib/lfe/bin/lfe
LFE = _build/default/lib/lfe/bin/lfe
ERL_LIBS = $(shell find ./_build/*/* -maxdepth 1 -mindepth 1 -exec printf "%s:" {} \;)
RIGHT_PAREN = )
LOCAL_DOCS_HOST = $(subst $(RIGHT_PAREN),,$(strip $(lastword $(shell grep host lfe.config))))
Expand Down
9 changes: 3 additions & 6 deletions priv/make/base.mk
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
compile:
rebar3 as dev compile
rebar3 compile

check:
@rebar3 as test eunit
@rebar3 eunit

repl: compile
@ERL_LIBS=$(ERL_LIBS) $(LFE)

shell:
@rebar3 as dev shell
@rebar3 shell

clean:
@rebar3 clean
@rm -rf ebin/* _build/*/lib/$(PROJECT)

clean-all: clean
@rebar3 as dev lfe clean
3 changes: 3 additions & 0 deletions priv/make/gen.mk
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ serve-watch-css: serve-header css-watch-dev serve-only
serve-dev: docs-header clean compile css-dev serve-header
@ERL_LIBS=$(ERL_LIBS) $(LFE) -s docs-cli gen-dev-httpd

serve-dev-watch: docs-header clean compile css-dev serve-header
@ERL_LIBS=$(ERL_LIBS) $(LFE) -s docs-cli gen-dev-watch

contributors:
git log --pretty=format:"%an"|sort -u

Expand Down
41 changes: 13 additions & 28 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{erl_opts, [{src_dirs, ["src", "test"]}]}.

{erlydtl_opts, [
{source_ext, ".html"},
{module_ext, "-tmpl"},
Expand All @@ -6,44 +8,27 @@
{return_errors, true}
]}.

{eunit_opts, [verbose]}.

{eunit_compile_opts, [{src_dirs, ["test", "src"]}]}.

{deps, [
{lfe, {git, "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/rvirding/lfe.git", {branch, "develop"}}},
{poise, {git, "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/lfex/poise.git", {branch, "master"}}},
{exemplar, {git, "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/lfex/exemplar.git", {tag, "0.5.0-rc2"}}},
{logjam, {git, "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/lfex/logjam.git", {tag, "0.5.0-rc2"}}},
{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-rc2"}}},
{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"}}}
]}.

{plugins, [
{'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"}}}
{branch, "master"}}},
{'lfe-test', {git, "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/lfe-rebar3/test.git", {tag, "0.4.0-rc2"}}}
]}.

{provider_hooks, [{pre, [{compile, {lfe, compile}},
{compile, {erlydtl, compile}}]}]}.

{profiles, [
{dev, [
{deps, [
{lfe, {git, "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/rvirding/lfe.git", {branch, "develop"}}},
{barista, {git, "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/lfe-mug/barista.git", {tag, "0.2.2"}}},
{inotify, {git, "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/erlsci/inotify.git", {tag, "v0.5.0"}}}
]},
{plugins, [
{'lfe-version', {git, "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/lfe-rebar3/version.git", {tag, "0.5.0-rc2"}}},
{'lfe-clean', {git, "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/lfe-rebar3/clean.git", {tag, "0.4.0-rc1"}}}
]}
]},
{test, [
{eunit_compile_opts, [
{src_dirs, ["test", "src"]}
]},
{deps, [
{ltest, {git, "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/lfex/ltest.git", {tag, "0.10.0-rc6"}}}]},
{plugins, [
{'lfe-test', {git, "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/lfe-rebar3/test.git", {tag, "0.4.0-rc2"}}}]},
{eunit_opts, [verbose]},
{erl_opts, [{src_dirs, ["src", "test"]}]}
]}
]}.
6 changes: 6 additions & 0 deletions src/docs-cli.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@
(lambda ()
(docs:gen-dev)
(docs:httpd))))

(defun gen-dev-watch ()
(do-cmd
(lambda ()
(docs:gen-dev)
(docs-watcher:start))))
55 changes: 45 additions & 10 deletions src/docs-watcher.lfe
Original file line number Diff line number Diff line change
@@ -1,32 +1,56 @@
(defmodule docs-watcher
(export all))

(defun source-data ()
`#("src" ,#'lfe-watcher/1))

(defun templates-data ()
`#("priv/templates" ,#'erlydtl-watcher/1))

(defun default-watch-data ()
`(#("priv/templates" ,#'erlydtl-watcher/1)
#("src" ,#'lfe-watcher/1)))
`(,(templates-data)
,(source-data)))

(defun lfe-compiler (filename)
(logjam:info "Recompiling LFE file: ~p" `(,filename)))
(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)))
(logjam:info "Recompiling ErlyDTL file: ~p" `(,filename))
(docs:httpd-restart))

(defun lfe-watcher
((`#(,path file close_write ,fd ,file))
(lfe-compiler (filename:join path file)))
((_arg)
'skipping))
(lfe-compiler path file))
((args)
(logjam:debug "LFE watcher event: ~p" `(,args))))

(defun erlydtl-watcher
((`#(,path file close_write ,fd ,file))
(erlydtl-compiler (filename:join path file)))
((_) 'skipping))
((args)
(logjam:debug "ErlyDTL watcher event: ~p" `(,args))))

(defun start ()
(start (default-watch-data)))

(defun start (watch-data)
(logjam:start)
(docs:start)
(docs:httpd)
(application:ensure_all_started 'inotify)
(case (lists:map (match-lambda ((`#(,path ,func))
(logjam:debug "Watching path: ~p with function: ~p"
Expand All @@ -35,3 +59,14 @@
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)))