Module:Step vis: Difference between revisions

ArrowHead294 (talk | contribs)
mNo edit summary
Ganaram inukshuk (talk | contribs)
m an underscore
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
local tip = require("Module:Template input parse")
local tip   = require("Module:Template input parse")
local yesno = require("Module:Yesno")
local yesno = require("Module:Yesno")
local p = {}
local p = {}


-- Helper function
-- Helper function
-- Create a step visualization that's based on the table on the diasem page
-- Create a step visualization
function p.step_pattern_to_visualization(step_pattern, debug_mode)
function p._step_vis(step_pattern)
local step_pattern = step_pattern or { 5, 2, 5, 0, 5, 2, 0 }
local step_pattern = step_pattern or { 5, 2, 5, 0, 5, 2, 0 }
local left_border = (debug_mode == true and "├" or "├") -- U+251C ├
local left_border         = "├"     -- U+251C ├
local right_border = (debug_mode == true and "┤" or "┤") -- U+2524 ┤
local right_border       = "┤"     -- U+2524 ┤
local no_border = (debug_mode == true and "─" or "─") -- U+2500 ─
local no_border           = "─"     -- U+2500 ─
local double_border = (debug_mode == true and "╫" or "╫") -- U+256B ╫
local double_border       = "╫"     -- U+256B ╫
local double_border_left = (debug_mode == true and "╟" or "╟") -- U+255F ╟
local double_border_left = "╟"     -- U+255F ╟
local double_border_right = (debug_mode == true and "╢" or "╢") -- U+2562 ╢
local double_border_right = "╢"     -- U+2562 ╢
local single_border = (debug_mode == true and "┼" or "┼") -- U+253C ┼
local single_border       = "┼"     -- U+253C ┼
local step_visualization = ""
local step_visualization = ""
Line 42: Line 42:
  of a 4-digit code point is 8 characters long, so removing the last box-drawing character means
  of a 4-digit code point is 8 characters long, so removing the last box-drawing character means
  removing the last 8 characters representing it, between indices -1 and -9
  removing the last 8 characters representing it, between indices -1 and -9
- This removes the double centre border at the end if the second-to-last and last steps are both 0
- This removes the double centre border at the end if the second-to-last and last steps are both 0.
- In debugging mode, the HTML entities themselves are displayed, so the index is -13 instead of -9
]]--
]]--
step_visualization = string.sub(step_visualization, 1, (debug_mode == true and -13 or -9))
step_visualization = string.sub(step_visualization, 1, -9)
end
end
current_step_vis = double_border_right
current_step_vis = double_border_right
Line 77: Line 76:


-- Wrapper function for step visualization
-- Wrapper function for step visualization
function p.step_vis_frame(frame)
function p.step_vis(frame)
local step_pattern = tip.parse_numeric_entries(frame.args["Step Pattern"], " ")
local step_pattern = tip.parse_numeric_entries(frame.args["Step Pattern"], " ")
local debugg = yesno(frame.args["debug"])
local debugg = yesno(frame.args["debug"])
return p.step_pattern_to_visualization(step_pattern, debugg)
local result = p._step_vis(step_pattern)
-- Debugger option
if debugg == true then
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>"
end
return frame:preprocess(result)
end
end


return p
return p