-module(comp_2_html).

-compile(export_all).


-import(ccv_html_lib,
        [para/0,
         italic/1
         ]).


%%%%%%%%%%%%%%%%
%%create a List, html tagged, from a list, represnting a component 
%% note : generalise with hof for formatting, like format(fun:html(), fun:sourcefile2tree()): visitor on composite ?
%%$



test()->
    Result=["<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n<html>\n<head>\n<title>",
     "Well done!",
     "</title>",
     [],
     "</head><body>",
     [[[[],["\r\n<p>\r\n"],["<i>","Comp _Name","</i>"]],
       ["\r\n<p>\r\n"],
       ["<i>","command -Namew","</i>"]],
      ["\r\n<p>\r\n"],
      ["<i>","predicate name_precond","</i>"]],
     "</body></html>"],
    Arg1=[{component, 
           [{name,"Comp _Name"}, 
          [{command,
            [{name,"command -Namew"},
             {precondition,
              [{predicate,
                [{name,"predicate name_precond"}]
               }]
              }]
            }]
         ]} ],
             
    F1= comp2html(Arg1),
    Result=F1,
     
    F1.

comp2html(X)->
    Title="Well done!",
    Style="",
    Out=format_comp(X,[]),
    
Html = 
        ["<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
         "<html>\n<head>\n<title>", Title, "</title>",
         Style,
         "</head><body>",Out, 
         "</body></html>"],
    %%tag the list

    %%footer
    Html.


format_comp([{name,Name}|T],A)->
    Out=[para(),italic(Name)],
    format_comp(T,[A|Out]);

format_comp([{component,T}],A)->format_comp(T,A);

format_comp([H|T],A)->
    format_comp(H,
                    format_comp(T,A));
    

format_comp([_],A)->A;
format_comp({_,T},A) -> format_comp(T,A);
%format_comp(T,format_comp(T1,A));




format_comp([],A)->A.