-- lobals -------------------------------------- local extention = ".luah" local working_directory = "" local html = "" local wrapper = function( inside ) return ( [[
\n" for i, args in ipairs( self.calls ) do for i, arg in ipairs( args ) do text = text..arg.."\n" end end text = text.."
\n" return text end, } collector ( ... ) return collector end function br( text ) local collector = new_collector { __tostring = function( self ) local text = "" for i, args in ipairs( self.calls ) do for i, arg in ipairs( args ) do text = text..arg..""..text.."\n"
end
for i=1, 6 do
local h = "h"..i
_G[h] = function( text )
return "<"..h..">"..text..""..h..">"
end
end
-- file system interaction functions -------------------------------------
local stored_directory_items = {}
function get_directory_items( path )
if stored_directory_items[ path ] then
return stored_directory_items[ path ]
end
local command = "ls -1 "
if #path > 0 then
command = command..'"'..path..'"'
end
local file = io.popen( command )
local items = {}
while true do
local read = file:read()
if not read then
file:close()
break
end
table.insert( items, read )
end
stored_directory_items[ path ] = items
return items
end
function get_working_directory()
return working_directory
end
function path_type( path )
local items = get_directory_items( path )
if #items == 0 then
local from = 0
while true do
local find = string.find( path, "/", from )
if not find then
from = from - 1
break
end
from = find + 1
end
local parent_directory = string.sub( path, 0, from )
local our_name = string.sub( path, from+1, #path )
local parent_items = get_directory_items( parent_directory )
local found_our_name = false
for i, item in ipairs ( parent_items ) do
if item == our_name then
found_our_name = true
break
end
end
if not found_our_name then
return
end
end
return (#items == 1 and items[1] == path) and "file" or "directory"
end
local home = ""
function get_home()
return home
end
function set_wrapper( set )
wrapper = set
end
function get_wrapper()
return wrapper
end
-- local functions ----------------------------
local function translate( file_path )
if file_path:sub( #file_path-3, #file_path ) ~= ".jes" then
return
end
-- read jes file --
local lua_file = io.open( file_path, "r" )
if not lua_file then
return
end
local lua = lua_file:read( "*a" )
lua_file:close()
-- run jes file --
html = ""
local func, err = loadstring( lua )
if not func then
print( "----------------------------------------------------" )
print( "GOOFED SYNTAX in '"..file_path.."'. change it please :3" )
print( err )
print( "----------------------------------------------------" )
error()
end
local status, err = xpcall ( func, debug.traceback )
if not status then
print( "----------------------------------------------------" )
print( "RUN ERROR in '"..file_path.."'. fix it please? :3" )
print( err )
print( "----------------------------------------------------" )
error()
end
local page = err or ""
-- construct valid html doc --
local html = ""..wrapper( page )..""
-- write html doc --
local name_path = file_path:sub( 0, #file_path-4 )
local html_path = name_path..".html"
local html_file = io.open( html_path, "w" )
html_file:write( html )
html_file:close()
print( html_path, "updated" )
end
local function in_scope_home()
local old_home = home
if home == "" then
home = "./"
else
home = home.."../"
end
return old_home
end
local function out_scope_home( old_home )
home = old_home
end
local translate_directory
local function translate_directory( dir_path )
if path_type( dir_path ) == "file" then
translate( dir_path )
return false
end
if #dir_path > 0 then
dir_path = dir_path.."/"
end
working_directory = dir_path
local old_home = in_scope_home()
translate( dir_path.."index.jes" )
out_scope_home( old_home )
local items = get_directory_items( working_directory )
for i, item in ipairs( items ) do
if item ~= "index.jes" then
local path = dir_path..item
working_directory = dir_path
local old_home = in_scope_home()
translate_directory( path )
out_scope_home( old_home )
end
end
return true
end
translate_directory( working_directory )