コンテンツにスキップ

英文维基 | 中文维基 | 日文维基 | 草榴社区

モジュール:Counter

モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

Template:Counter用のモジュール。

書式

[編集]

{{#invoke:Counter|Main}}

local p = {}

function p.Main(frame)

    local type = string.lower(frame.args['type'])
    if type == '' then type = 'decimal' end

    local types = {
        ['lower-roman'] = 'lower-roman',
        lr = 'lower-roman',
        ['upper-roman'] = 'upper-roman',
        ur = 'upper-roman',
        ['lower-greek'] = 'lower-greek',
        lg = 'lower-greek',
        decimal = 'decimal',
        d = 'decimal',
        ['lower-alpha'] = 'lower-alpha',
        la = 'lower-alpha',
        ['upper-alpha'] = 'upper-alpha',
        ua = 'upper-alpha'
    }
    type = types[type]
    if type == nil then
        return '<span style="color: red; font-weight: bold;">エラー: type引数が不正です</span>'
    end

    local action = frame.args['action']
    if action == nil then
        action = ''
    else
        action = string.lower(action)
    end
    if action == 'init' or action == 'initialize' then
        return frame:extensionTag{name = 'templatestyles', args = {src = 'Template:Counter/styles.css'}}
    elseif action == 'reset' then
        return '<div class="tl_counter_' .. type .. '_reset"></div>'
    elseif action == 'preserve' then
        return '<div class="tl_counter_' .. type .. '_preserve" style="display: inline-block;"></div>'
    elseif action == '' or action == 'normal' then
        return '<div class="tl_counter_' .. type .. '" style="display: inline-block;"></div>'
    else
        return '<span style="color: red; font-weight: bold;">エラー: action引数が不正です</span>'
    end

end

return p