[ADD] New template for Lua script
This commit is contained in:
		
							
								
								
									
										31
									
								
								composants/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								composants/index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					<!DOCTYPE html>
 | 
				
			||||||
 | 
					<head>
 | 
				
			||||||
 | 
					  <meta charset="UTF-8" />
 | 
				
			||||||
 | 
					  <title>${TITLE}</title>
 | 
				
			||||||
 | 
					<!--[if lt IE 9]>
 | 
				
			||||||
 | 
					  <script src="html5.js" type="text/javascript"></script>
 | 
				
			||||||
 | 
					<![endif]-->
 | 
				
			||||||
 | 
					  <link rel="stylesheet" href="${DEFAULT_CSS}" type="text/css" media="all" title="${CSS_NAME}" />
 | 
				
			||||||
 | 
					  <link rel="stylesheet" href="${CSS_COLOR}" type="text/css" media="all" title="${CSS_NAME}" />
 | 
				
			||||||
 | 
					</head>
 | 
				
			||||||
 | 
					<body>
 | 
				
			||||||
 | 
					<!-- Entete de page -->
 | 
				
			||||||
 | 
					  <header>
 | 
				
			||||||
 | 
					    <h1>${PORTEAIL_TITLE}</h1>
 | 
				
			||||||
 | 
					  </header>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- Corps de la page -->
 | 
				
			||||||
 | 
					  <div id="corps">
 | 
				
			||||||
 | 
					    ${INTRODUCTION}
 | 
				
			||||||
 | 
					    ${CONTENT}
 | 
				
			||||||
 | 
					  </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					${MENU}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					<!-- Pied de page -->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  <footer>
 | 
				
			||||||
 | 
					    <p>Page générée à l'aide de <a href="http://porteail.e-mergence.org/" title="Se rendre sur la page officielle du projet PorteAil">PorteAil</a></p>
 | 
				
			||||||
 | 
					  </footer>
 | 
				
			||||||
 | 
					</body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
							
								
								
									
										61
									
								
								porteail.lua
									
									
									
									
									
								
							
							
						
						
									
										61
									
								
								porteail.lua
									
									
									
									
									
								
							@@ -9,17 +9,18 @@ require 'lfs'
 | 
				
			|||||||
--[[ Variables ]]--
 | 
					--[[ Variables ]]--
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- Mandatories files
 | 
					-- Mandatories files
 | 
				
			||||||
configFile = './' .. 'configrc'
 | 
					local configFile = './' .. 'configrc'
 | 
				
			||||||
-- Default directories values
 | 
					-- Default directories values
 | 
				
			||||||
local currentpath = os.getenv('CURDIR') or '.'
 | 
					local currentpath = os.getenv('CURDIR') or '.'
 | 
				
			||||||
default_dir_category = 'categ'
 | 
					local default_dir_category = 'categ'
 | 
				
			||||||
default_dir_component = 'composants'
 | 
					local default_dir_component = 'composants'
 | 
				
			||||||
 | 
					local default_dir_destination = 'porteail'
 | 
				
			||||||
-- Default files values
 | 
					-- Default files values
 | 
				
			||||||
default_img_filename = 'generique.png'
 | 
					local default_img_filename = 'generique.png'
 | 
				
			||||||
default_header_filename = 'entete.html'
 | 
					local default_index_filename = 'index.html'
 | 
				
			||||||
default_footer_filename = 'enqueue.html'
 | 
					local default_template_index_filename = 'index.html'
 | 
				
			||||||
default_categ_extension = 'txt'
 | 
					-- Other defaults values
 | 
				
			||||||
 | 
					local default_categ_extension = 'txt'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
--[[ Functions ]]--
 | 
					--[[ Functions ]]--
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -42,6 +43,12 @@ function getConfig(file)
 | 
				
			|||||||
  return result
 | 
					  return result
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function replace(string, table)
 | 
				
			||||||
 | 
					  return string:gsub("$(%b{})", function(string)
 | 
				
			||||||
 | 
					    return table[string:sub(2,-2)]
 | 
				
			||||||
 | 
					   end)
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function listing (path, extension)
 | 
					function listing (path, extension)
 | 
				
			||||||
  files = {}
 | 
					  files = {}
 | 
				
			||||||
  if lfs.attributes(path) then
 | 
					  if lfs.attributes(path) then
 | 
				
			||||||
