익명
×
새 문서 만들기
여기에 문서 제목을 쓰세요:
We currently have 900 articles on 루리위키. Type your article name above or click on one of the titles below and start writing!



900Articles

모듈:푸른 저편의 포리듬/ 캐릭터 프로필: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
9번째 줄: 9번째 줄:
end
end


-- 안전한 HTML 인코딩 함수 정의
-- 안전한 HTML 인코딩 (mw.text.html_encode 대체)
local function safe_html_encode(s)
local function safe_html_encode(s)
     if not s or s == '' then return '' end
     if not s or s == '' then return '' end
     -- mw.text.escape 대신 mw.text.html_encode를 사용하거나, mw.text가 없다면 일반 문자열로 반환
     -- mw.text.html_encode가 있다면 사용 (가장 안전)
     if mw.text and mw.text.html_encode then
     if mw.text and mw.text.html_encode then
         return mw.text.html_encode(tostring(s))
         return mw.text.html_encode(tostring(s))
     end
     end
     -- 대체 인코딩 (대부분의 위키에서 mw.text가 작동하므로, 이 코드는 보험용)
     -- 없으면 최소한의 수동 인코딩
     s = tostring(s)
     s = tostring(s)
     s = s:gsub('&', '&')
     s = s:gsub('&', '&')
     s = s:gsub('<', '&lt;')
     s = s:gsub('<', '&lt;')
     s = s:gsub('>', '&gt;')
     s = s:gsub('>', '&gt;')
    s = s:gsub('"', '&quot;')
    s = s:gsub("'", '&#39;')
     return s
     return s
end
end


-- 시그니처 기술 수집 (시그니처기술1..10)
-- 시그니처 기술 수집 및 HTML 리스트 반환
local function gather_techs(args)
local function gather_techs(args)
     local techs = {}
     local techs = {}
35번째 줄: 33번째 줄:
         end
         end
     end
     end
    -- 리스트 아이템 HTML로 반환
     if #techs > 0 then
     if #techs > 0 then
         local tstr = '<ul class="prf-list">'
         local tstr = '<ul style="list-style:decimal; margin:0; padding:0 0 0 20px; font-size:95%;">'
         for _, tname in ipairs(techs) do
         for _, tname in ipairs(techs) do
             tstr = tstr .. string.format('<li>%s</li>', safe_html_encode(tname))
             tstr = tstr .. string.format('<li>%s</li>', safe_html_encode(tname))
47번째 줄: 44번째 줄:
end
end


-- 이미지 블록 (탭 기능 대신 선택된 이미지 반환)
-- 이미지 블록 (표 셀 안에 들어갈 위키텍스트)
local function build_image_block(args)
local function build_image_block(args)
     local version = trim(args['버전'] or 'VN')
    -- 탭 기능을 모듈 내에서 구현하면 충돌 위험이 크므로, 첫 번째 이미지 또는 지정된 버전의 이미지를 반환
    local file_name = ''
     local file_name = trim(args['이미지_VN'] or args['이미지_애니'] or '')
      
      
     if version == 'Anime' then
     if file_name ~= '' then
         file_name = trim(args['이미지_Anime'] or '')
         -- 파일명만 인코딩
     else -- VN 또는 기본값
        return string.format('[[파일:%s|250px|center]]', mw.text.encode(file_name))
         file_name = trim(args['이미지_VN'] or '')
     else
         return '[[파일:NoImage.png|250px|center]]'
     end
     end
end


     if file_name ~= '' then
-- 이름 블록 (표 셀 안에 들어갈 HTML)
        -- 파일명만 인코딩 (위키텍스트는 HTML 엔코딩이 아닌 URI 엔코딩이 필요함)
local function build_name_block(args)
        return string.format('<div class="prf-img-wrapper">[[파일:%s|250px|center]]</div>', mw.text.encode(file_name))
    local kr = trim(args['이름'] or '')
     else
    local jp = trim(args['이름_일어'] or '')
         return '<div class="prf-img-wrapper">[[파일:NoImage.png|250px|center]]</div>'
    local en = trim(args['이름_영어'] or '')
    local parts = {}
   
     if kr ~= '' then table.insert(parts, string.format('<strong>%s</strong>', safe_html_encode(kr))) end
   
    local sub_parts = {}
    if jp ~= '' then table.insert(sub_parts, safe_html_encode(jp)) end
    if en ~= '' then table.insert(sub_parts, safe_html_encode(en)) end
      
    if #sub_parts > 0 then
         table.insert(parts, string.format('<div style="font-size:90%%; margin-top:2px;">%s</div>', table.concat(sub_parts, ' / ')))
     end
     end
    return table.concat(parts, '\n')
