Skip to content

Commit

Permalink
Considered diff line highlighting/formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
calaldees committed Nov 14, 2024
1 parent a7d72ca commit 11f7ce5
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions teachprogramming/lib/static/projects.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ <h1>Projects</h1>
const hostElement = document.getElementById('main') || document.getElementsByTagName('body').item(0);


function renderProjects(projects) {
function renderProjectList(projects) {
function _hrefProject(project) {
const _urlParams = new URLSearchParams(urlParams)
_urlParams.append(QUERY_STRING_project, project)
Expand All @@ -44,22 +44,17 @@ <h1>Projects</h1>
h('h2',{},language),
...Object.entries(data.versions.parents).map(([version, parent_version])=>[
h('h3',{},version),
h('pre',{classList: 'diff'}, data.diffs[language][version]),
h('pre',{classList: 'diff'}, renderDiff(data.diffs[language][version])),
h('pre',{classList: 'full'}, data.languages[language][version]),
]).flat()
]).flat())
}

function renderProjectBasic(data) {
return h('div',{},Object.entries(data.languages).map(
([language, _version_code])=>[h('h2',{},language), ...(!_version_code?[]:
Object.entries(_version_code).map(([version, code])=>[
h('h3',{},version),
h('pre',{},code),
h('pre',{},data.diffs[language][version])
]).flat()
)]
).flat())
function renderDiff(diff) {
if (!diff) {return}
return h('code',{},diff.split("\n").map(line=>
h('span',{classList:["line", line.startsWith("+")?"add":""]},line+"\n")
))
}

// Consider CSS toggle
Expand All @@ -73,7 +68,7 @@ <h1>Projects</h1>
} else {
fetch('/api/v1/projects.json')
.then(response => response.json())
.then(data=>hostElement.appendChild(renderProjects(data.projects)))
.then(data=>hostElement.appendChild(renderProjectList(data.projects)))
.catch(err => console.error(err))
}

Expand Down

0 comments on commit 11f7ce5

Please sign in to comment.