module Faker::HTMLIpsum
Loosely based on html-ipsum.com/ Requires Faker::Lorem
module
Public Instance Methods
a(word_count = 2)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 10 def a(word_count = 2) "<a href=\"##{word}\" title=\"#{words(word_count).capitalize!}\">#{words(word_count).capitalize!}</a>" end
body()
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 96 def body s = "<h1>#{words(2).capitalize!}</h1>" rand(4).times do s << "<p>#{fancy_string}</p>" end s << table(rand(4)) s << "<h2>#{words(2).capitalize!}</h2> <ol>" rand(4).times do s << "<li>#{paragraph 1}</li>" end s << "</ol> <blockquote><p>#{paragraphs 3}</p></blockquote> <h3>#{words(2).capitalize!}</h3> <ul>" rand(4).times do s << "<li>#{paragraph 1}</li>" end s << "</ul> <pre><code> ##{word} h1 a { display: block; width: 300px; height: 80px; } </code></pre>" end
dl(definitions = 2)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 25 def dl(definitions = 2) s = "<dl>" definitions.times do s << "<dt>#{words(1).capitalize!}</dt><dd>#{paragraph 2}</dd>" end s << "</dl>" end
fancy_string(count = 3, include_breaks = false)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 124 def fancy_string(count = 3, include_breaks = false) sep = include_breaks ? "<br>" : " " a = k([ "<strong>#{words(2).capitalize!}</strong>.", "<em>#{paragraph}</em>", "<code>#{words 2}</code>", "#{a 2}" ] + Faker::Lorem::paragraphs(count)) a.random_pick(count).join(sep) end
ol_long(items = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 57 def ol_long(items = 3) s = "<ol>" items.times do s << "<li>#{paragraph 2}</li>" end s << "</ol>" end
ol_short(items = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 49 def ol_short(items = 3) s = "<ol>" items.times do s << "<li>#{sentence 2}</li>" end s << "</ol>" end
p(count = 3, options = {})
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 14 def p(count = 3, options = {}) options = {:fancy => false, :include_breaks => false}.merge(options) if options[:fancy] s = fancy_string(count, options[:include_breaks]) else mode = options[:include_breaks] ? "paragraphs" : "paragraph" s = send(mode.to_sym, count) end "<p>#{s}</p>" end
table(rows = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 73 def table(rows = 3) s = "<table> <thead> <tr> <th>#{word.capitalize!}</th> <th>#{word.capitalize!}</th> <th>#{word.capitalize!}</th> <th>#{word.capitalize!}</th> </tr> </thead> <tbody>" rows.times do s << "<tr> <td>#{words(1).capitalize!}</td> <td>#{words(1).capitalize!}</td> <td>#{words(1).capitalize!}</td> <td>#{a}</td> </tr>" end s << "</tbody> </table>" end
ul_links(items = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 65 def ul_links(items = 3) s = "<ul>" items.times do s << "<li>#{a 1}</li>" end s << "</ul>" end
ul_long(items = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 41 def ul_long(items = 3) s = "<ul>" items.times do s << "<li>#{paragraph 2}</li>" end s << "</ul>" end
ul_short(items = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 33 def ul_short(items = 3) s = "<ul>" items.times do s << "<li>#{sentence 2}</li>" end s << "</ul>" end
Private Instance Methods
paragraph(sentence_count = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 152 def paragraph(sentence_count = 3) Faker::Lorem::paragraph(sentence_count) end
paragraphs(paragraph_count = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 156 def paragraphs(paragraph_count = 3) Faker::Lorem::paragraphs(paragraph_count).join('<br>') end
sentence(word_count = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 144 def sentence(word_count = 3) Faker::Lorem::sentence(word_count) end
sentences(sentence_count = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 148 def sentences(sentence_count = 3) Faker::Lorem::sentences(sentence_count).join(' ') end
word()
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 136 def word Faker::Lorem::word end
words(word_count = 3)
click to toggle source
# File lib/ffakerer/html_ipsum.rb, line 140 def words(word_count = 3) Faker::Lorem::words(word_count).join(' ') end