diff --git a/doc/default/html.md b/doc/default/html.md new file mode 100644 index 0000000000..ea1d631080 --- /dev/null +++ b/doc/default/html.md @@ -0,0 +1,47 @@ +# Faker::HTML + +Available since version 3.2.1. + +The `Faker::HTML` module provides methods for generating random HTML content. + +```ruby +# heading - Produces a random HTML heading format. +Faker::HTML.heading #=> "
Incidunt atque quis
" + +# emphasis - Produces a random emphasis formatting on a random sentence. +Faker::HTML.emphasis #=> "repellat id impedit. + +# ordered_list - Produces a random ordered list of items between 1 and 10 in HTML format. +Faker::HTML.ordered_list #=> "\nEos quasi qui.
\n
"
+
+# table - Produces a random HTML table with 3 rows and 3 columns.
+Faker::HTML.table #=> "ad | \nsimilique | \nvoluptatem | \n\n\ncorrupti | \nest | \nrerum | \nmolestiae | \nquidem | \net | \nin | \ntempora | \nat | \n<\tbody>\n\nvoluptatem | \ndebitis | \nrem | \n\n
---|
Incidunt atque quis
" + # + # @faker.version 3.2.1 + def paragraph(sentence_count: 3, supplemental: false, random_sentences_to_add: 0, exclude_words: nil) + "#{Faker::Lorem.paragraph(sentence_count: sentence_count, supplemental: supplemental, random_sentences_to_add: random_sentences_to_add, exclude_words: exclude_words)}
" + end + + ## + # Produces a random emphasis formatting on a random word in two HTML paragraphs. + # + # @return [String] + # + # @example + # Faker::HTML.emphasis #=> "repellat id impedit" + # + # @faker.version 3.2.1 + def emphasis + "#{Faker::Lorem.paragraph(sentence_count: 1)}" + end + + ## + # Produces a random ordered list in HTML format, with at least one element. + # + # @return [String] + # + # @example + # Faker::HTML.ordered_list #=> "Eos quasi qui.
"
+ #
+ # @faker.version 3.2.1
+ def code
+ "#{Lorem.sentence(word_count: 1)}
"
+ end
+
+ ##
+ # Produces a random HTML table.
+ #
+ # @return [String]
+ #
+ # @example
+ # Faker::HTML.table #=> "ad | \nsimilique | \nvoluptatem | \n\n\ncorrupti | \nest | \nrerum | \nmolestiae | \nquidem | \net | \nin | \ntempora | \nat | \n<\tbody>\n\nvoluptatem | \ndebitis | \nrem | \n\n
---|
.+<\/p>/, @tester.paragraph)
+ end
+
+ def test_emphasis
+ assert_match(/.*<\/em>/, @tester.emphasis)
+ end
+
+ def test_ordered_list
+ assert_match(/.*<\/ol>/m, @tester.ordered_list)
+ end
+
+ def test_unordered_list
+ assert_match(/
.*<\/ul>/m, @tester.unordered_list)
+ end
+
+ def test_code
+ assert_match(/
.+<\/code>/, @tester.code)
+ end
+
+ def test_table
+ table_html = @tester.table
+
+ assert(table_html.start_with?('
'))
+ assert(table_html.end_with?('
'))
+
+ assert_equal(1, count_occurrences(table_html, ''))
+ assert_equal(1, count_occurrences(table_html, ''))
+ assert_equal(1, count_occurrences(table_html, ''))
+ assert_equal(3, count_occurrences(table_html, ''))
+ assert_equal(5, count_occurrences(table_html, ' '))
+ assert_equal(12, count_occurrences(table_html, ' '))
+ end
+
+ def test_script
+ assert_match(/