Module:User:DTLHS Jul 8th 2013, 00:23, by DTLHS | | Line 118: | Line 118: | | | | | | table.insert(t, data["date"]) | | table.insert(t, data["date"]) | − | table.insert(t, parse_authors(data["authors"])) | + | if type(data["authors"]) == table then | | + | table.insert(t, parse_authors(data["authors"])) | | + | else | | + | table.insert(t, data["authors"]) | | + | end | | table.insert(t, data["title"]) | | table.insert(t, data["title"]) | | | | | local m = {} m["Adams Hitchhiker"] = { title = "The Hitchhiker's Guide to the Galaxy", wlink = "The Hitchhiker's Guide to the Galaxy (novel)", type = "book", date = "1979", authors = {{ name = "Douglas Adams", wlink = "Douglas Adams"}}, languages = {"en"}, isbn = "0-330-25864-8", publisher = "Pan Books", oclc = "24722438", display = "standard" } m["Authorized Version"] = { title = "King James Version of the Bible (Authorized Version)", wlink = "King James Version#Authorized Version", slink = "Bible (King James)", type = "book", date = "1611", authors = "various", languages = {"en"}, custom_parameters = {"book", "chapter", "verse_start", "verse_end"}, display = {default = "<sup>url</sup>", ["1 2 3"] = {"Bible (King James)", "/", 1, "#", 2, ":", 3}, ["1 2 3 4"] = {"", "/", 1, "#", 2, ":", 3, "–", 4} } } m["Bronte Wuthering"] = { title = "Wuthering Heights", wlink = "Wuthering Heights", slink = "Wuthering Heights", type = "book", date = "1847", authors = {{name = "Emily Brontë", wlink = "Emily Brontë"}}, languages = {"en"}, custom_parameters = {"chapter"}, custom_display = {["1"] = {"Wuthering Heights", "/", "Chapter ", 1}}, oclc = "71126926", isbn = "978-1-932535-14-3", gbooks = "KhMYAAAAYAAJ" } m["Chaucer Canterbury"] = { title = "The Canterbury Tales", wlink = "The Canterbury Tales", slink = "The Canterbury Tales", type = "book", date = "1478", authors = {{name = "Geoffrey Chaucer", wlink = "Geoffrey Chaucer"}}, languages = {"en", "enm"}, display = "standard" } m["Chaucer Troilus"] = { title = "Troilus and Criseyde", wlink = "Troilus and Criseyde", slink = "Troilus and Criseyde", type = "book", date = "1482", authors = {{name = "Geoffrey Chaucer", wlink = "Geoffrey Chaucer"}}, languages = {"en", "enm"}, display = "standard" } local export = {} function split_string(string) local result = {} for i in string.gmatch(string, "%S+") do table.insert(result, i) end return result end function wplink(title, disp) if disp ~= "" then if title ~= disp then return "[[w:"..title.."|"..disp.."]]" end end return "[[w:"..title.."|"..title.."]]" end function parse_authors(t) local result = {} for i, v in pairs(t) do disp = v["name"] or "" title = v["wlink"] or "" table.insert(result, wplink(title, disp)) end return table.concat(result, ", ") end function table.contains(table, element) for _, value in pairs(table) do if value == element then return true end end return false end function export.display(frame) local args = frame:getParent().args local result = "" local id = args[1] local data = m[id] local custom = data[custom_parameters] or {} local t = {} table.insert(t, data["date"]) if type(data["authors"]) == table then table.insert(t, parse_authors(data["authors"])) else table.insert(t, data["authors"]) end table.insert(t, data["title"]) if not table.contains(custom, "chapter") then e = args["chapter"] or "" if e ~= "" then table.insert(t, "chapter "..e) end end if not table.contains(custom, "volume") then e = args["volume"] or "" if e ~= "" then table.insert(t, "volume "..e) end end if not table.contains(custom, "section") then e = args["section"] or "" if e ~= "" then table.insert(t, "section "..e) end end if not table.contains(custom, "page") then e = args["page"] or "" if e ~= "" then table.insert(t, "page "..e) end end custom_parameters_display = data[custom_display] or {} override = {} for i, v in ipairs(custom) do if table.contains(args, v) then table.insert(override, i) end end table.sort(override) override = table.concat(override, " ") if table.contains(custom_parameters_display, override) then override_s = "" for i, v in ipairs(custom_parameters_display[override]) do if type(v) == string then override_s = override_s..v else override_s = overrided_s..args[custom[i]] end end table.insert(t, override_s) elseif table.contains(custom_parameters_display, default) then override_s = custom_parameters_display[default] table.insert(t, override_s) end return table.concat(t, ", ") end return export |