[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 ]]--
 | 
			
		||||
 | 
			
		||||
-- Mandatories files
 | 
			
		||||
configFile = './' .. 'configrc'
 | 
			
		||||
local configFile = './' .. 'configrc'
 | 
			
		||||
-- Default directories values
 | 
			
		||||
local currentpath = os.getenv('CURDIR') or '.'
 | 
			
		||||
default_dir_category = 'categ'
 | 
			
		||||
default_dir_component = 'composants'
 | 
			
		||||
local default_dir_category = 'categ'
 | 
			
		||||
local default_dir_component = 'composants'
 | 
			
		||||
local default_dir_destination = 'porteail'
 | 
			
		||||
-- Default files values
 | 
			
		||||
default_img_filename = 'generique.png'
 | 
			
		||||
default_header_filename = 'entete.html'
 | 
			
		||||
default_footer_filename = 'enqueue.html'
 | 
			
		||||
default_categ_extension = 'txt'
 | 
			
		||||
 | 
			
		||||
local default_img_filename = 'generique.png'
 | 
			
		||||
local default_index_filename = 'index.html'
 | 
			
		||||
local default_template_index_filename = 'index.html'
 | 
			
		||||
-- Other defaults values
 | 
			
		||||
local default_categ_extension = 'txt'
 | 
			
		||||
 | 
			
		||||
--[[ Functions ]]--
 | 
			
		||||
 | 
			
		||||
@@ -42,6 +43,12 @@ function getConfig(file)
 | 
			
		||||
  return result
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function replace(string, table)
 | 
			
		||||
  return string:gsub("$(%b{})", function(string)
 | 
			
		||||
    return table[string:sub(2,-2)]
 | 
			
		||||
   end)
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
function listing (path, extension)
 | 
			
		||||
  files = {}
 | 
			
		||||
  if lfs.attributes(path) then
 | 
			
		||||
@@ -94,21 +101,22 @@ end
 | 
			
		||||
 | 
			
		||||
-- fetch user defined values
 | 
			
		||||
config = getConfig(configFile)
 | 
			
		||||
 | 
			
		||||
-- create values for directories
 | 
			
		||||
categ = config['CATEGORIES'] or default_dir_category
 | 
			
		||||
component = config['COMPOSANTS'] or default_dir_component
 | 
			
		||||
destination = config['CIBLE'] or default_dir_destination
 | 
			
		||||
-- create values for files
 | 
			
		||||
header_filename = config['ENTETE'] or default_header_filename
 | 
			
		||||
footer_filename = config['ENQUEUE'] or default_footer_filename
 | 
			
		||||
index_filename = config['INDEX'] or default_index_filename
 | 
			
		||||
main_template = config['TEMPLATE_INDEX'] or default_template_index_filename
 | 
			
		||||
-- other default values
 | 
			
		||||
categ_extension = config['CATEGORIES_EXT'] or default_categ_extension
 | 
			
		||||
-- get header and footer content
 | 
			
		||||
header_file = assert(io.open(currentpath .. '/' .. component .. '/' .. header_filename, 'r'))
 | 
			
		||||
header = assert(header_file:read('*a'))
 | 
			
		||||
assert(header_file:close())
 | 
			
		||||
footer_file = assert(io.open(currentpath .. '/' .. component .. '/' .. footer_filename, 'r'))
 | 
			
		||||
footer = assert(footer_file:read('*a'))
 | 
			
		||||
assert(footer_file:close())
 | 
			
		||||
 | 
			
		||||
-- get page
 | 
			
		||||
index_file = assert(io.open(currentpath .. '/' .. component .. '/' .. index_filename, 'r'))
 | 
			
		||||
index = assert(index_file:read('*a'))
 | 
			
		||||
assert(index_file:close())
 | 
			
		||||
 | 
			
		||||
-- Browse categ directory
 | 
			
		||||
local categories_files = listing (currentpath .. '/' .. categ, categ_extension)
 | 
			
		||||
if categories_files then
 | 
			
		||||
@@ -122,3 +130,22 @@ if categories_files then
 | 
			
		||||
else
 | 
			
		||||
  print ("-- No category file found!")
 | 
			
		||||
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