לדלג לתוכן

יחידה:עיצוב יצירות מוזיקליות

מתוך חב"דפדיה, אנציקלופדיה חב"דית חופשית

ניתן ליצור תיעוד על היחידה הזאת בדף יחידה:עיצוב יצירות מוזיקליות/תיעוד

local p = {}
local Linker = require('Module:סוגריים')
local SpecialCharDecoder = require('Module:קידוד תווים מיוחדים')
local StringUtil = require('Module:String')
local hebrewChars = "א,ב,ג,ד,ה,ו,ז,ח,ט,י,כ,ל,מ,נ,ס,ע,פ,צ,ק,ר,ש,ת,ך,ם,ן,ף,ץ"

local function formatTitle(name, isSingle, isAlbum, isBold)
	-- Decode and clean the name
	frame_name = SpecialCharDecoder.decode_html_entities_internal(Linker.remove_linker_internal(name))

	-- Frame for Hebrew detection
    local frame = {
        args = {
            [1] = frame_name,
            [2] = hebrewChars
        }
    }

	-- Wrapping setup
    local ltrWrapper = '<span dir="ltr">%s</span>'
    local rtlWrapper = '<span dir="rtl">%s</span>'

    -- Apply bold if needed
    local title = isBold == 'כן' and string.format("<b>%s</b>", name) or name

	-- Apply album/single-specific formatting
    if isSingle == 'כן' then
        title = string.format('"%s"', title)
        return string.format(ltrWrapper, title)
    elseif isAlbum == 'כן' then
        if StringUtil.contains_any_csv(frame) then
            -- Hebrew → add quotes
            title = string.format('"%s"', title)
            return string.format(rtlWrapper, title)
        else
            -- Non-Hebrew → make italic
            title = string.format("<i>%s</i>", title)
            return string.format(ltrWrapper, title)
        end
    else
        -- Default handling
        if StringUtil.contains_any_csv(frame) then
            return string.format(rtlWrapper, title)
        else
            return string.format(ltrWrapper, title)
        end
    end
end

function p.main(frame)
    local args = frame:getParent().args
    local isSingle = args['סינגל'] or 'לא'
    local isAlbum = args['אלבום'] or 'לא'
    local isBold = args['הדגשה'] or 'כן'

    local formattedTitle = formatTitle(args['שם'], isSingle, isAlbum, isBold) or ''

    -- Handle שם2 if it exists
    if args['שם2'] and args['שם2'] ~= '' then
        local secondaryTitle = formatTitle(args['שם2'], isSingle, isAlbum, 'לא')
        formattedTitle = formattedTitle .. ' / ' .. secondaryTitle
    end
    
    return formattedTitle
end

return p