The RSpec matcher tests if two HTML fragments are equivalent. Equivalency means: Whitespace is ignored Types of attribute quotes are irrelevant Attribute order is irrelevant Comments are ignored
html = ... expect(html).to match_html(<<~HTML) Expected content HTML You may override options from CompareXML by passing keyword arguments after the HTML string: html = ...
Browsers differ in which HTML, CSS and JavaScript features they support. This lesson covers how to find out what you can use, which browsers we support, and how transpilation, polyfills...
...degrade gracefully when a feature may be missing — detect it and fall back — in HTML, CSS and JavaScript. You can test an app in browsers and devices you don't...
There are two distinct ways of commenting Haml markup: HTML and Ruby. HTML comments This will create an HTML comment that will be sent to the client (aka browser):
...to 'Example', 'www.example.com' This produces the following HTML: Only use this variant if you need the comment to appear in the HTML. Ruby comments This will comment code so it...
end end end World(HtmlSelectorsHelpers) nth-of-type matches by counting the actual HTML-tag Using :nth-of-type like this, might not work as you expect, as...
...it only cares about the HTML-Tag type. Example. This might lead to breaking tests when your html changes. Once browser support is fulfilled prefiltering nth-child selector will be...
...user actually sees) puts page.text Prints just the visible text body, completely stripped of HTML tags and hidden elements. Raw HTML puts page.body Prints the full HTML so you can...
...inspect CSS classes, attributes, or missing elements. If HTML output is cluttered with excessive blank lines, you can easily avoid printing them: puts page.body.gsub(/^\s*$/, '').squeeze("\n") Advanced DOM parsing...
...cannot be achieved with the [inert] attribute. See also Preventing interactivity on elements using HTML or CSS Non-interactive Elements with the inert attribute
...HTML elements can automatically start playing when the autoplay attribute is set on them. Except for when they can not, e.g. on pageload, or when the element enters the DOM...
To return non-HTML responses (like XLS spreadsheets), we usually use the respond_to do |format| format.xls do # send spreadsheet end end This is often, but not always the same...
Today I learned that you can animate HTML elements using the Web Animation API's method .animate(keyframes, options) (which seems to be Baseline for all browsers since 2022).
...can install wkhtmltopdf on your appserver if you need to generate PDF files from HTML. However, please note that wkhtmltopdf is no longer actively maintained, which comes with certain limitations...
Nokogiri is great. It will even fix invalid HTML for you, like a browser would (e.g. move block elements out of parents which are specified to not allow them).
...HTML.fragment(" foo bar ").to_s => " foo bar " While this is mostly useful, browsers are actually fine with a bit of badly formatted HTML. And you don't want to be...
When your Cucumber feature needs to browse the page HTML, and you are not sure how to express your query as a clever CSS or XPath expression, there is another...
You cannot use Array#join on an array of strings where some strings are html_safe and others are not. The result will be an unsafe string and will thus...
...be escaped when rendered in a view: unsafe_string = ' foo ' safe_string = ' bar '.html_safe [unsafe_string, safe_string].join(' ') # will incorrectly render as '<span>foo</span...
...plain form helpers are the better choice. You can configure Simple Form's generated HTML to match a project's markup, e.g. with its Bootstrap wrapper configuration.
...use Simple Form. Expect some pain to initially configure Simple Form to use the HTML structure of your MovieDB. After that your forms should be much shorter than before.
Web forms can be made much more usable with a few HTML attributes. Short summary: type: Tells browsers about the input data type. Mobile browsers will select a virtual keyboard...
...a subject block. You can also use describe to specify which parts of your html you are currently interested in naming it with it's actual selector. The context can...
Code snippet tested with Rails 2.3 def index # ... if request.xhr? html = render_to_string(:partial => "list", :layout => false) respond_to do |format| format.html { render :text => html } format.json { render :json => {:html...
...html,...
end end end Note: Perhaps you ran into ActionView::MissingTemplate error and this card might help. If you call render_to_string within the format.json block, Rails will only...
Make sure that you use the correct property when editing an HTML attribute. Using innerHTML with unsafe arguments...
...makes your application vulnerable to XSS. textContent: Sets the content of a Node (arguments are HTML-safe escaped) innerHTML: Sets the HTML of an Element (arguments are not escaped and...
While both the alt attribute and the figcaption element provide a way to describe images, the way we write for...
...chapters explain different approaches in Rails, how you can assign such an association via HTML forms. In most cases you want to use Option 4 with assignable values.
...chapters explain different approaches in Rails, how you can assign such an association via HTML forms. Option 1: Array column One way to solve the problem is using a database...
Besides their default styling properties, HTML elements have a semantic meaning. For example, an h1 tag is usually styled with a larger font and bold, while it denotes "the single...
...most important headline in its context". While CSS enables us to style almost any HTML element like anything that is needed, choosing HTML elements corresponding to the meaning of their...
...files, it can be a security issue. Example: A user uploads a file with HTML/JavaScript content using no file extension. In the Apache default configuration if you access the file...
...it will have no Content-Type. Some browsers will guess/autodetect it as HTML and now you are vulnerable to XSS. To prevent this, you can set a default Content-Type...
...reconfiguring your Rails app so two requests to the same resource produce the same HTML for a given user...
...you need; see attributes and whitespace removal 📄 Haml tutorial — ten minutes to the basics 🎮 html2haml — converts HTML or ERB to Haml; useful to check your own conversions, not to skip...
Convert the rest yourself, and check every page still renders the same HTML. Hint The Haml-tutorial doesn't show how to execute ruby-code that isn't...