Module: Faker::HTMLIpsum

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

Overview

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

Instance Method Summary collapse

Methods included from ModuleUtils

const_missing, k, underscore

Instance Method Details

#a(word_count = 2) ⇒ Object



10
11
12
# 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

#bodyObject



96
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
# 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) ⇒ Object



25
26
27
28
29
30
31
# 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) ⇒ Object



124
125
126
127
128
129
130
131
132
133
# 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) ⇒ Object



57
58
59
60
61
62
63
# 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) ⇒ Object



49
50
51
52
53
54
55
# 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 = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# 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) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# 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


65
66
67
68
69
70
71
# 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) ⇒ Object



41
42
43
44
45
46
47
# 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) ⇒ Object



33
34
35
36
37
38
39
# 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