element_table.erl 1.2 KB

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