Created
June 25, 2014 08:05
-
-
Save fcalderan/2098b6af9b3275ff890d to your computer and use it in GitHub Desktop.
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
# A Liquid tag for random number generation | |
# Usage: {% random min:max %} where min and max are integers and min < max | |
module Jekyll | |
class Random < Liquid::Tag | |
def initialize(tag_name, range, tokens) | |
super | |
limits = range.split(":") | |
@min = limits[0].to_i | |
@max = limits[1].to_i | |
end | |
def render(context) | |
(@min + rand(@max - @min)).to_s | |
end | |
end | |
end | |
Liquid::Template.register_tag('random', Jekyll::Random) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment