element_table.erl 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. -module(element_table).
  2. -include_lib("nitro/include/nitro.hrl").
  3. -compile(export_all).
  4. render_element(Record) when Record#table.show_if==false -> [<<>>];
  5. render_element(Record = #table{}) ->
  6. Header = case Record#table.header of
  7. [] -> "";
  8. H when is_tuple(H) -> H;
  9. _ -> wf_tags:emit_tag(<<"thead">>, nitro:render(Record#table.header), [])
  10. end,
  11. Footer = case Record#table.footer of
  12. [] -> "";
  13. _ -> wf_tags:emit_tag(<<"tfoot">>, nitro:render(Record#table.footer), [])
  14. end,
  15. Bodies = case Record#table.body of
  16. #tbody{} = B -> B;
  17. [] -> #tbody{};
  18. unndefined -> #tbody{};
  19. Rows -> [case B of #tbody{}=B1 -> B1; _-> #tbody{body=B} end || B <- Rows]
  20. end,
  21. Caption = case Record#table.caption of
  22. [] -> "";
  23. _ -> wf_tags:emit_tag(<<"caption">>, nitro:render(Record#table.caption), [])
  24. end,
  25. Colgroup = case Record#table.colgroup of
  26. [] -> "";
  27. _ -> wf_tags:emit_tag(<<"colgroup">>, nitro:render(Record#table.colgroup), [])
  28. end,
  29. wf_tags:emit_tag( <<"table">>, nitro:render([Caption, Colgroup, Header, Footer, Bodies]), [
  30. {<<"id">>, Record#table.id},
  31. {<<"class">>, Record#table.class},
  32. {<<"style">>, Record#table.style} | Record#table.data_fields
  33. ]).