require("luamods/layout")
header = layout.getHeader()
footer = layout.getFooter()

widgets = {}
widgets = command.getFilesInTable( main_conf.widgets_xml_path )
number_of_widgets = #(widgets)

html = header..[[
                    <div id="info">	
                        <center><h1>Home</h1></center>
                    </div>
                    <div style="text-align:center;">
]]

if number_of_widgets > 6 then number_of_widgets = 6 end
for i = 1, number_of_widgets do
    local widgetXML = command.returnFileString(main_conf.widgets_xml_path..widgets[i])
    if (widgetXML ~= nil) then
        widgetTitle = widgetXML:match("<title>%s*(.-)%s*</title>")
        widgetHref = widgetXML:match("<href>%s*(.-)%s*</href>")
        widgetImg = widgetXML:match("<img>%s*(.-)%s*</img>")
        widgetDesc = widgetXML:match("<desc>%s*(.-)%s*</desc>")
        
        if (widgetTitle ~= nil) and (widgetHref ~= nil) and (widgetImg ~= nil) and (widgetDesc ~= nil) then
            html = html .. [[
                        <div class="widget">
                            <a href="]]..widgetHref..[[">
                                <h3>]]..widgetTitle..[[</h3>
                                <img src="]]..widgetImg..[[" height="94">
                            </a>
                            <p>]]..widgetDesc..[[</p>
                        </div>
]]
        end
    end
end

html = html..[[                        
                    </div>
]]

html = html..footer
print (html)
