মডিউল:Poetry

উইকিসংকলন থেকে

Summary[সম্পাদনা]

Lua support routines for poetry-related templates.

Entry Points[সম্পাদনা]

  • divify: encapsulate each separate line in passed text block in <div>-</div> sequences.
  • rmuid: remove any and all occurrences of a list of values (typically unit-name-codes e.g. "em", "px" etc.) from passed string and return whatever remains. Useful for isolating multiplier factors prior to use in later calculations.

Utilisation[সম্পাদনা]

Currently used by these templates:

  • {{constant leading}} (alias: {{divify}}: Mark text block to be rendered with equal line height separating both normal lines and paragraphs.
  • {{stanza}}: Format stanzas of poetry with common margin and hanging indent characteristics. Also supports presentation of an optional leading drop-capital letter.

--[[
divify

Main entry point for Lua function to wrap individual lines of poetry in passed string in protective <div>..</div> pairs.

Usage:

  {{#invoke:Poetry|divify|poetry-string}}
]]

Poetry = {};

function Poetry.divify(frame)
    rhyme = frame.args[1] or ""

    -- Noting passed in? Acceptable as response.
    if rhyme == '' then
        return rhyme
    end

    return '<div>' .. mw.ustring.gsub( rhyme, '\n', '</div>\n<div>' ).. '</div>'
end

--[[
rmuid

Main entry point for Lua function to remove any and all unit-ids (typically "em", "ex" etc.) from quantity presented and return truncated result.

Usage:

  {{#invoke:Poetry|rmuid|3em|cm|em|ex|in|mm|pc|pt|px}}

  would in this case return the string "3".
]]

function Poetry.rmuid(frame)
    local quantity = frame.args[1] or ""

    -- Iterate over remaining arguments, and remove each string found from quantity.
    key = 2
    while ( frame.args[key] ~= nil ) do
        quantity = mw.ustring.gsub( quantity, frame.args[key], '' )
        key = key + 1
    end

    return quantity
end

return Poetry