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

FINAL: Glossary generation in rules & reverse linking in algorithms #147

Merged
merged 7 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defaults:
path: ""
type: rules
values:
name: undefined
layout: rule
- scope:
path: ""
Expand All @@ -41,7 +42,6 @@ defaults:
layout: rule
draft: true
name: undefined
rule_id: undefined
test_mode: undefined
- scope:
path: ""
Expand All @@ -55,10 +55,14 @@ defaults:
layout: testcase
draft: true
- scope:
path: pages/algorithms
path: "pages/algorithms"
type: pages
values:
layout: algorithm
category: algorithms

exclude:
- _draft-testcase-embeds
- _drafts/early-stage
- _draft-testcase-embeds
- _drafts/outdated
- _rules/outdated
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions _layouts/algorithm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
layout: default
---

{{ content }}

<!--INSERT-GLOSSARY-USAGE-HERE-->
14 changes: 4 additions & 10 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,14 @@
<head>
<meta charset="utf-8">
{% if page.layout == 'rule' %}

{% if page.rule_id != 'undefined' %}
{% assign page_title = page.rule_id | prepend: "Rule: " %}
{% else %}
{% assign page_title = page.name | prepend: "Rule: " %}
{% endif %}

{% assign page_title = page.name | prepend: "Rule: " %}
{% else %}
{% if page.layout == 'testcase' %}

{% if page.rule_id != 'undefined' %}
{% assign page_title = page.rule_id | prepend: "Test Cases for " %}
{% else %}
{% assign page_title = page.name | prepend: "Test Cases for " %}
{% endif %}

{% else %}
{% assign page_title = page.title %}
{% endif %}
Expand Down Expand Up @@ -174,9 +166,11 @@ <h1>{{ page_title }}</h1>
{{ content }}
</p>
</main>



<script src="{{ site.baseurl }}/assets/js/jquery.min.js"></script>
<script src="{{ site.baseurl }}/assets/js/bootstrap.min.js"></script>

</body>
</html>
</html>
2 changes: 2 additions & 0 deletions _layouts/rule.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ <h2 id="requirements">Accessibility Requirements</h2>

{{ content }}

<!--INSERT-GLOSSARY-HERE-->

{% if page.test_aspects %}
<h2 id="test-aspects">Test Aspects</h2>
Test aspects are defined as part of the <a href="https://w3c.github.io/wcag-act/act-rules-format.html#input-aspects-common">ACT Rules format 1.0</a>.
Expand Down
19 changes: 13 additions & 6 deletions _plugins/frame_embed_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ class FrameEmbedGenerator < Generator
'ODD_TAG_COUNT' => 'Expects even pairs of' + KEY_MATCH_CODE_TAG_BACKTICK + ' and ' + KEY_MATCH_CODE_TAG_BACKTICK + '. Odd number of tags identified in page '
}

def initialize(p)
def initialize(config)
@markdown = Converters::Markdown.new
super(p)
super(config)
end

def generate(site)
# Hooks
Hooks.register :site, :post_write do |site|
FileUtils.copy_entry KEY_EMBEDS_DIR, site.dest + '/' + KEY_EMBEDS_DIR
end

# Clean directory
base_dir = site.source + '/' + KEY_EMBEDS_DIR
FileUtils.rm_f Dir.glob("#{base_dir}/*")

# Create empty directory
Dir.mkdir(base_dir) unless File.exists?(base_dir)
# Loop documents and create test case embeds
Expand All @@ -37,6 +35,12 @@ def generate(site)
create_frame_embed_content(doc, site)
end
end

# Hook after post_write and then copy across generated frame embed documents
Hooks.register :site, :post_write do |site|
FileUtils.copy_entry KEY_EMBEDS_DIR, site.dest + '/' + KEY_EMBEDS_DIR
end

end

def get_code_tag_line_indices(document)
Expand Down Expand Up @@ -87,6 +91,7 @@ def create_frame_embed_content(document, site)
doc_content = get_md_content(document.content, spread_indices, hash)
document.content = doc_content
end

