Skip to content

Commit

Permalink
Modify Languages page to indicate untested and untestable languages (T…
Browse files Browse the repository at this point in the history
…heRenegadeCoder#629)

* Modify Languages page to indicate untested and untestable languages

* Fix untestable count and update welcome message
  • Loading branch information
rzuckerm authored Dec 22, 2023
1 parent 88e7b92 commit 49600b8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 8 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
snakemd~=2.1.0
subete~=0.17.0
subete~=0.18.0
image-titler~=2.4.0
glotter2~=0.8.0
pyyaml~=6.0
46 changes: 39 additions & 7 deletions scripts/automate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Optional, Iterable, List, Set
from typing import Optional, Iterable, List, Set, Union
import datetime
import functools
import imghdr
Expand Down Expand Up @@ -625,11 +625,17 @@ def generate_languages_index(repo: subete.Repo):
times=times,
image=_get_default_language_image()
)
language_index.add_paragraph(
welcome_text = (
"Welcome to the Languages page! Here, you'll find a list of all of the languages represented in the collection. "
f"At this time, there are {len(list(repo))} languages, of which {repo.total_tests()} are tested, "
f"and {repo.total_programs()} code snippets."
f"At this time, there are {len(list(repo))} languages, of which {repo.total_tests()} are tested"
)
untestables = repo.total_untestables()
if untestables:
verb_untestables = "are" if untestables != 1 else "is"
welcome_text += f", {untestables} {verb_untestables} untestable"

welcome_text += f", and {repo.total_programs()} code snippets."
language_index.add_paragraph(welcome_text)
language_index.add_heading("Language Collections by Letter", level=2)
language_index.add_paragraph(
"To help you navigate the collection, the following languages are organized alphabetically and grouped by first letter."
Expand All @@ -641,21 +647,47 @@ def generate_languages_index(repo: subete.Repo):
snippets = sum(language.total_programs() for language in languages)
tests = sum(1 if language.has_testinfo()
else 0 for language in languages)
untestables = sum(1 if language.has_untestable_info()
else 0 for language in languages)
verb = "are" if tests != 1 else "is"
singular = "language" if len(languages) == 1 else "languages"
language_index.add_paragraph(
verb_untestables = "are" if untestables != 1 else "is"
language_statement = (
f"The '{letter.upper()}' collection contains {len(languages)} {singular}, "
f"of which {tests} {verb} tested, and {snippets} code snippets."
f"of which {tests} {verb} tested"
)
if untestables:
language_statement += f", {untestables} {verb_untestables} untestable"

language_index.add_paragraph(f"{language_statement}, and {snippets} code snippets.")
languages.sort(key=lambda x: x.name().casefold())
languages = [
snakemd.Inline(x.name(), link=x.lang_docs_url())
_get_language_link_and_testability(x)
for x in languages
]
language_index.add_block(snakemd.MDList(languages))
language_index.dump("index", dir=str(language_index_path))


def _get_language_link_and_testability(
language: subete.LanguageCollection
) -> Union[snakemd.Inline, snakemd.Paragraph]:
language_link = snakemd.Inline(language.name(), link=language.lang_docs_url())
if language.has_testinfo():
return language_link

if language.has_untestable_info():
testability = [
snakemd.Inline(" ("),
snakemd.Inline("untestabled", link=language.untestable_info_url()),
snakemd.Inline(")")
]
else:
testability = [snakemd.Inline(" (untested)")]

return snakemd.Paragraph([language_link] + testability)


def generate_projects_index(repo: subete.Repo):
"""
Generate index.md for file for Projects page
Expand Down

0 comments on commit 49600b8

Please sign in to comment.