Skip to content

Instantly share code, notes, and snippets.

@shaneriley
Created June 17, 2015 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaneriley/7792b5ebbb3df4d41c06 to your computer and use it in GitHub Desktop.
Save shaneriley/7792b5ebbb3df4d41c06 to your computer and use it in GitHub Desktop.
UiHelper
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