mirror of
https://github.com/seigler/dash-docs
synced 2025-07-27 09:46:12 +00:00
Randomize the ordering of clients displayed.
This commit is contained in:
parent
47b73f5d6d
commit
6850fc8c83
2 changed files with 26 additions and 2 deletions
23
_plugins/random.rb
Normal file
23
_plugins/random.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
class Random < Liquid::Tag
|
||||
Syntax = /(\w+[.]?\w+)\s+(\w+)/o
|
||||
|
||||
def initialize(tag_name, markup, tokens)
|
||||
if markup =~ Syntax
|
||||
@collection_name = $1
|
||||
@randomized_name = $2
|
||||
else
|
||||
raise SyntaxError.new("Syntax Error in 'random' - Valid syntax: random [source] [var]")
|
||||
end
|
||||
super
|
||||
end
|
||||
|
||||
def render(context)
|
||||
collection = context[@collection_name]
|
||||
collection = collection.sort_by{rand}
|
||||
context[@randomized_name] = collection
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
Liquid::Template.register_tag('random', Random)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue