Skip to content

Commit

Permalink
Add initial JSON writer and bump version
Browse files Browse the repository at this point in the history
Move make-doc to make-html, add make-json and update make targets.

See #23
  • Loading branch information
yurrriq committed Apr 30, 2016
1 parent cb411e4 commit 8175a78
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 10 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ all: compile

compile: ; @rebar3 compile

doc: compile; @./make-doc
doc: html json

html: compile; @./make-html

json: compile; @./make-json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Finally, add Lodox to your `project_plugins` list.
```erlang
{project_plugins, [
%% ...
{lodox, {git, "git://github.com/lfe-rebar3/lodox.git", {tag, "0.14.1"}}}
{lodox, {git, "git://github.com/lfe-rebar3/lodox.git", {tag, "0.15.0"}}}
]}.
```

Expand Down
2 changes: 1 addition & 1 deletion doc
4 changes: 2 additions & 2 deletions make-doc → make-html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@

(include-file "_build/default/lib/clj/include/compose.lfe")

(io:format " ~~~~> Generating documentation for lodox ...\n")
(io:format "\e[32m===> Generating HTML documentation for lodox...\e[0m\n")

(->> (lodox-parse:docs #"lodox" '[lodox-search])
(list* `#(app-dir ,(let ((`#(ok ,cwd) (file:get_cwd))) cwd))
`#(source-uri ,(++ "https://github.com/lfe-rebar3/lodox"
"/blob/{version}/{filepath}#L{line}")))
(lodox-html-writer:write-docs)
(list)
(io:format "\nGenerated documentation in ./~s\n"))
(io:format " ~~~~> Generated docs in ./~s\n"))
5 changes: 5 additions & 0 deletions make-json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env lfe
;; -*- lfe -*-
(io:format "\e[32m===> Generating JSON documentation for lodox...\e[0m\n")
(lodox-json-writer:write-docs (lodox-parse:docs #"lodox"))
(io:format " ~~~~> Generated ./doc/lodox.json\n")
41 changes: 41 additions & 0 deletions src/lodox-json-writer.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
(defmodule lodox-json-writer
(doc "Documentation writer that outputs JSON.")
(export (write-docs 1)))

(include-lib "clj/include/compose.lfe")

(defun write-docs (app)
"Take raw documentation info and turn it into JSON.
Write to and return `output-path` in `app`. Default: `\"./doc\"`"
(let* ((json (jsx:encode (do-modules app) '[space #(indent 2)]))
(output-path (proplists:get_value 'output-path app "doc"))
('ok (filelib:ensure_dir output-path))
(app-name (proplists:get_value 'name app))
(filename (binary (app-name binary) ".json")))
(file:write_file (filename:join output-path filename) json)
output-path))

(defun do-modules (app)
(-> (lists:map #'do-module/1 (proplists:get_value 'modules app))
(->> (tuple 'modules))
(cons (proplists:delete 'modules app))))

(defun do-module (module)
(-> (lists:map #'do-patterns/1 (proplists:get_value 'exports module))
(->> (tuple 'exports))
(list* (do-behaviour (proplists:get_value 'behaviour module))
(proplists:delete 'behaviour (proplists:delete 'exports module)))))

(defun do-patterns (export)
(-> (lists:map #'do-pattern/1 (proplists:get_value 'patterns export))
(->> (tuple 'patterns))
(cons (proplists:delete 'patterns export))))

(defun do-pattern (pattern)
(re:replace (lfe_io_pretty:term pattern) "comma " ". ,"
'[global #(return binary)]))

(defun do-behaviour (behaviours)
(-> (lambda (atm) (atom_to_binary atm 'latin1))
(lists:map behaviours)
(->> (tuple 'behaviour))))
2 changes: 1 addition & 1 deletion src/lodox-parse.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
```commonlisp
[#(name #\"lodox\")
#(version \"0.14.1\")
#(version \"0.15.0\")
#(description \"The LFE rebar3 Lodox plugin\")
#(documents [])
#(modules {{list of proplists of module metadata}})
Expand Down
8 changes: 4 additions & 4 deletions src/lodox.app.src
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{application, lodox, [
{description, "The LFE rebar3 Lodox plugin."},
{vsn, "0.14.1"},
{vsn, "0.15.0"},
{modules, [lodox,
'lodox-html-writer', 'lodox-parse', 'lodox-search',
'unit-lodox-tests']},
{applications, [kernel, stdlib, lfe, clj, exemplar, levaindoc]},
'lodox-html-writer', 'lodox-json-writer',
'lodox-parse', 'lodox-search', 'unit-lodox-tests']},
{applications, [kernel, stdlib, lfe, clj, exemplar, levaindoc, jsx]},

{maintainers, ["Eric Bailey"]},
{licenses, ["MIT"]},
Expand Down

0 comments on commit 8175a78

Please sign in to comment.