From dc30b7c000281efdc2a4c58b85bd71985a125e50 Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Thu, 16 May 2013 10:41:48 +0200 Subject: [PATCH] [ADD] Check that no more than 1 category have been filled in category file --- create_homepage.lua | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/create_homepage.lua b/create_homepage.lua index f6fe72a..6c3119d 100755 --- a/create_homepage.lua +++ b/create_homepage.lua @@ -130,8 +130,10 @@ end function process(filepath, template_categ, template_element, img_destination, destination, img_source, default_img) -- parse given file - local categ_page = '' local elements = {} + local categ_title = '' + local categ_description = '' + local categ_count = 0 for line in io.lines(filepath) do local element = '' -- check if this line is a comment ("# my comment"), a category ("[[My category]]Its description") or an element ("Title##Description##URL##Image") @@ -141,11 +143,9 @@ function process(filepath, template_categ, template_element, img_destination, de if is_comment then -- do nothing because it's a comment elseif is_title then - title = '' - for t in string.gmatch(line, '%[%[(.*)%]%].*') do title = title .. t end - description ='' - for d in string.gmatch(line, '%[%[.*%]%](.*)') do description = description .. d end - categ_page = replace(template_categ, {CATEG_TITLE=title, CATEG_DESC=description}) + for t in string.gmatch(line, '%[%[(.*)%]%].*') do categ_title = categ_title .. t end + for d in string.gmatch(line, '%[%[.*%]%](.*)') do categ_description = categ_description .. d end + categ_count = categ_count + 1 elseif is_element then title = '' description = '' @@ -162,11 +162,15 @@ function process(filepath, template_categ, template_element, img_destination, de table.insert(elements, element) end end + if categ_count > 1 then + print (' ' .. filepath .. ' not imported: too many categories.') + return '' + end local text_elements = '' for k, v in pairs(elements) do text_elements = text_elements .. v end - local result = replace(categ_page, {ELEMENTS=text_elements}) + local result = replace(template_categ, {CATEG_TITLE=categ_title, CATEG_DESC=categ_description, ELEMENTS=text_elements}) return result end