@@ -94,21 +101,22 @@ end
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
-- fetch user defined values
 | 
					-- fetch user defined values
 | 
				
			||||||
config = getConfig(configFile)
 | 
					config = getConfig(configFile)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- create values for directories
 | 
					-- create values for directories
 | 
				
			||||||
categ = config['CATEGORIES'] or default_dir_category
 | 
					categ = config['CATEGORIES'] or default_dir_category
 | 
				
			||||||
component = config['COMPOSANTS'] or default_dir_component
 | 
					component = config['COMPOSANTS'] or default_dir_component
 | 
				
			||||||
 | 
					destination = config['CIBLE'] or default_dir_destination
 | 
				
			||||||
-- create values for files
 | 
					-- create values for files
 | 
				
			||||||
header_filename = config['ENTETE'] or default_header_filename
 | 
					index_filename = config['INDEX'] or default_index_filename
 | 
				
			||||||
footer_filename = config['ENQUEUE'] or default_footer_filename
 | 
					main_template = config['TEMPLATE_INDEX'] or default_template_index_filename
 | 
				
			||||||
-- other default values
 | 
					-- other default values
 | 
				
			||||||
categ_extension = config['CATEGORIES_EXT'] or default_categ_extension
 | 
					categ_extension = config['CATEGORIES_EXT'] or default_categ_extension
 | 
				
			||||||
-- get header and footer content
 | 
					
 | 
				
			||||||
header_file = assert(io.open(currentpath .. '/' .. component .. '/' .. header_filename, 'r'))
 | 
					-- get page
 | 
				
			||||||
header = assert(header_file:read('*a'))
 | 
					index_file = assert(io.open(currentpath .. '/' .. component .. '/' .. index_filename, 'r'))
 | 
				
			||||||
assert(header_file:close())
 | 
					index = assert(index_file:read('*a'))
 | 
				
			||||||
footer_file = assert(io.open(currentpath .. '/' .. component .. '/' .. footer_filename, 'r'))
 | 
					assert(index_file:close())
 | 
				
			||||||
footer = assert(footer_file:read('*a'))
 | 
					
 | 
				
			||||||
assert(footer_file:close())
 | 
					 | 
				
			||||||
-- Browse categ directory
 | 
					-- Browse categ directory
 | 
				
			||||||
local categories_files = listing (currentpath .. '/' .. categ, categ_extension)
 | 
					local categories_files = listing (currentpath .. '/' .. categ, categ_extension)
 | 
				
			||||||
if categories_files then
 | 
					if categories_files then
 | 
				
			||||||
@@ -122,3 +130,22 @@ if categories_files then
 | 
				
			|||||||
else
 | 
					else
 | 
				
			||||||
  print ("-- No category file found!")
 | 
					  print ("-- No category file found!")
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Check if public directory exists
 | 
				
			||||||
 | 
					if lfs.attributes(destination) == nil then
 | 
				
			||||||
 | 
					  assert(lfs.mkdir(destination))
 | 
				
			||||||
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- Create index file in destination directory
 | 
				
			||||||
 | 
					result = assert(io.open(destination .. '/' .. main_template, 'wb'))
 | 
				
			||||||
 | 
					-- create substitution table
 | 
				
			||||||
 | 
					substitutions = {
 | 
				
			||||||
 | 
					  TITLE=config['TITRE'] .. ' - Accueil',
 | 
				
			||||||
 | 
					  PORTEAIL_TITLE=config['TITRE'],
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					-- replace variables in result
 | 
				
			||||||
 | 
					assert(result:write(replace(index, substitutions)))
 | 
				
			||||||
 | 
					-- close file
 | 
				
			||||||
 | 
					assert(result:close())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					--[[ END ]]--
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user