Skip to content
Open
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 include/mad.hrl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
-define(VERSION,"1b48b6").
-define(VERSION,"ca88d4").
Binary file modified mad
Binary file not shown.
7 changes: 7 additions & 0 deletions priv/web/apps/sample/rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,10 @@
{source_ext, ".html"},
{module_ext, "_view"}
]}.
{jaderl_opts, [
{doc_root, "priv/templates"},
{out_dir, "ebin"},
{compiler_options, [report, return, debug_info]},
{source_ext, ".jade"},
{module_ext, "_view"}
]}.
3 changes: 2 additions & 1 deletion src/compile/mad_compile.erl
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ dep(Cwd, _Conf, ConfigFile, Name) ->
Opts = mad_utils:get_value(erl_opts, Conf1, []),
FilesStatus = compile_files(Files,IncDir, EbinDir, Opts,Includes),
DTLStatus = mad_dtl:compile(DepPath,Conf1),
JADEStatus = mad_jade:compile(DepPath, Conf1),
PortStatus = lists:any(fun(X)->X end,mad_port:compile(DepPath,Conf1)),
% io:format("Status: ~p~n",[[Name,FilesStatus,DTLStatus,PortStatus,DepsRes]]),
put(Name, compiled),
case (DepsRes orelse FilesStatus orelse DTLStatus orelse PortStatus) andalso filelib:is_dir(Name)==false of
case (DepsRes orelse FilesStatus orelse DTLStatus orelse JADEStatus orelse PortStatus) andalso filelib:is_dir(Name)==false of
true -> {error,Name};
false -> {ok,Name} end end.

Expand Down
59 changes: 59 additions & 0 deletions src/compile/mad_jade.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
-module(mad_jade).
-copyright('Sina Samavati').
-copyright('Igor Savchuk').
-compile(export_all).

compile(Dir,Config) ->
case mad_utils:get_value(jaderl_opts, Config, []) of
[] -> false;
X -> compile_jaderl_files(validate_jaderl_opts(Dir,X)) end.

get_kv(K, Opts, Default) ->
V = mad_utils:get_value(K, Opts, Default),
KV = {K, V},
{KV, Opts -- [KV]}.

file_to_beam(Bin, Filename) -> filename:join(Bin, filename:basename(Filename) ++ ".beam").

validate_jaderl_opts(Cwd, Opts) ->
DefaultDocRoot = filename:join("priv", "templates"),
{DocRoot, Opts1} = get_kv(doc_root, Opts, DefaultDocRoot),
{OutDir, Opts2} = get_kv(out_dir, Opts1, "ebin"),
{CompilerOpts, Opts3} = get_kv(compiler_options, Opts2, []),
{SourceExt, Opts4} = get_kv(source_ext, Opts3, ".jade"),
{ModuleExt, Opts5} = get_kv(module_ext, Opts4, ""),

{_, DocRootDir} = DocRoot,
DocRoot1 = {doc_root, filename:join(Cwd, DocRootDir)},
{_, OutDir1} = OutDir,
OutDir2 = {out_dir, filename:join(Cwd, OutDir1)},

[DocRoot1, OutDir2, CompilerOpts, SourceExt, ModuleExt|Opts5].

module_name(File, Ext, NewExt) ->
list_to_atom(filename:basename(File, Ext) ++ NewExt).

compile_jaderl_files(Opts) ->

{{_, DocRoot}, Opts1} = get_kv(doc_root, Opts, ""),
{{_, SourceExt}, Opts2} = get_kv(source_ext, Opts1, ""),
{{_, ModuleExt}, Opts3} = get_kv(module_ext, Opts2, ""),
{{_, OutDir}, _} = get_kv(out_dir, Opts3, ""),

Files = filelib:fold_files(DocRoot, SourceExt, true,
fun(F, Acc) -> [F|Acc] end, []),

Compile = fun(F) ->
ModuleName = module_name(F, SourceExt, ModuleExt),
BeamFile = file_to_beam(OutDir, atom_to_list(ModuleName)),
Compiled = mad_compile:is_compiled(BeamFile, F),
case Compiled of false ->
mad:info("JADE Compiling ~s~n", [F -- mad_utils:cwd()]),
Res = jaderl:compile(F, ModuleName, Opts3),
file:change_time(BeamFile, calendar:local_time()),
case Res of {error,Error} -> mad:info("Error: ~p~n",[Error]);
OK -> OK end;
true -> ok end
end,

lists:any(fun({error,_}) -> true; (ok) -> false end,[Compile(F) || F <- Files]).