Method: Faker::HTML.element
- Defined in:
- lib/faker/default/html.rb
.element(tag: 'div', content: Lorem.sentence(word_count: 3), attributes: { class: Lorem.word, onclick: "#{Lorem.word}()" }) ⇒ String
Generates HTML content with customizable attributes for any HTML tag.
168 169 170 171 |
# File 'lib/faker/default/html.rb', line 168 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 |