action_jq.erl 1.1 KB

123456789101112131415161718192021
  1. -module(action_jq).
  2. -author('Rusty Klophaus').
  3. -author('Andrey Martemyanov').
  4. -include_lib("nitro/include/nitro.hrl").
  5. -include_lib("nitro/include/event.hrl").
  6. -compile(export_all).
  7. -define(B(E), nitro:to_binary(E)).
  8. -define(R(E), nitro:render(E)).
  9. -define(T(T), wf_event:target(T)).
  10. -define(U, undefined).
  11. render_action(#jq{property=?U,target=T,method=Methods,args=Args0,format=F}) ->
  12. Args = case F of "'~s'" -> [ ?R(Args0) ]; _ -> Args0 end,
  13. Format = fun(A) when is_tuple(A) orelse is_integer(A) -> ?R(A); (A) -> nitro:to_list(A) end,
  14. RenderedArgs = string:join([ Format(A) || A <- Args], ","),
  15. [[?T(T),".",?B(M),"(",nitro:f(F,[RenderedArgs]),");"] || M <- Methods];
  16. render_action(#jq{target=T,method=?U,property=P,right=R,args=simple}) -> [?B(T),".",?B(P),"='",?R(R),"';"];
  17. render_action(#jq{target=T,method=?U,property=P,right=?U}) -> [?T(T),".",?B(P),";"];
  18. render_action(#jq{target=T,method=?U,property=P,right=#jq{}=R}) -> [?T(T),".",?B(P),"=", ?R(R), ";"];
  19. render_action(#jq{target=T,method=?U,property=P,right=R}) -> [?T(T),".",?B(P),"='",?R(R),"';"].