end
end


70번째 줄: 80번째 줄:
     if not value or value == '' then return '' end
     if not value or value == '' then return '' end
     -- 목록 형태로 반환
     -- 목록 형태로 반환
     return string.format('<li><strong>%s</strong>: %s</li>', safe_html_encode(label), safe_html_encode(value))
     return string.format('<div style="margin: 4px 0;">%s: %s</div>', safe_html_encode(label), safe_html_encode(value))
end
 
-- 섹션 헤더 생성
local function section_header(title)
    return string.format('<div class="prf-header"><h4>%s</h4></div>', safe_html_encode(title))
end
end


96번째 줄: 101번째 줄:
end
end


-- 메인 생성 함수
 
function p.main(frame)
function p.main(frame)
     local parent = frame:getParent() or frame
     local parent = frame:getParent() or frame
104번째 줄: 109번째 줄:
     local theme = args['색상'] and args['색상'] ~= '' and args['색상'] or '#007bff'
     local theme = args['색상'] and args['색상'] ~= '' and args['색상'] or '#007bff'
      
      
    -- ********** 데이터 구성 **********
     local image_block = build_image_block(args)
     local image_block = build_image_block(args)
   
     local name_block = build_name_block(args)
    -- 이름 블록
     local name_block = ''
    name_block = name_block .. string.format('<div class="prf-name-kr">%s</div>', safe_html_encode(args['이름'] or ''))
    local sub_name = {}
    if args['이름_일어'] then table.insert(sub_name, safe_html_encode(args['이름_일어'])) end
    if args['이름_영어'] then table.insert(sub_name, safe_html_encode(args['이름_영어'])) end
    if #sub_name > 0 then
        name_block = name_block .. string.format('<div class="prf-name-sub">%s</div>', table.concat(sub_name, ' / '))
    end
      
      
     -- 섹션별 정보 구성
     -- 섹션별 정보 구성
     local sections = {}
     local basic = table.concat({
   
    -- 1. 기본 정보
    local basic = {
         info_row('성별', args['성별']),
         info_row('성별', args['성별']),
         build_age_row(args),
         build_age_row(args),
129번째 줄: 121번째 줄:
         info_row('머리색', args['머리색']),
         info_row('머리색', args['머리색']),
         info_row('눈색', args['눈색']),
         info_row('눈색', args['눈색']),
     }
     }, '\n')
   
 
    -- 2. FC 프로필
     local fc = table.concat({
     local fc_techs = gather_techs(args)
    local fc = {
         info_row('포지션', args['포지션']),
         info_row('포지션', args['포지션']),
     }
     }, '\n') .. gather_techs(args)
    if fc_techs ~= '' then
 
        -- 시그니처 기술은 별도 HTML로 구성
     local personal = table.concat({
        table.insert(fc, string.format('<li><strong>시그니처 기술</strong>:%s</li>', fc_techs))
    end
   
    -- 3. 개인 정보
     local personal = {
         info_row('학교', args['학교']),
         info_row('학교', args['학교']),
         info_row('거주지', args['거주지']),
         info_row('거주지', args['거주지']),
         info_row('취미', args['취미']),
         info_row('취미', args['취미']),
         info_row('좋아하는 음식', args['좋아하는음식']),
         info_row('좋아하는 음식', args['좋아하는음식']),
     }
     }, '\n')
      
      
    -- 4. 성우
     local voice = table.concat({
     local voice = {
         info_row('일본어', args['성우_JP']),
         info_row('일본어', args['성우_JP']),
         info_row('영어', args['성우_EN']),
         info_row('영어', args['성우_EN']),
     }
     }, '\n')
      
      
    -- 5. 데뷔
     local debut = table.concat({
     local debut = {
         info_row('애니메이션', args['애니_데뷔']),
         info_row('애니메이션', args['애니_데뷔']),
         info_row('게임(VN)', args['게임_데뷔']),
         info_row('게임(VN)', args['게임_데뷔']),
         info_row('만화', args['만화_데뷔']),
         info_row('만화', args['만화_데뷔']),
     }
     }, '\n')
      
      
    -- ********** HTML 문자열 조립 **********
    local html = {}
      
      
     -- 전체 컨테이너 시작
     -- ********** 위키 테이블 문자열 조립 **********
     table.insert(html, string.format('<div class="prf-card-wrap" style="border: 1px solid %s; border-radius: 5px; max-width: 600px; margin: 1em auto;">', safe_html_encode(theme)))
    local wiki_table = {}
     table.insert(html, '<div class="prf-card-inner" style="display: flex; flex-wrap: wrap;">')
 
    -- 1. 전체 컨테이너 테이블 시작 (2열: 이미지 / 정보)
     table.insert(wiki_table, string.format('{| class="wikitable" style="width: 100%%; max-width: 650px; border: 2px solid %s; border-collapse: collapse; margin: 1em auto; font-size: 95%%;"', safe_html_encode(theme)))
     table.insert(wiki_table, '|-')
      
      
     -- 좌측: 이미지 및 스위치 (40%)
     -- 2. 좌측 열 (이미지 영역)
     table.insert(html, '<div class="prf-left-col" style="flex: 0 0 40%; padding: 10px; border-right: 1px solid #ddd;">')
     table.insert(wiki_table, string.format('! style="width: 35%%; vertical-align: top; padding: 10px; background-color: #f8f8f8;" | %s', image_block))
    table.insert(html, image_block)
    -- 버전 스위치 (간단한 HTML 텍스트로 대체)
    table.insert(html, '<div style="text-align: center; font-size: 85%; margin-top: 5px;">(VN / Anime 스위치 필요)</div>')
    table.insert(html, '</div>')
      
      
     -- 우측: 정보 (60%)
     -- 3. 우측 열 (정보 영역)
     table.insert(html, '<div class="prf-right-col" style="flex: 1 1 58%; padding: 10px; background-color: #f9f9f9;">')
     table.insert(wiki_table, '! style="width: 65%%; vertical-align: top; padding: 10px;" |')
      
      
     -- 이름 블록
     -- 우측 영역 내부 내용 (이름, 섹션 헤더, 정보 리스트)
     table.insert(html, string.format('<div class="prf-name-block">%s</div>', name_block))
    local right_content = {}
     table.insert(html, '<hr style="border: 0; border-top: 1px solid #ccc; margin: 8px 0;">')
     table.insert(right_content, string.format('<div style="color:%s; font-weight:bold; font-size:1.4em;">%s</div>', safe_html_encode(theme), name_block))
     table.insert(right_content, '<hr style="border: 0; border-top: 1px solid #ccc; margin: 8px 0;">')
      
      
    -- 섹션 추가 함수 (빈 섹션은 제외)
     local function add_section(title, content)
     local function add_section(title, data_table)
         if trim(content) ~= '' then
        local content = table.concat(data_table, '\n')
             table.insert(right_content, string.format('<h4 style="color:%s; margin:8px 0 4px 0; padding:0; font-size:1em; border-bottom:1px solid %s;">%s</h4>', safe_html_encode(theme), safe_html_encode(theme), safe_html_encode(title)))
         if content ~= '' then
            table.insert(right_content, content)
             table.insert(html, section_header(title))
            table.insert(html, string.format('<ul class="prf-section-list">%s</ul>', content))
         end
         end
     end
     end
