----------------------------------------------------------------- -- Composition rules for generating the output files. ----------------------------------------------------------------- -- Table of expected Lua types to be bolded on the output. -- @see first_rest. local types = { string = 1, number = 1, table = 1, ["function"] = 1, ["nil"] = 1, tabela = 1, numero = 1, funcao = 1, ["número"] = 1, ["função"] = 1, } ----------------------------------------------------------------- -- Split the string in two parts: the first word and the rest of -- the string. -- @param str String to be processed. -- @return Two strings: the first word and the rest of the original -- string. function first_rest (str) local t = types t.first = nil t.rest = nil local _ = string.gsub (str, "^(%S+)(.*)$", function (f,r) if t[string.lower (f)] then t.first = f t.rest = r end end) if _ then return t.first, t.rest else return nil, nil end end ----------------------------------------------------------------- -- Print the file header. function file_header (field_value) field_value = string.gsub (field_value, "^.*/([^/]+)$", "%1") return field_value.."
" end ----------------------------------------------------------------- -- Print the file footer. function file_footer (field_value) if not field_value then field_value = "" else field_value = field_value.."
" end return field_value.. "
This file was automatically generated by LuaDoc in ".. os.date ("%d of %B of %Y").."." end ----------------------------------------------------------------- -- Build a function that will create an anchor with a filter. -- @param f Function that will filter the name of the anchor. -- @return Function that will be used to create an anchor. function anchor (f) return function (field_value) return ''..f (field_value)..'' end end function link_rel (f) return function (field_value) return ''..f (field_value)..'' end end function link_abs (f) return function (field_value) field_value = string.gsub (field_value, "^.*/([^/]+)$", "%1") return ''..f (field_value)..'' end end function link_abs_1 (field_value) field_value = string.gsub (field_value, "^.*/([^/]+)$", "%1") return '' end function link_abs_2 (f) return function (field_value) field_value = string.gsub (field_value, "^.*/([^/]+)$", "%1") return f (field_value)..'' end end ----------------------------------------------------------------- -- Names of document sections. local section_names = { ["function"] = "Functions", local_function = "Local functions", string = "Definitions", constant = "Definitions", table = "Definitions", } ----------------------------------------------------------------- -- @param source Table with source data. function MakeTitle (source) if source.class and CMP.section_name ~= section_names[source.class] then CMP.section_name = section_names[source.class] CMP.write ("

\n"..CMP.section_name.."\n

") end end ----------------------------------------------------------------- -- @param source Table with source data (not used). function MakeIndex (source) if not CMP._index_ then CMP._index_ = 1 CMP.write ("

Index

\n

Files

\n") end end ----------------------------------------------------------------- -- @param field_value Object to be printed. function Write (field_value) return field_value end ----------------------------------------------------------------- -- Build a [[Write]] function that generate the output for a table. -- @param label String label used by the function. -- @return Function that "prints" all table's fields and values. function Write_each (label) return function (field_value) local s = "" for i, v in pairs(field_value) do if i ~= "n" then local first, rest = first_rest (v) if first then s = s.."
"..i..": "..first.."".. rest.."\n" else s = s.."
"..i..": "..v.."\n" end end end return "
"..label.."\n"..s end end function List_table (label) return function (field_value) local s = "" for j = 1, table.getn(field_value) do local i = field_value[j] local v = field_value[i] if i ~= "n" and v then local first, rest = first_rest (v) if first then s = s..''..i.. ''..first..''.. rest..'\n' else s = s..''..i.. ''..v..'\n' end end end return "
"..label.."\n"..s.."
\n" end end function List_each_link (label) return function (field_value) local s = "" for i, v in field_value do if i ~= "n" then local t = { f = "", n = v, } if string.find (v, "#", 1, 1) then string.gsub (v, "^([^#]+)#([^#]+)$", function (file, name) t.f = file..".html" t.n = name end) end s = s..'
'..t.n..'\n' end end return "
"..label.."\n"..s end end function Ctags (...) local b = "" local e = "" for i = 1, table.getn(arg) do local tag = arg[i] b = b.."<"..tag..">" e = e.."" end return function (field_value) return b..field_value..e.."\n" end end function Citemize (label, linebreak) return function (field_value) return ""..label..": "..field_value..linebreak.."\n" end end function Citemize_first (label, linebreak) return function (field_value) local first, rest = first_rest (field_value) if first then return ""..label.." "..first..""..rest.. linebreak.."\n" else return ""..label.." "..field_value..linebreak.."\n" end end end html = { { "in_file", file_header }, { "title", Ctags ("p", "h1") }, -- "

\n", { "resume", Ctags ("h3") }, { "description", Citemize ("Description", "
") }, { "author", Citemize ("Author", "
") }, { "copyright", Citemize ("Copyright", "
") }, { "date", Citemize ("Date", "
") }, ; internal = { MakeTitle, { "name", anchor (Ctags ("code", "b")) }, { "param_list", Ctags ("code") }, { "value", Citemize_first ("=", "
") }, "

\n", "

\n", ; order_field = { "section", "name" }, anchor_field = { "name" }, }, internal_index = { MakeTitle, { "name", link_rel (Ctags ("code", "b")) }, { "param_list", Ctags ("code") }, { "value", Citemize_first ("=", "") }, "

\n", { "resume", Write }, "

\n", ; order_field = { "section", "name" }, link_field = { "name" }, }, file_index = { MakeIndex, ; internal = {}, internal_index = { { "out_file", link_abs_1 }, { "in_file", link_abs_2 (Ctags ("code", "b")) }, --{ "in_file", link_abs (Ctags ("code", "b")) }, --{ "out_file", link_abs (Ctags ("code", "b")) }, "
\n", }, order_field = { "out_file" }, }, footer = file_footer, }