Content deleted Content added
create; |
No edit summary |
||
(6 intermediate revisions by 2 users not shown) | |||
Line 15:
identifiers.set_selected_modules (cfg, utilities); -- so that functions in Identifiers can see the selected cfg tables and selected Utilities module
local Frame; -- local copy of <frame> from main(); nil else
local this_page = mw.title.getCurrentTitle(); -- used to limit categorization to certain namepsaces
Line 123 ⟶ 124:
--[[--------------------------<
this function applies cs1|2 template style sheet to a rendered identifier or error message
supported identifier templates are:▼
{{arxiv}} {{bibcode}} {{biorxiv}} {{citeseerx}} {{doi}}▼
{{hdl}} {{isbn}} {{issn}} {{jfm}} {{jstor}}▼
{{medrxiv}} {{mr}} {{oclc}} {{osti}} {{pmc}}▼
{{pmid}} {{ssrn}} {{zbl}}▼
]]
local function render_final (output)
if not Frame then -- not set when this module called from another module
Frame = mw.getCurrentFrame(); -- get the calling module's frame so that we can call extensionTag()
end
return substitute ('$1$2', {▼
output -- to the rendered identifier or error message
});▼
end
--[[--------------------------< _ M A I N >--------------------------------------------------------------------
entry point when called from another module; example:
local rendered_identifier = require ('Module:CS1 identifiers')._main ({'10.4231/sommat', _template = 'doi', ['doi-access'] = 'free', ['doi-broken-date'] = 'June 2025'});
▲supported identifier templates are:
▲ {{arxiv}} {{asin}} {{bibcode}} {{biorxiv}} {{citeseerx}} {{doi}}
▲ {{hdl}} {{isbn}} {{ismn}} {{issn}} {{jfm}} {{jstor}}
▲ {{medrxiv}} {{mr}} {{oclc}} {{ol}} {{osti}} {{pmc}}
▲ {{pmid}} {{sbn}} {{ssrn}} {{s2cid}} {{zbl}}
<args_t> is a table of all parameters needed to properly render the identifier
]]
Line 170 ⟶ 177:
repeat -- loop until no
local params_t = params_get (args_t, i); -- get the parameters associated with enumerator <i>
params_t[template_name] = params_t[1] or params_t['id'];
params_t._template = nil; -- unset as no longer needed
if not params_t[template_name] then -- in case params_t[1] and params_t.id are nil
params_t[template_name] = ''; -- set <id> to empty string
return render_final ( -- make an error message and done
message_prefix,
substitute ('[[Template:$1|help]]', template_name),
no_cat and '' or substitute ('[[Category:Pages with $1 errors]]', template_name:upper())
}));
end
params_t[i] = nil; -- unset these as no longer needed
Line 182 ⟶ 194:
local Embargo = params_t['pmc-embargo-date']; -- {{pmc}} only
local Class = params_t['class']; -- {{arxiv}} only
local AsinTLD = params_t['asin-tld']; -- {{asin}} only
ID_list_t, ID_list_coins_t = identifiers.identifier_lists_get (params_t, {DoiBroken = DoiBroken, Embargo = Embargo, Class = Class, ASINTLD = AsinTLD}, {}); -- {} is a placeholder for unused ID_support{}
rendered_id = ID_list_t[1];
Line 220 ⟶ 233:
if leadout then -- extra text goes between last two identifiers in the list
return render_final (mw.text.listToText (rendered_ids_t, list_separator, leadout)); -- make a list, add templatestyles, and done
end
return render_final (table.concat (rendered_ids_t, list_separator));
end
Line 229 ⟶ 242:
--[[--------------------------< M A I N >----------------------------------------------------------------------
entry point from an invoke
{{#invoke:identifiers|main|_template=<identifier name>}}▼
▲ {{#invoke:CS1 identifiers|main|_template=<identifier name>}}
]]
local function main (frame)
Frame = frame; -- make a copy for rendering final output
local args_t = get_args (frame); -- extract the arguments
return _main (args_t); -- render the identifier and done
▲ return substitute ('$1$2', {
▲ frame:extensionTag ('templatestyles', '', {src='Module:Citation/CS1/styles.css'}),
▲ });
end
Line 247 ⟶ 260:
return {
main = main, -- entry point from an invoke (in a template usually)
_main = _main -- entry point when called from another module
}
|