Module

Difference between revisions of "Publications"

From ACES

(Created page with "local getArgs = require('Module:Arguments').getArgs local cargo = mw.ext.cargo local p = {} local fields = { "entry", "address", "annote", "author", "booktitle", "chapter...")
 
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
local getArgs = require([[Module:Arguments]]).getArgs
local date = require([[Module:Date]])
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local fstr = mw.ustring.format
local p = {}
local p = {}


local fields = {
local fields = {
     "entry", "address", "annote", "author", "booktitle", "chapter", "edition",
     entry = {},
     "editor", "howpublished", "institution", "journal", "note", "number",
    address = {BibTeX = true},
     "organization", "pages", "publisher", "school", "series", "title", "type",
    annote = {BibTeX = true},
     "volume", "date", "doi", "issn", "isbn", "url", "pdf"
    author = {BibTeX = true},
    booktitle = {BibTeX = true},
    chapter = {BibTeX = true},
    edition = {BibTeX = true},
     editor = {BibTeX = true},
    howpublished = {BibTeX = true},
    institution = {BibTeX = true},
    journal = {BibTeX = true},
    note = {BibTeX = true},
    number = {BibTeX = true},
     organization = {BibTeX = true},
    pages = {BibTeX = true},
    publisher = {BibTeX = true},
    school = {BibTeX = true},
    series = {BibTeX = true},
    title = {BibTeX = true},
    type = {BibTeX = true},
     volume = {BibTeX = true},
    date = {},
    doi = {BibTeX = true},
    issn = {BibTeX = true},
    isbn = {BibTeX = true},
    url = {BibTeX = true},
    _pageName = {},
    pdf = {}
}
}
function p.getBibTeX(entry)
    local out = {}
    table.insert(out, fstr("@%s{%s,", entry.entry, entry._pageName))
    for k, v in pairs(fields) do
        if v.BibTeX and entry[k] and entry[k] ~= "" then
            table.insert(out, fstr("%s = {%s},", k, entry[k]))
        end
    end
    if entry.date and entry.date ~= "" then
        local entryDate = date(entry.date)
        table.insert(out, fstr("year = {%s},", entryDate:getyear()))
        table.insert(out, fstr("month = {%s},", entryDate:getmonth()))
    end
    return table.concat(out, "\n")
end


function p._main(args)
function p._main(args)
     local tables = 'publication'
     local tables = 'publication'
     local fields = table.concat(fields, ",")
     local cargoFields = {}
    for k, _ in pairs(fields) do table.insert(cargoFields, k) end
 
    cargoFields = table.concat(cargoFields, ",")
     local args = {
     local args = {
         where = nil,
         where = nil,
Line 22: Line 67:
         offset = nil
         offset = nil
     }
     }
     local results = cargo.query(tables, fields, args)
     local results = cargo.query(tables, cargoFields, args)


     mw.logObject(results)
     mw.logObject(results)
    mw.logObject(p.getBibTeX(results[1]))
end
end



Revision as of 20:33, 2 September 2021

Documentation for this module may be created at Module:Publications/doc

local getArgs = require([[Module:Arguments]]).getArgs
local date = require([[Module:Date]])
local cargo = mw.ext.cargo
local fstr = mw.ustring.format
local p = {}

local fields = {
    entry = {},
    address = {BibTeX = true},
    annote = {BibTeX = true},
    author = {BibTeX = true},
    booktitle = {BibTeX = true},
    chapter = {BibTeX = true},
    edition = {BibTeX = true},
    editor = {BibTeX = true},
    howpublished = {BibTeX = true},
    institution = {BibTeX = true},
    journal = {BibTeX = true},
    note = {BibTeX = true},
    number = {BibTeX = true},
    organization = {BibTeX = true},
    pages = {BibTeX = true},
    publisher = {BibTeX = true},
    school = {BibTeX = true},
    series = {BibTeX = true},
    title = {BibTeX = true},
    type = {BibTeX = true},
    volume = {BibTeX = true},
    date = {},
    doi = {BibTeX = true},
    issn = {BibTeX = true},
    isbn = {BibTeX = true},
    url = {BibTeX = true},
    _pageName = {},
    pdf = {}
}

function p.getBibTeX(entry)
    local out = {}
    table.insert(out, fstr("@%s{%s,", entry.entry, entry._pageName))
    for k, v in pairs(fields) do
        if v.BibTeX and entry[k] and entry[k] ~= "" then
            table.insert(out, fstr("%s = {%s},", k, entry[k]))
        end
    end
    if entry.date and entry.date ~= "" then
        local entryDate = date(entry.date)
        table.insert(out, fstr("year = {%s},", entryDate:getyear()))
        table.insert(out, fstr("month = {%s},", entryDate:getmonth()))
    end
    return table.concat(out, "\n")
end

function p._main(args)
    local tables = 'publication'
    local cargoFields = {}
    for k, _ in pairs(fields) do table.insert(cargoFields, k) end

    cargoFields = table.concat(cargoFields, ",")
    local args = {
        where = nil,
        join = nil,
        groupBy = nil,
        having = nil,
        orderBy = 'date',
        limit = nil,
        offset = nil
    }
    local results = cargo.query(tables, cargoFields, args)

    mw.logObject(results)
    mw.logObject(p.getBibTeX(results[1]))
end

-- test: =p._main{}
function p.main(frame) return p._main(getArgs(frame)) end

return p