Module: FFaker::HTMLIpsum

Extended by:
HTMLIpsum, ModuleUtils
Included in:
HTMLIpsum
Defined in:
lib/ffaker/html_ipsum.rb

Overview

Loosely based on html-ipsum.com/ Requires FFaker::Lorem module

Instance Method Summary collapse

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

#bodyObject



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 = (:h1, words(2).capitalize)
  rand(0..3).times do
    body << (:p, fancy_string)
  end
  body << table(rand(0..3))
  body << (:h2, words(2).capitalize)
  body << (:ol) do |ol|
    rand(0..3).times do
      ol << (:li, paragraph(1))
    end
  end
  body << (:blockquote) do |bq|
    bq << (:p, paragraphs(3))
  end
  body << (:h3, words(2).capitalize!)
  body << (:ul) do |ul|
    rand(0..3).times do
      ul << (:li, paragraph(1))
    end
  end
  body << (:pre) do |pre|
    pre << (: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)
   :dl do |dl|
    definitions.times do
      dl << (:dt, words(1).capitalize!)
      dl << (: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([
    (:strong, words(2).capitalize!),
    (:em, paragraph),
    (:mark, paragraph),
    (:del, words(2)),
    (:ins, words(2)),
    (:sub, words(2)),
    (:sup, words(2)),
    (:code, words(2)),
    (: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)
   :ol do |ol|
    items.times do
      ol << (: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)
   :ol do |ol|
    items.times do
      ol << (: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, 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)
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)
  (:table) do |table|
    table << (:thead) do |thead|
      thead << (:tr) do |tr|
        tr << (:th, word.capitalize)
        tr << (:th, word.capitalize)
        tr << (:th, word.capitalize)
        tr << (:th, word.capitalize)
      end
    end
    table << (:tbody) do |tbody|
      rows.times do
        tbody << (:tr) do |tr|
          tr << (:td, words(1).capitalize)
          tr << (:td, words(1).capitalize)
          tr << (:td, words(1).capitalize)
          tr << (:td, a)
        end
      end
    end
  end
end


66
67
68
69
70
71
72
# File 'lib/ffaker/html_ipsum.rb', line 66

def ul_links(items = 3)
   :ul do |ul|
    items.times do
      ul << (: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)
   :ul do |ul|
    items.times do
      ul << (: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)
   :ul do |ul|
    items.times do
      ul << (:li, sentence(2))
    end
  end
end