Module: FFaker::HTMLIpsum
Overview
Loosely based on html-ipsum.com/ Requires FFaker::Lorem module
Instance Method Summary collapse
- #a(word_count = 2) ⇒ Object
- #body ⇒ Object
- #dl(definitions = 2) ⇒ Object
- #fancy_string(count = 3, include_breaks = false) ⇒ Object
- #ol_long(items = 3) ⇒ Object
- #ol_short(items = 3) ⇒ Object
- #p(count = 3, options = {}) ⇒ Object
- #table(rows = 3) ⇒ Object
- #ul_links(items = 3) ⇒ Object
- #ul_long(items = 3) ⇒ Object
- #ul_short(items = 3) ⇒ Object
Methods included from ModuleUtils
const_missing, k, luhn_check, underscore, unique
Methods included from RandomUtils
#fetch_sample, #rand, #shuffle
Instance Method Details
#a(word_count = 2) ⇒ Object
10 11 12 |
# File 'lib/ffaker/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 ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/ffaker/html_ipsum.rb', line 97 def body body = content_tag_for(:h1, words(2).capitalize) rand(0..3).times do body << content_tag_for(:p, fancy_string) end body << table(rand(0..3)) body << content_tag_for(:h2, words(2).capitalize) body << content_tag_for(:ol) do |ol| rand(0..3).times do ol << content_tag_for(:li, paragraph(1)) end end body << content_tag_for(:blockquote) do |bq| bq << content_tag_for(:p, paragraphs(3)) end body << content_tag_for(:h3, words(2).capitalize!) body << content_tag_for(:ul) do |ul| rand(0..3).times do ul << content_tag_for(:li, paragraph(1)) end end body << content_tag_for(:pre) do |pre| pre << content_tag_for(:code) do |code| code << " ##{word} h1 a { display: block; width: 300px; height: 80px; } " end end body end |
#dl(definitions = 2) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ffaker/html_ipsum.rb', line 25 def dl(definitions = 2) content_tag_for :dl do |dl| definitions.times do dl << content_tag_for(:dt, words(1).capitalize!) dl << content_tag_for(:dd, paragraph(2)) end end end |
#fancy_string(count = 3, include_breaks = false) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/ffaker/html_ipsum.rb', line 132 def fancy_string(count = 3, include_breaks = false) sep = include_breaks ? '<br>' : ' ' a = k([ content_tag_for(:strong, words(2).capitalize!), content_tag_for(:em, paragraph), content_tag_for(:mark, paragraph), content_tag_for(:del, words(2)), content_tag_for(:ins, words(2)), content_tag_for(:sub, words(2)), content_tag_for(:sup, words(2)), content_tag_for(:code, words(2)), content_tag_for(:small, words(2)), (a 2).to_s ] + FFaker::Lorem.paragraphs(count - 1)) fetch_sample(a, count: count).join(sep) end |
#ol_long(items = 3) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/ffaker/html_ipsum.rb', line 58 def ol_long(items = 3) content_tag_for :ol do |ol| items.times do ol << content_tag_for(:li, paragraph(2)) end end end |
#ol_short(items = 3) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/ffaker/html_ipsum.rb', line 50 def ol_short(items = 3) content_tag_for :ol do |ol| items.times do ol << content_tag_for(:li, sentence(2)) end end end |
#p(count = 3, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ffaker/html_ipsum.rb', line 14 def p(count = 3, = {}) = { fancy: false, include_breaks: false }.merge() if [:fancy] s = fancy_string(count, [:include_breaks]) else mode = [:include_breaks] ? 'paragraphs' : 'paragraph' s = send(mode.to_sym, count) end content_tag_for(:p, s) end |
#table(rows = 3) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/ffaker/html_ipsum.rb', line 74 def table(rows = 3) content_tag_for(:table) do |table| table << content_tag_for(:thead) do |thead| thead << content_tag_for(:tr) do |tr| tr << content_tag_for(:th, word.capitalize) tr << content_tag_for(:th, word.capitalize) tr << content_tag_for(:th, word.capitalize) tr << content_tag_for(:th, word.capitalize) end end table << content_tag_for(:tbody) do |tbody| rows.times do tbody << content_tag_for(:tr) do |tr| tr << content_tag_for(:td, words(1).capitalize) tr << content_tag_for(:td, words(1).capitalize) tr << content_tag_for(:td, words(1).capitalize) tr << content_tag_for(:td, a) end end end end end |
#ul_links(items = 3) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/ffaker/html_ipsum.rb', line 66 def ul_links(items = 3) content_tag_for :ul do |ul| items.times do ul << content_tag_for(:li, a(1)) end end end |
#ul_long(items = 3) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/ffaker/html_ipsum.rb', line 42 def ul_long(items = 3) content_tag_for :ul do |ul| items.times do ul << content_tag_for(:li, paragraph(2)) end end end |
#ul_short(items = 3) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/ffaker/html_ipsum.rb', line 34 def ul_short(items = 3) content_tag_for :ul do |ul| items.times do ul << content_tag_for(:li, sentence(2)) end end end |