「モジュール:SignalinstWiki」の版間の差分
細編集の要約なし |
細編集の要約なし |
||
| (同じ利用者による、間の18版が非表示) | |||
| 27行目: | 27行目: | ||
if propertySplit == nil or propertySplit == '' then propertySplit = "、" end | if propertySplit == nil or propertySplit == '' then propertySplit = "、" end | ||
-- 元の propertyValue に「など」が含まれているかチェック | |||
local hasNado = false | |||
if string.find(propertyValue, "など") then | |||
hasNado = true | |||
end | |||
-- Valueを分割 | |||
local splitValues = {} | local splitValues = {} | ||
local pattern = "(.-)" .. propertySplit | |||
local pattern = "(.-)" .. propertySplit | |||
-- propertyValue の末尾に propertySplit を追加することで、最後の要素が正しく取得されるようにする | -- propertyValue の末尾に propertySplit を追加することで、最後の要素が正しく取得されるようにする | ||
| 38行目: | 42行目: | ||
-- 各要素の前後の空白をトリム(取り除く) | -- 各要素の前後の空白をトリム(取り除く) | ||
local trimmedPart = part:match("^%s*(.-)%s*$") | local trimmedPart = part:match("^%s*(.-)%s*$") | ||
-- ここで「など」を空文字列に置き換える処理 | |||
-- 各部分から「など」を削除してからリストに追加する | |||
trimmedPart = string.gsub(trimmedPart, "など", "") | |||
if trimmedPart ~= '' then -- 空文字列でない場合のみ追加 | if trimmedPart ~= '' then -- 空文字列でない場合のみ追加 | ||
table.insert(splitValues, trimmedPart) | table.insert(splitValues, trimmedPart) | ||
| 49行目: | 58行目: | ||
end | end | ||
-- | -- ここで最終的な文字列を構築 | ||
local finalOutput = table.concat(smwProperties, propertySplit) | |||
-- もし元の propertyValue に「など」が含まれていた場合、最終出力の末尾に追加 | |||
if hasNado then | |||
-- 結合された文字列が空でない場合のみ、区切り文字を付けて「など」を追加 | |||
if finalOutput ~= '' then | |||
finalOutput = finalOutput .. "など" | |||
else | |||
-- 全くプロパティが生成されなかった場合でも「など」だけ返す | |||
finalOutput = "など" | |||
end | |||
end | |||
return finalOutput | |||
end | |||
function p.categoriesToTemplate(frame) | |||
local args = { | |||
title = "カテゴリ一覧", | |||
opened = "False" | |||
} | |||
local categories = mw.text.trim( | |||
frame:expandTemplate{ title = "カテゴリ一覧" } or "" | |||
) | |||
local i = 1 | |||
for category in mw.text.gsplit(categories, ",", true) do | |||
category = mw.text.trim(category) | |||
if category ~= "" then | |||
local categoryName = mw.text.trim( | |||
category:gsub("^カテゴリ:", "") | |||
) | |||
local pages = mw.text.trim( | |||
frame:expandTemplate{ | |||
title = "カテゴリ別ページ一覧", | |||
args = { category } | |||
} or "" | |||
) | |||
args["header" .. i] = "[[:カテゴリ:"..categoryName.."|"..categoryName.."]]" | |||
args["content" .. i] = pages | |||
i = i + 1 | |||
end | |||
end | |||
return frame:expandTemplate{ | |||
title = "ナビゲーションボックス", | |||
args = args | |||
} | |||
end | end | ||
return p | return p | ||