Phil
Phil is a lightweight content generation module that wraps around Ffaker. You can create large amounts of markup for layout testing with a few simple methods.
A big theme of Phil is that any parameter that can accept a number also accepts a range. This allows for far more utility than vanilla Ffaker when it comes to testing different permutations of content.
Iteration
Get a random integer from an array or range:
Phil.pick 1..3
Phil.pick [1, 2, 3]
Phil.pick ["Foo", "Bar", "Baz"]
Loop a random number of times:
Phil.loop 1..100 do |i|
"This will be output between 1 and 100 times and is index #{i}"
end
Have a 1 in N chance of doing something (N defaults to 3):
Phil.sometimes "foo"
Phil.sometimes "foo", 100
Phil.sometimes do
"foo"
Phil.sometimes 100 do
"foo"
Content Generation
Body content
Generate a ton of body content with one method. This defaults to
"h1 p p h2 p ol h2 p ul"
, but you can pass it a string of whatever content tags you like,
including blockquote
, other headings, and so on. Blockquotes will contain multiple <p>
elements, paragraphs will contain a few sentences, and any other tags will contain 3-15 words.
Phil.markup
Phil.markup "h1 p h2 ul p blockquote h5 h6"
Images
Generate a placehold.it image URL. Requires dimensions, but you can also request colors (in the format #background/#foreground
) and containing text. Placehold.it doesn't play nice with some containing text characters so those are stripped out.
You can pass parameters in any order if you like – Phil is reasonably smart about figuring them out – or name them if you're feeling verbose.
Phil.image 200
Phil.image '200x400', '#ff0000'
Phil.image '200x400', '#ff0000/#00ff00'
Phil.image 'Jackie Jormp-Jomp?', 600
Phil.image(text: 'Pants', width: 300, height: (300..500), background: '#ff0000', foreground: '#0000ff')
Lorem methods (all take ranges or numbers)
Phil.words 5
Phil.words 5..50
Phil.paragraphs 5
Phil.paragraphs 5..50
Phil.blockquote
Phil.blockquote 1..5
Phil.ul
Phil.ul 1..5, 10
Phil.ol
Phil.ol 1..5, 10
Phil.link_list
Phil.link_list 1..5, 10
Assorted other content generation methods
Phil.date
Phil.date 7
Phil.date 7-14
Phil.currency 10..100
Phil.currency 10..100, "£"
Phil.phone
Phil.phone "###-#### x###"
Phil.number 5
Phil.number 5..10
Aliased Ffaker methods for convenience
Phil.address
Phil.city
Phil.state_abbr
Phil.domain_name
Phil.email
Phil.name
Phil.first_name
Phil.last_name
Phil.company_name