-- lobals -------------------------------------- local extention = ".luah" local working_directory = "" local html = "" local wrapper = function( inside ) return ( [[
]] ..inside ..[[
]] ) end -- global dsl functions ------------------------ local __collector = { __call = function( self, ... ) table.insert( self.calls, {...} ) return self end, __concat = function( a, b ) return tostring( a )..tostring( b ) end, __tostring = function( self ) local text = "" for i, args in ipairs( self.calls ) do for i, arg in ipairs( args ) do text = text..arg end end return text end, } local function new_collector( collector ) collector = collector or {} collector.calls = {} setmetatable( collector, collector ) for k,v in pairs( __collector ) do collector[ k ] = collector[ k ] or v end return collector end -- html tag functions ------------------------------------------- function i ( text ) return [[]]..text..[[]] end local codacs = { ogg = "ogg", mp3 = "mpeg", } function audio ( path ) local ext = string.match( path, ".*%.(.*)$" ) local codac = codacs local this = ( "" .. [[]].."\n" ) return this end function img( link, alt ) return [[]] end function p( ... ) local collector = new_collector { __tostring = function( self ) local text = "" text = text.."

\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.."
\n" end end if #text == 0 then text = "
\n" end return text end, } collector ( text ) return collector end function ol ( ... ) local collector = new_collector { __tostring = function( self ) local text = "" text = text.."
    \n" for i, args in ipairs( self.calls ) do for i, arg in ipairs( args ) do text = text.."
  1. "..arg.."
  2. \n" end end text = text.."
\n" return text end, } collector ( ... ) return collector end function ul ( ... ) local collector = new_collector { __tostring = function( self ) local text = "" text = text.."\n" return text end, } collector ( ... ) return collector end function hr() return "
\n" end function b( text ) return ""..text.."" end function a( ... ) -- href, text local collector = new_collector { __tostring = function( self ) local text = "" for i, args in ipairs( self.calls ) do if #text > 0 then text = text.."
\n" end local href = args[1] local desk = args[2] or href if href:sub( 0, 8 ) ~= "https://" and href:sub(#href, #href) == "/" then href = href.."index.html" end text = text..[[]]..desk..[[]] end return text end } collector ( ... ) return collector end function u ( text ) return ""..text.."" end function code ( text ) local linebreaks = {} while true do local find = string.find( text, "\n", (linebreaks[#linebreaks] or 0) + 1 ) if not find then break end table.insert( linebreaks, find ) end local begining = 0 for i, linebreak in ipairs( linebreaks ) do if text:sub( begining, linebreak) == "\n" then begining = linebreak else break end end local ending = #text local i = #linebreaks while i > 0 do local linebreak = linebreaks[i] if text:sub( linebreak, ending ) == "\n" then ending = linebreak else break end i = i - 1 end text = text:sub( begining, ending ) return "
"..text.."
\n" end for i=1, 6 do local h = "h"..i _G[h] = function( text ) return "<"..h..">"..text.."" 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 )