def get_highlight_lang(opening_tag)
lang = 'html'
language_tag = opening_tag.gsub(KEY_MATCH_CODE_TAG_BACKTICK, '')
Expand Down Expand Up @@ -140,6 +145,8 @@ def make_frame_src_file(
f.write(file_content)
end
end

private

def fail(msg)
Jekyll.logger.error 'Fatal (Frame Embed):', msg
Expand Down
136 changes: 136 additions & 0 deletions _plugins/glossary_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
module Jekyll
module GlossaryEmbed

class GlossaryGenerator < Generator

safe true
priority :highest

# Steps
# read list of all algorithm keys -> make an object/ hash
# parse each draft/ rule and find usage of algorithm keys -> make an object/ hash
# overwrite respective md files with definitions yml & list of key terms at the bottom

def initialize(config)
super(config)
end

def generate(site)
hash = Hash.new
Hooks.register :pages, :pre_render do |page|
if (page.url['/algorithms'])
page_meta = page.data
page_key = (page_meta['key'] && page_meta['key'].length > 0) ? page_meta["key"] : nil
if(page_key)
hash[page_key] = {
'url' => page.url,
'title' => page_meta['title'],
'key' => page_meta['key']
}
end
end
end
Hooks.register :site, :post_write do |site|
update_rules_drafts_with_glossary(site, hash)
update_algorithm_with_usages(site, hash)
end
end



def update_rules_drafts_with_glossary(site, glossary_hash)
site.documents.each do |doc|
if (doc.url['/drafts'] || doc.url['/rules'])
glossary_data = get_glossary_for_document(site, doc, glossary_hash)
append_glossary(site.dest + doc.url, glossary_data)
end
end
end

def update_algorithm_with_usages(site, glossary_hash)
h = Hash.new
glossary_hash.each do |k, v|
site.documents.each do |doc|
if (doc.url['/drafts'] || doc.url['/rules'])
term_exists_in_docs = glossary_term_exists(site, doc, k)
if(term_exists_in_docs.length > 0)
h[k] = h[k] != nil ? h[k] << term_exists_in_docs[0] : term_exists_in_docs
end
end
end
end
site.pages.each do |page|
if (page.url['/algorithms'])
append_to_glossary_usage_in_rule(site.dest + page.url, h[page.data['key']])
end
end
end

private

def glossary_term_exists(s, d, term)
out = []
d.content.each_line.with_index do |line, index|
if(line['#' + term])
anchor_url = s.baseurl + d.url
anchor = "<a class='glossary-usage-link' href='#{anchor_url}'>#{ d.data['name'] + ' (' + d.data['slug'] + ')' }</a>"
out.push(anchor)
end
end
out
end

def append_to_glossary_usage_in_rule(url, data)
if(data)
text = File.read(url)
to_append_data = "<div class='glossary-usages'>"\
"<h3 class='title'>Usages:</h3>"\
"#{data.join}"\
'</div></div>'
new_contents = text.gsub(/<!--INSERT-GLOSSARY-USAGE-HERE-->/, to_append_data)
File.open(url, "w") {|file| file.puts new_contents }
end
end

def append_glossary(url, data)
text = File.read(url)
new_contents = text.gsub(/<!--INSERT-GLOSSARY-HERE-->/, data)
File.open(url, "w") {|file| file.puts new_contents }
end

def get_glossary_for_document(s, d, gh)
out = ""
d.content.each_line.with_index do |line, index|
gh.each do |k, v|
if(line['#' + k])
g_out = "<div class='glossary-item'>"\
"<a id='#{v["key"]}' href='#{s.baseurl}#{v['url']}'><h3>#{ v['title']}</h3></a>"\
"#{ get_page_content(s, v['url']) }"\
'</div></div>'
out = out << g_out
end
end
end
out.length > 0 ? "<h2>Definitions</h2><div class='glossary-list'>#{out}</div>" : ""
end

def get_page_content(s, url)
content = nil
s.pages.each do |p|
if(p.url == url)
content = p.content
break
end
end
content
end

def fail(msg)
Jekyll.logger.error 'Fatal (Frame Embed):', msg
raise LoadError, msg
end

end

end
end
4 changes: 2 additions & 2 deletions _rules/SC2-4-2-page-has-title.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The page contains at least one `title` element.

### Expectation 2

The first `title` element contains [non-empty text][].
The first `title` element contains [non-empty text](#non-empty).

## Assumptions

Expand Down Expand Up @@ -138,4 +138,4 @@ _There are no major accessibility support issues known for this rule._
</svg>
```

[non-empty text]: ../pages/algorithms/non-empty.html

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 5 additions & 1 deletion assets/css/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
html {
position: relative;
min-height: 100%;
overflow-x: hidden; /* Prevent scroll on narrow devices */
}


$brush-accent: #003349;
$brush-white: #fff;
$brush-black: #000;
Expand Down Expand Up @@ -98,6 +98,10 @@ body {
margin: 20px 0;
}

.glossary-usage-link{
display: block;
}

.embed-wrapper {
display: flex;
width: 100%;
Expand Down
1 change: 1 addition & 0 deletions pages/algorithms/accessible-name.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Accessible Name
key: accessible-name
---

The accessible name is the name of a user interface element. Each platform accessibility API provides the accessible name property.
Expand Down
1 change: 1 addition & 0 deletions pages/algorithms/content.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Content (element type)
key: content
---

1. A node in the DOM tree is considered `content` when it is a text node that does not consist of exclusively whitespace characters and that is not a descendant of a `head`, `script` or `style` element.
Expand Down
1 change: 1 addition & 0 deletions pages/algorithms/decorative.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Decorative
key: decorative
---

Serving only an aesthetic purpose, providing no information, and having no functionality.
1 change: 1 addition & 0 deletions pages/algorithms/exposed-to-assistive-technologies.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Exposed to assistive technologies
key: exposed-to-assistive-technologies
---

Elements should be contained in the accessibility tree as described in [Core Accessibility API Mappings 1.1](https://www.w3.org/TR/core-aam-1.1/#mapping_general)
8 changes: 4 additions & 4 deletions pages/algorithms/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Algorithms
---

{% for algorithms in site.pages %}

{% if algorithms.category == "algorithms"%}- [{{ algorithms.title }}]({{ algorithms.url | prepend: site.baseurl }})

{% endif %}{% endfor %}
{% if algorithms.category == "algorithms"%}
- [{{ algorithms.title }}]({{ algorithms.url | prepend: site.baseurl }})
{% endif %}
{% endfor %}
1 change: 1 addition & 0 deletions pages/algorithms/interactive-element.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Interactive element
key: interactive-element
---

1. An element is interactive if tabindex is not turned off on a standard interactive HMTL element. These will match the following selector:
Expand Down
1 change: 1 addition & 0 deletions pages/algorithms/is-data-table.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Identifying Data Tables
key: is-data-table
---

## Identifying Tables in QuailJS
Expand Down
1 change: 1 addition & 0 deletions pages/algorithms/lang-identification.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Language identification
key: language-identification
---

A language identification algorithm is used the determine the language of a given text. Some languages can be determined reliably from their character use alone. In these cases it is sufficient to analyse the characters and encoding of the web content. For languages sharing the same script (such as languages using the latin alphabet), the distinction is more difficult.
Expand Down
1 change: 1 addition & 0 deletions pages/algorithms/non-empty.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Non-empty text string
key: non-empty
---

A string of characters (text) is considered *"non-empty"* if it contains 1 or more characters that are contained within any of the following unicode categories:
Expand Down
1 change: 1 addition & 0 deletions pages/algorithms/rendered-text.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Rendered text
key: rendered-text
---

An element is considered to have "rendered text" when it contains text nodes that do not inherit from an element that is styled with `display:none` or `visibility:hidden`. The rendered text is a string of the concatenated text of all these text nodes.