-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(countdown): move streams into lua (#4372)
* refactor `Module:Links/Stream` - get rid of some anno warnings - add display components (in prep for moving it from js to lua) - add filter function - allow 2nd stream for any platform * add `module:COuntdown` * adjust the js & add option to not show streams * make space between the streams options * move stream adding completely to lua * simplify as per review * do not display dash if live is over (12h, same as in js) * rename const var as per review * refactor finished handling * fix * invert * Update standard/links_stream.lua * mirror old behaviour exactly - let js add the ` - ` with the same criteria as before - display streams if finished is not set but the time switch has already happened --> it will again show the date together with the stream but without dash and countdown * kick unused const var * Update standard/links_stream.lua Co-authored-by: Rikard Blixt <rikardblixt@gmail.com> * as per review * as per review * as per review * thx, linter --------- Co-authored-by: Rikard Blixt <rikardblixt@gmail.com>
- Loading branch information
Showing
4 changed files
with
215 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
-- @Liquipedia | ||
-- wiki=commons | ||
-- page=Module:Countdown | ||
-- | ||
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute | ||
-- | ||
|
||
local Arguments = require('Module:Arguments') | ||
local DateExt = require('Module:Date/Ext') | ||
local Logic = require('Module:Logic') | ||
local Lua = require('Module:Lua') | ||
|
||
local StreamLinks = Lua.import('Module:Links/Stream') | ||
|
||
local Countdown = {} | ||
|
||
---@param frame Frame | ||
---@return string | ||
function Countdown.create(frame) | ||
return Countdown._create(Arguments.getArgs(frame)) | ||
end | ||
|
||
---@param args table | ||
---@return string | ||
function Countdown._create(args) | ||
if Logic.isEmpty(args.date) and not args.timestamp then | ||
return '' | ||
end | ||
|
||
local wrapper = mw.html.create('span') | ||
:addClass('timer-object') | ||
|
||
if Logic.readBool(args.rawcountdown) then | ||
wrapper:addClass('timer-object-countdown-only') | ||
end | ||
if Logic.readBool(args.rawdatetime) then | ||
wrapper:addClass('timer-object-datetime-only') | ||
end | ||
|
||
-- Timestamp | ||
local timestamp = args.timestamp or DateExt.readTimestampOrNil(args.date) or 'error' | ||
wrapper:attr('data-timestamp', timestamp) | ||
|
||
local streams | ||
if Logic.readBool(args.finished) then | ||
wrapper:attr('data-finished', 'finished') | ||
elseif not Logic.readBool(args.nostreams) then | ||
streams = StreamLinks.buildDisplays(StreamLinks.filterStreams(args)) | ||
end | ||
if streams then | ||
streams = table.concat(streams, ' ') | ||
wrapper:attr('data-hasstreams', 'true') | ||
end | ||
|
||
|
||
if args.text then | ||
wrapper:attr('data-countdown-end-text', args.text) | ||
end | ||
if args.separator then | ||
wrapper:attr('data-separator', args.separator) | ||
end | ||
|
||
wrapper:wikitext(args.date) | ||
|
||
if Logic.isEmpty(streams) then | ||
return tostring(wrapper) | ||
end | ||
|
||
return tostring(mw.html.create() | ||
:node(wrapper) | ||
:wikitext(streams) | ||
) | ||
end | ||
|
||
return Countdown |
Oops, something went wrong.