synrc / mad

⚡ MAD: Managing Application Dependencies LING/UNIX
https://mad.n2o.dev
Other
173 stars 53 forks source link

fail to compile dtl #71

Closed ganeshrd closed 7 years ago

ganeshrd commented 7 years ago

Thank you for your work. I am using the synrc products since few weeks now and i suddenly ran into that problem. Here is the output on mad compile:

escript: exception error: no function clause matching mad_dtl:'-compile_erlydtl_files/1-fun-2-'({ok,hta_view}) (/home/chazam/dev/mad/src/compile /mad_dtl.erl, line 58)

Because i have changed the erlydtl tag from 0.8.0 to 0.12.1, i have tried to change the 58th line from lists:any(fun({error,_}) -> true; (ok) -> false end,[Compile(F) || F <- Files]). to lists:any(fun({error,_}) -> true; ({ok,_}) -> false end,[Compile(F) || F <- Files]).

mad goes through the compile process now but fails on repl. Here is the scattered output i get from the console: [{mad_dtl,'-compile_erlydtl_files/1-fun-2-',[ok],[{file,"/home/chazam/dev/mad/src/compile/mad_dtl.erl"},{line,58}]},{lists,any,2,[{file,"lists.erl"},{line,1225}]},{mad_compile,dep,4,[{file,"/home/chazam/dev/mad/src/compile/mad_compile.erl"},{line,69}]}, {mad_compile,deps,4,[{file,"/home/chazam/dev/mad/src/compile/mad_compile.erl"}, {line,20}]},{active,compile,2, [{file,"/tmp/hm_web/deps/active/src/active.erl"},{line,92}]}, {active,handle_cast,2,[{file,"/tmp/hm_web/deps/active/src/active.erl"},{line,17}]}, {gen_server,try_dispatch,4,[{file,"gen_server.erl"},{line,601}]}, Catch: error:function_clause {gen_server,handle_msg,5,[{file,"gen_server.erl"},{line,667}]}]

doxtop commented 7 years ago

you doesn't change the result of CompileF function by your changes, it still returns either {error,_} or ok. look at the changed api, somewhere around matching of erlydtl:compile results

5HT commented 7 years ago

DTL is needed only by synrc/nitro, not synrc/n2o. And nitro #dtl element supports only 0.8 version. If you want to have 0.12 you should write your own DTL element. It is no so big:

-module(element_dtl).
-author('Maxim Sokhatsky').
-include("nitro.hrl").
-compile(export_all).

render_element(Record=#dtl{}) ->
    M = list_to_atom(nitro:to_list(Record#dtl.file) ++ "_view"),
    {ok,R} = render(M, Record#dtl.js_escape, 
       [{K,nitro:render(V)} || {K,V} <- Record#dtl.bindings] ++
        if Record#dtl.bind_script==true -> [{script,nitro:script()}]; true-> [] end),
    R.

render(M, true, Args) ->
    {ok, R} = M:render(Args),
    {ok, nitro:js_escape(R)};
render(M, _, Args) -> M:render(Args).