Modul:Path
| Ta modul je ocenjen kot beta in je pripravljen za široko uporabo. Še vedno je nov in ga je treba uporabljati previdno, da se zagotovijo pričakovani rezultati. |
This module offers utilities to convert paths into different formats.
Functions
Info: In all functions the |1= argument can indifferently be a relative (i.e. beginning with ./ or ../ or /) or an absolute path.
abs
The abs function parses the |1= argument and returns it as an absolute path.
Examples
{{#invoke:path|abs|./example}}- ↳ Modul:Path/example
{{#invoke:path|abs|.}}- ↳ Modul:Path
{{#invoke:path|abs|Wikipedia:Lua}}- ↳ Wikipedia:Lua
{{#invoke:path|abs}}- ↳ Modul:Path
rel
The rel function parses the |1= argument and returns it as a relative path.
Examples
{{#invoke:path|rel|Module:Path/example}}- ↳ Module:Path/example
{{#invoke:path|rel|Module:Path}}- ↳ Module:Path
{{#invoke:path|rel|Wikipedia:Lua}}- ↳ Wikipedia:Lua
{{#invoke:path|rel}}- ↳ .
[[Module:Path/example|{{#invoke:path|rel|Module:Path/example}}]]- ↳ Module:Path/example
- See also {{Relative link}}
- ↳ Module:Path/example
sub
The sub function parses the |1= argument and returns it as a partial path with only the subpages shown.
Examples
{{#invoke:path|sub|Module:Path/example}}- ↳ Module:Path/example
{{#invoke:path|sub|Module:Path}}- ↳ Module:Path
{{#invoke:path|sub|Wikipedia:Lua}}- ↳ Wikipedia:Lua
{{#invoke:path|sub}}- ↳
[[Module:Path/example|{{#invoke:path|sub|Module:Path/example}}]]- ↳ Module:Path/example
- See also {{Relative link implicit}}
- ↳ Module:Path/example
See also
| Zgornja dokumentacija je vključena iz Modul:Path/dok. (uredi | zgodovina) Urejevalci lahko preizkušate ta modul v peskovniku (ustvari | mirror) in testnihprimerih (ustvari). Prosimo, da dodate kategorije v /dok podstran. Podstrani te predloge. |
require[[strict]]
local function split_path (path)
local parts = {}
local len = 0
for token in path:gmatch("[^/]+") do
len = len + 1
parts[len] = token
end
return parts, len
end
local function get_abs_path (current, page)
local tbl_i, len_i = split_path(page)
local tbl_o
local len_o
if tbl_i[1] == '.' or tbl_i[1] == '..' then
tbl_o, len_o = split_path(current)
else
tbl_i[1] = tbl_i[1]:gsub('^([^:]?)([^:]*)(:?)(.?)',
function (s1, s2, s3, s4)
if s3 == '' then return s1:upper() .. s2 end
return s1:upper() .. s2 .. s3 .. s4:upper()
end,
1
)
tbl_o = {}
len_o = 0
end
for key, val in ipairs(tbl_i) do
if val == '..' then
if len_o < 1 then
error('Module:Path: invalid path', 0) end
tbl_o[len_o] = nil
len_o = len_o - 1
elseif val ~= '.' then
len_o = len_o + 1
tbl_o[len_o] = val
end
end
if len_o < 1 then
tbl_o[1] = ''
len_o = 1
end
return tbl_o, len_o
end
local function get_rel_path (current, page, add_prefixes)
local tbl_i, len_i = get_abs_path(current, page)
local tbl_c, len_c = split_path(current)
local tbl_o = {}
local len_o = 0
local minlen
local new_at = 0
if len_c < len_i then minlen = len_c else minlen = len_i end
for idx = 1, minlen do
if tbl_c[idx] ~= tbl_i[idx] then
new_at = idx
break
end
end
if new_at == 1 then return table.concat(tbl_i, '/') end
if add_prefixes then
if new_at == 0 then
tbl_o[1] = '.'
new_at = minlen + 1
end
for idx = new_at, len_c do
len_o = len_o + 1
tbl_o[len_o] = '..'
end
if len_o < 1 then len_o = 1 end
elseif new_at == 0 then new_at = minlen + 1 end
for idx = new_at, len_i do
len_o = len_o + 1
tbl_o[len_o] = tbl_i[idx]
end
return table.concat(tbl_o, '/')
end
local iface = {}
iface.abs = function (frame)
local page = frame.args[1]
if page ~= nil then page = page:match'^%s*(.*%S)' end
if page == nil then return mw.title.getCurrentTitle().prefixedText end
local retval, _ = table.concat(get_abs_path(
mw.title.getCurrentTitle().prefixedText,
page:gsub('^%s*/%s*', './', 1)
), '/')
return retval
end
iface.rel = function (frame)
local page = frame.args[1]
if page ~= nil then page = page:match'^%s*(.*%S)' end
if page == nil then return '.' end
return get_rel_path(mw.title.getCurrentTitle().prefixedText,
page:gsub('^%s*/%s*', './', 1), true)
end
iface.sub = function (frame)
local page = frame.args[1]
if page ~= nil then page = page:match'^%s*(.*%S)' end
if page == nil then return '' end
return get_rel_path(mw.title.getCurrentTitle().prefixedText,
page:gsub('^%s*/%s*', './', 1), false)
end
return iface
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.
Index:
pl ar de en es fr it arz nl ja pt ceb sv uk vi war zh ru af ast az bg zh-min-nan bn be ca cs cy da et el eo eu fa gl ko hi hr id he ka la lv lt hu mk ms min no nn ce uz kk ro simple sk sl sr sh fi ta tt th tg azb tr ur zh-yue hy my ace als am an hyw ban bjn map-bms ba be-tarask bcl bpy bar bs br cv nv eml hif fo fy ga gd gu hak ha hsb io ig ilo ia ie os is jv kn ht ku ckb ky mrj lb lij li lmo mai mg ml zh-classical mr xmf mzn cdo mn nap new ne frr oc mhr or as pa pnb ps pms nds crh qu sa sah sco sq scn si sd szl su sw tl shn te bug vec vo wa wuu yi yo diq bat-smg zu lad kbd ang smn ab roa-rup frp arc gn av ay bh bi bo bxr cbk-zam co za dag ary se pdc dv dsb myv ext fur gv gag inh ki glk gan guw xal haw rw kbp pam csb kw km kv koi kg gom ks gcr lo lbe ltg lez nia ln jbo lg mt mi tw mwl mdf mnw nqo fj nah na nds-nl nrm nov om pi pag pap pfl pcd krc kaa ksh rm rue sm sat sc trv stq nso sn cu so srn kab roa-tara tet tpi to chr tum tk tyv udm ug vep fiu-vro vls wo xh zea ty ak bm ch ny ee ff got iu ik kl mad cr pih ami pwn pnt dz rmy rn sg st tn ss ti din chy ts kcg ve