198번째 줄: 177번째 줄:
     add_section('데뷔', debut)
     add_section('데뷔', debut)
      
      
     table.insert(html, '</div>') -- prf-right-col 닫기
     table.insert(wiki_table, table.concat(right_content, '\n'))
    table.insert(html, '</div>') -- prf-card-inner 닫기
    table.insert(html, '</div>') -- prf-card-wrap 닫기
      
      
     -- ********** CSS 정의 **********
     -- 4. 테이블 닫기
    local style = string.format([[
     table.insert(wiki_table, '|}')
    <style>
    .prf-name-kr { font-size: 1.3em; font-weight: bold; color: %s; }
    .prf-name-sub { font-size: 0.9em; color: #555; margin-top: 2px; }
     .prf-header h4 { margin: 8px 0 4px 0; padding: 0; font-size: 1em; color: %s; border-bottom: 1px solid %s; font-weight: bold; }
    .prf-section-list, .prf-list { list-style: none; margin: 0 0 10px 0; padding: 0; }
    .prf-section-list li, .prf-list li { margin: 3px 0; font-size: 0.95em; }
    .prf-img-wrapper { text-align: center; }
    @media screen and (max-width: 600px) {
        .prf-left-col, .prf-right-col { flex: 0 0 100%% !important; border-right: none !important; }
        .prf-left-col { border-bottom: 1px solid #ddd; }
    }
    </style>
    ]], theme, theme, theme)


    -- 최종 출력: 스타일 + HTML 문자열
     return table.concat(wiki_table, '\n')
     return style .. table.concat(html, '\n')
end
end


return p
return p

2025년 12월 5일 (금) 03:21 판

이 모듈에 대한 설명문서는 모듈:푸른 저편의 포리듬/ 캐릭터 프로필/설명문서에서 만들 수 있습니다

local p = {}
local mw = mw
local tt = mw.text

-- 안전 문자열 트림
local function trim(s)
    if not s then return '' end
    return tt.trim(tostring(s))
end

-- 안전한 HTML 인코딩 (mw.text.html_encode 대체)
local function safe_html_encode(s)
    if not s or s == '' then return '' end
    -- mw.text.html_encode가 있다면 사용 (가장 안전)
    if mw.text and mw.text.html_encode then
        return mw.text.html_encode(tostring(s))
    end
    -- 없으면 최소한의 수동 인코딩
    s = tostring(s)
    s = s:gsub('&', '&amp;')
    s = s:gsub('<', '&lt;')
    s = s:gsub('>', '&gt;')
    return s
end

-- 시그니처 기술 수집 및 HTML 리스트 반환
local function gather_techs(args)
    local techs = {}
    for i = 1, 10 do
        local k = '시그니처기술' .. i
        if args[k] and args[k] ~= '' then
            table.insert(techs, trim(args[k]))
        end
    end
    if #techs > 0 then
        local tstr = '<ul style="list-style:decimal; margin:0; padding:0 0 0 20px; font-size:95%;">'
        for _, tname in ipairs(techs) do
            tstr = tstr .. string.format('<li>%s</li>', safe_html_encode(tname))
        end
        tstr = tstr .. '</ul>'
        return tstr
    end
    return ''
end

-- 이미지 블록 (표 셀 안에 들어갈 위키텍스트)
local function build_image_block(args)
    -- 탭 기능을 모듈 내에서 구현하면 충돌 위험이 크므로, 첫 번째 이미지 또는 지정된 버전의 이미지를 반환
    local file_name = trim(args['이미지_VN'] or args['이미지_애니'] or '')
    
    if file_name ~= '' then
        -- 파일명만 인코딩
        return string.format('[[파일:%s|250px|center]]', mw.text.encode(file_name))
    else
        return '[[파일:NoImage.png|250px|center]]'
    end
end

-- 이름 블록 (표 셀 안에 들어갈 HTML)
local function build_name_block(args)
    local kr = trim(args['이름'] or '')
    local jp = trim(args['이름_일어'] or '')
    local en = trim(args['이름_영어'] or '')
    local parts = {}
    
    if kr ~= '' then table.insert(parts, string.format('<strong>%s</strong>', safe_html_encode(kr))) end
    
    local sub_parts = {}
    if jp ~= '' then table.insert(sub_parts, safe_html_encode(jp)) end
    if en ~= '' then table.insert(sub_parts, safe_html_encode(en)) end
    
    if #sub_parts > 0 then
        table.insert(parts, string.format('<div style="font-size:90%%; margin-top:2px;">%s</div>', table.concat(sub_parts, ' / ')))
    end
    return table.concat(parts, '\n')
end

-- 라벨+값 행 생성 (값 없으면 빈 문자열)
local function info_row(label, value)
    if not value or value == '' then return '' end
    -- 목록 형태로 반환
    return string.format('<div style="margin: 4px 0;">%s: %s</div>', safe_html_encode(label), safe_html_encode(value))
end

-- 나이 출력 규칙
local function build_age_row(args)
    local nv = trim(args['나이_VN'])
    local na = trim(args['나이_애니'])
    
    local age_str = ''
    if nv ~= '' and na ~= '' then
        age_str = string.format('VN %s / Anime %s', safe_html_encode(nv), safe_html_encode(na))
    elseif nv ~= '' then
        age_str = string.format('VN %s', safe_html_encode(nv))
    elseif na ~= '' then
        age_str = string.format('Anime %s', safe_html_encode(na))
    else
        return ''
    end
    return info_row('나이', age_str)
end


function p.main(frame)
    local parent = frame:getParent() or frame
    local args = parent.args or {}
    for k, v in pairs(args) do args[k] = trim(v) end
    
    local theme = args['색상'] and args['색상'] ~= '' and args['색상'] or '#007bff'
    
    local image_block = build_image_block(args)
    local name_block = build_name_block(args)
    
    -- 섹션별 정보 구성
    local basic = table.concat({
        info_row('성별', args['성별']),
        build_age_row(args),
        info_row('생일', args['생일']),
        info_row('신장', args['신장']),
        info_row('체중', args['체중']),
        info_row('머리색', args['머리색']),
        info_row('눈색', args['눈색']),
    }, '\n')

    local fc = table.concat({
        info_row('포지션', args['포지션']),
    }, '\n') .. gather_techs(args)

    local personal = table.concat({
        info_row('학교', args['학교']),
        info_row('거주지', args['거주지']),
        info_row('취미', args['취미']),
        info_row('좋아하는 음식', args['좋아하는음식']),
    }, '\n')
    
    local voice = table.concat({
        info_row('일본어', args['성우_JP']),
        info_row('영어', args['성우_EN']),
    }, '\n')
    
    local debut = table.concat({
        info_row('애니메이션', args['애니_데뷔']),
        info_row('게임(VN)', args['게임_데뷔']),
        info_row('만화', args['만화_데뷔']),
    }, '\n')
    
    
    -- ********** 위키 테이블 문자열 조립 **********
    local wiki_table = {}

    -- 1. 전체 컨테이너 테이블 시작 (2열: 이미지 / 정보)
    table.insert(wiki_table, string.format('{| class="wikitable" style="width: 100%%; max-width: 650px; border: 2px solid %s; border-collapse: collapse; margin: 1em auto; font-size: 95%%;"', safe_html_encode(theme)))
    table.insert(wiki_table, '|-')
    
    -- 2. 좌측 열 (이미지 영역)
    table.insert(wiki_table, string.format('! style="width: 35%%; vertical-align: top; padding: 10px; background-color: #f8f8f8;" | %s', image_block))
    
    -- 3. 우측 열 (정보 영역)
    table.insert(wiki_table, '! style="width: 65%%; vertical-align: top; padding: 10px;" |')
    
    -- 우측 영역 내부 내용 (이름, 섹션 헤더, 정보 리스트)
    local right_content = {}
    table.insert(right_content, string.format('<div style="color:%s; font-weight:bold; font-size:1.4em;">%s</div>', safe_html_encode(theme), name_block))
    table.insert(right_content, '<hr style="border: 0; border-top: 1px solid #ccc; margin: 8px 0;">')
    
    local function add_section(title, content)
        if trim(content) ~= '' then
            table.insert(right_content, string.format('<h4 style="color:%s; margin:8px 0 4px 0; padding:0; font-size:1em; border-bottom:1px solid %s;">%s</h4>', safe_html_encode(theme), safe_html_encode(theme), safe_html_encode(title)))
            table.insert(right_content, content)
        end
    end

    add_section('기본 정보', basic)
    add_section('FC 프로필', fc)
    add_section('개인 정보', personal)
    add_section('성우', voice)
    add_section('데뷔', debut)
    
    table.insert(wiki_table, table.concat(right_content, '\n'))
    
    -- 4. 테이블 닫기
    table.insert(wiki_table, '|}')

    return table.concat(wiki_table, '\n')
end

return p