class Faker::HTML

def available_methods

def available_methods
  (HTML.public_methods(false) - Base.methods).sort
end

def code

Returns:
  • (String) -
def code
  "<code>#{Lorem.sentence(word_count: 1)}</code>"
end

def element(tag: 'div', content: Lorem.sentence(word_count: 3), attributes: { class: Lorem.word, onclick: "#{Lorem.word}()" })

Returns:
  • (String) -

Parameters:
  • attributes (Hash) -- The attributes to include in the tag.
  • content (String) -- The Content of the HTML tag.
  • tag (String) -- The HTML tag to generate.
def element(tag: 'div', content: Lorem.sentence(word_count: 3), attributes: { class: Lorem.word, onclick: "#{Lorem.word}()" })
  attribute_string = attributes.map { |key, value| "#{key}=\"#{value}\"" }.join(' ')
  "<#{tag} #{attribute_string}>#{content}</#{tag}>"
end

def emphasis

Returns:
  • (String) -
def emphasis
  "<em>#{Faker::Lorem.paragraph(sentence_count: 1)}</em>"
end

def generate_table_row(tag, cell_count)

def generate_table_row(tag, cell_count)
  row = "<tr>\n"
  cell_count.times do
    row += "<#{tag == 'th' ? 'th' : 'td'}>#{Lorem.word}</#{tag == 'th' ? 'th' : 'td'}>\n"
  end
  row += "</tr>\n"
  row
end

def heading

Returns:
  • (String) -
def heading
  level = rand(1..6)
  "<h#{level}>#{Lorem.word.capitalize}</h#{level}>"
end

def link(rel: 'stylesheet')

Returns:
  • (String) -

Parameters:
  • rel (String) -- The rel of the link tag.
def link(rel: 'stylesheet')
  "<link rel=\"#{rel}\" href=\"#{Faker::Internet.url}.css\">"
end

def ordered_list

Returns:
  • (String) -
def ordered_list
  number = rand(1..10)
  items = []
  number.times do
    items << "<li>#{Faker::Lorem.sentence(word_count: 1)}</li>"
  end
  "<ol>\n#{items.join("\n")}\n</ol>"
end

def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0, exclude_words: nil)

Returns:
  • (String) -

Parameters:
  • exclude_words (Array) -- Words to exclude from the generated paragraph.
  • random_sentences_to_add (Integer) -- The number of random sentences to add to the paragraph.
  • supplemental (Boolean) -- Include supplemental text.
  • sentence_count (Integer) -- The number of sentences in the paragraph.
def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0, exclude_words: nil)
  "<p>#{Faker::Lorem.paragraph(sentence_count: sentence_count, supplemental: supplemental, random_sentences_to_add: random_sentences_to_add, exclude_words: exclude_words)}</p>"
end

def random(exclude: [])

Returns:
  • (String) -

Parameters:
  • methods (Symbol) -- Specify which methods to exclude.

Overloads:
  • random(methods)
def random(exclude: [])
  method_list = available_methods
  exclude.each { |ex| method_list.delete_if { |meth| meth == ex.to_sym } }
  send(method_list[Faker::Config.random.rand(0..method_list.length - 1)])
end

def sandwich(sentences: 3, repeat: 1)

Returns:
  • (String) -

Parameters:
  • repeat (Integer) -- The number of times to repeat the pattern (header, paragraph, random).
  • sentences (Integer) -- The number of sentences in each paragraph.
def sandwich(sentences: 3, repeat: 1)
  text_block = []
  text_block << heading
  repeat.times do
    text_block << paragraph(sentence_count: sentences)
    text_block << random(exclude: %i[script link])
  end
  text_block.join("\n")
end

def script

Returns:
  • (String) -
def script
  "<script src=\"#{Faker::Internet.url}.js\"></script>"
end

def table

Returns:
  • (String) -
def table
  header_row = generate_table_row('th', 3)
  footer_row = generate_table_row('td', 3)
  body_rows = []
  3.times do
    row = generate_table_row('td', 3)
    body_rows << row
  end
  thead = "<thead>\n#{header_row}</thead>"
  tbody = "<tbody>\n#{body_rows.join("\n")}</tbody>"
  tfoot = "<tfoot>\n#{footer_row}</tfoot>"
  "<table>\n#{thead}\n#{tbody}\n#{tfoot}\n</table>"
end

def unordered_list

Returns:
  • (String) -
def unordered_list
  number = rand(1..10)
  items = []
  number.times do
    items << "<li>#{Faker::Lorem.sentence(word_count: 1)}</li>"
  end
  "<ul>\n#{items.join("\n")}\n</ul>"
end