Created
June 17, 2015 00:44
-
-
Save shaneriley/7792b5ebbb3df4d41c06 to your computer and use it in GitHub Desktop.
UiHelper
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
module UiHelper | |
def dummy_image(width, height, background=nil, text=nil) | |
background = background ? "/#{background}" : "" | |
text = text ? "/#{text}" : "" | |
content_tag :img, nil, alt: "", "data-src" => "/placeholder/#{width}x#{height}#{background}#{text}" | |
end | |
def lorem_paragraph(quantity = 3) | |
Faker::Lorem.paragraphs(quantity).join | |
end | |
def lorem_words(num) | |
num = around(num) if num.is_a?(Range) | |
Faker::Lorem.words(num).join(' ').html_safe | |
end | |
def around(range) | |
range.to_a.sample | |
end | |
def sometimes(num=3) | |
if num == around(1..num) | |
yield | |
end | |
end | |
def lorem_phone(format = "(###) ###-####") | |
format.gsub(/#/) { rand(9) + 1 } | |
end | |
def lorem_number(length = 3) | |
(1..length).map { rand(10) }.join | |
end | |
def lorem_date(format = "m/d/Y") | |
year = (rand * 2).ceil + Time.now.year - 2 | |
month = (rand * 12).ceil | |
day = (rand * 31).ceil | |
format.gsub(/[mdY]/, "m" => month, "d" => day, "Y" => year) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment