Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tidy-html5 to validate the term-table page #15577

Closed
wants to merge 3 commits into from

Conversation

octopusinvitro
Copy link
Contributor

@octopusinvitro octopusinvitro commented Sep 26, 2016

What does this do?

HTML-validates the term-table page and in doing so addresses this comments

Why was this needed?

HTML was broken

Relevant Issue(s)

everypolitician/everypolitician#505

Implementation notes

None

Screenshots

None

Notes to Reviewer

Errors corrected:

  • An "img" element must have an "alt" attribute, except under certain
    conditions. For details, consult guidance on providing text alternatives
    for images. (All occurrences)

Notes to Merger

This branch has been rebased with master. An HTML helper is being introduced as part of #15584, a helper to which this PR would be adding new methods, so that PR should probably be merged first so that adding a new helper is not part of this PR, but just modifying it.

@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-15577 September 26, 2016 16:39 Inactive
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-15577 September 26, 2016 16:51 Inactive
@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-15577 September 26, 2016 16:59 Inactive
@octopusinvitro octopusinvitro changed the title Fix closing tag 3 Use tidy-html5 to validate the term-table page Sep 26, 2016
Copy link
Contributor

@tmtmtmtm tmtmtmtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still also quite hesitant of adding such a large fixture for this change. If you only need somewhere that has both a name with double quotes, and also both normal images and placeholders, the popolo for The Bahamas is one sixth of the size.

require 'test_helper'
require_relative '../../../app'

describe 'Phillipines' do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: "Philippines"

@@ -12,6 +12,7 @@
require 'everypolitician/popolo'

require_relative './lib/popolo_helper'
require_relative './helpers/html'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we be consistent where the helpers live? If we're making a new 'helpers' directory for them, then we should probably move the popolo_helper there too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that and I think it may be a good idea. I've seen that in other frameworks as Rails or Middleman and I think it helps to keep concerns separated. But I am happy to put this file under lib if we prefer it so.

end
end

helpers HTMLEscapeHelper
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the PopoloHelper we set it up in app.rb itself. I'm not sure whether it's generally preferred to do it that way or this, but again I think we should be consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See previous comment. I am happy to move it to app.rb though.


it 'doesnt break for names with double quotes' do
img = tiangco.css('img.person-card__image')
img.attr('alt').text.must_equal 'Member headshot for Tiangco, Tobias "Toby" M.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are actually two different images with this text, and only one of them is getting checked here. Both of them actually get returned from this css selector, though, so it should be quite easy to check both.


module Sinatra
module HTMLEscapeHelper
def h(text)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is h a general standard for naming functions like this? I'm generally a fan of brevity, but I'm a little hesitant here, unless this is a universally recognised approach.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this was copied from the official documentation, I can certainly rename it

@tmtmtmtm tmtmtmtm temporarily deployed to everypolitician-viewe-pr-15577 September 27, 2016 13:34 Inactive
@octopusinvitro
Copy link
Contributor Author

@tmtmtmtm Feedback addressed in fixup commits

  • I tried to call the HTML helper from the app but it couldn't make it work. So I just moved the helper from the helper folder to the lib folder. I also renamed the h method to escape_html.
  • I downloaded and used the popolo file from the Bahamas and removed the one for the Philippines.
  • I removed the test file for the Philippines and added a new one for the Bahamas. The switch to the Bahamas file allowed me to discover another bug, when one of the urls in the sources of the data contains spaces. I fixed that by adding another method to the HTMLEscapeHelper called escape_uri which uses URI.escape.

@@ -198,7 +198,7 @@
<div class="page-section page-section--grey source-credits">
<div class="container">
<% if @page.data_sources %>
<p>Main Source<% if @page.data_sources.size > 1 %>s<% end %>: <%= @page.data_sources.map { |url| %Q(<a href="#{url}">#{url}</a>) }.join(", ") %></p>
<p>Main Source<% if @page.data_sources.size > 1 %>s<% end %>: <%= @page.data_sources.map { |url| %Q(<a href="#{escape_uri(url)}">#{url}</a>) }.join(", ") %></p>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach concerns me. If the problem is that EP is giving us invalid URLs, then we should fix that upstream, so that everyone consuming the data doesn't need to do things like this.

Whichever approach we take, however, this feels like something that deserves a PR of its own, properly explaining the problem and solution etc., rather than cramming more into this PR.

@tmtmtmtm
Copy link
Contributor

@octopusinvitro when you say "it couldn't make it work", what was the problem?

The fixture is needed to HTML-validate the term-table page, in
particular, the contents of the alt attribute in images, for which
a person with a normal image, a person with a placeholder image
and a person with double quotes in their name are needed.
Errors corrected:
- An "img" element must have an "alt" attribute, except under certain
conditions. For details, consult guidance on providing text alternatives
for images. (All occurrences)
@octopusinvitro
Copy link
Contributor Author

@tmtmtmtm This branch has been rebased with master. An HTML helper is being introduced as part of #15584, a helper to which this PR would be adding new methods, so that PR should probably be merged first so that adding a new helper is not part of this PR, but just modifying it.

@octopusinvitro
Copy link
Contributor Author

Closed as it was moved to #15587

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants