打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

本站正在进行早期测试,目前仍存在许多内容的缺失。

模块:CSS:修订间差异

来自星砂岛百科
Sizau留言 | 贡献
创建页面
 
Sizau留言 | 贡献
无编辑摘要
第1行: 第1行:
local common = require('Module:Common')
local p = {}
local p = {}
local LUACACHE_NAMESPACE = 'css:templatestyles'
local LUACACHE_VERSION = '2026-03-09'


local function trim(value)
local function trim(value)
第47行: 第42行:


     local ts_path = namespace_prefix(ns_code) .. target .. '/styles.css'
     local ts_path = namespace_prefix(ns_code) .. target .. '/styles.css'
     local page_key = get_fullpagename()
     frame:callParserFunction('vardefine', 'ts_path', ts_path)
     local cache_key = common.buildLuaCacheKey(LUACACHE_NAMESPACE, LUACACHE_VERSION, page_key .. '|' .. ts_path)
 
     local loaded = common.luaCacheGet(cache_key)
     local loaded_key = 'ts_loaded_' .. ts_path
     if loaded ~= nil then
     local loaded = trim(frame:callParserFunction('var', loaded_key))
     if loaded ~= '' then
         return ''
         return ''
     end
     end


     common.luaCacheSet(cache_key, '1')
     frame:callParserFunction('vardefine', loaded_key, '1')
     return frame:extensionTag('templatestyles', '', { src = ts_path })
     return frame:extensionTag('templatestyles', '', { src = ts_path })
end
end

2026年3月12日 (四) 05:03的版本

概述

CSS 用于按需注入 TemplateStyles,并确保同一页面上同一路径的样式只加载一次。

用法

{{#invoke:CSS|main|Item}}
local css = require('Module:CSS')
return css.quickCall('Item')

示例

{{#invoke:CSS|main|Item|10}}

函数

  • call:按名称、命名空间代码和文件名拼出样式页路径并注入。
  • quickCallcall 的简写封装。
  • main:供 #invoke 直接调用的入口。

local p = {}

local function trim(value)
    if value == nil then
        return ''
    end
    return mw.text.trim(tostring(value))
end

local function get_args(frame)
    if frame == mw.getCurrentFrame() then
        return require('Module:ProcessArgs').merge(true)
    end
    return frame
end

local function namespace_prefix(code)
    local normalized = trim(code)
    if normalized == '828' then
        return 'Module:'
    end
    if normalized == '4' then
        return 'Project:'
    end
    if normalized == '0' then
        return ':'
    end
    return 'Template:'
end

local function get_fullpagename()
    local title = mw.title.getCurrentTitle()
    return title and title.prefixedText or ''
end

function p.call(name, ns_code)
    local frame = mw.getCurrentFrame()
    local target = trim(name)
    if target == '' then
        target = get_fullpagename()
    end

    local ts_path = namespace_prefix(ns_code) .. target .. '/styles.css'
    frame:callParserFunction('vardefine', 'ts_path', ts_path)

    local loaded_key = 'ts_loaded_' .. ts_path
    local loaded = trim(frame:callParserFunction('var', loaded_key))
    if loaded ~= '' then
        return ''
    end

    frame:callParserFunction('vardefine', loaded_key, '1')
    return frame:extensionTag('templatestyles', '', { src = ts_path })
end

function p.main(frame)
    local args = get_args(frame)
    return p.call(args[1], args[2])
end

return p