-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure html so that we show each language in a separate detail
The code that we show is only related to code snippet that is relevant so that we reduce the amount of noise that is presented to the user.
- Loading branch information
1 parent
2db2357
commit 2534d87
Showing
9 changed files
with
95 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
{% load pygmentize %} | ||
{% for file in files %} | ||
{% for filetype, filenames in files.items %} | ||
<details> | ||
<summary>{{file.name}}</summary> | ||
{{file.src|pygmentize:file.type}} | ||
<summary>{{ filetype }}</summary> | ||
{% for file in filenames %} | ||
<br> | ||
{{ file.filename }} (LOC {{ file.loc }}) | ||
{{ file.src|pygmentize:file.pygment_type }} | ||
{% endfor %} | ||
</details> | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{% load humanize %} | ||
<form data-controller="book-search" data-reflex-root="#morph"> | ||
<input type="text" placeholder="search for a book ..." data-target="book-search.query" | ||
data-action="debounced:input->book-search#perform" /> | ||
<div id="morph"> | ||
<div> | ||
|
||
<span data-target="book-search.activity" class="" hidden> | ||
<i class="fas fa-spinner fa-spin"></i> | ||
Searching for books... | ||
</span> | ||
<span data-target="book-search.count" class=""> | ||
<strong>{{count|default:0|intcomma}}</strong> books found | ||
</span> | ||
</div> | ||
|
||
<table data-target="book-search.list" {% if not books %} hidden {% endif %}> | ||
<thead> | ||
<tr> | ||
<th scope="col">Subject</th> | ||
<th scope="col">Title</th> | ||
<th scope="col">Author</th> | ||
<th scope="col">Publish Date</th> | ||
<th scope="col">ISBN</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for book in books|slice:'0:5' %} | ||
<tr> | ||
<td>{{book.subject|join:', '|truncatechars:10}} </td> | ||
<td>{{book.title|truncatechars:30}}</td> | ||
<td>{{book.author_name|join:', '|truncatechars:30}}</td> | ||
<td>{{book.publish_year.0 }}</td> | ||
<td>{{book.isbn.0|truncatechars:5}}</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<section> | ||
<a | ||
href="#" | ||
data-controller="example" | ||
data-action="click->example#increment" | ||
data-count="{{ count }}" | ||
> | ||
Increment {{ count }} | ||
</a> | ||
</section> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% extends "base.html" %} | ||
{% load humanize %} | ||
{% block subtitle %}{{ subtitle }}{% endblock subtitle %} | ||
{% block main %} | ||
<div> | ||
{% include demo_template %} | ||
{% include "_add_sources.html" %} | ||
</div> | ||
{% endblock %} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,32 @@ | ||
from collections import defaultdict | ||
from django.conf import settings | ||
import os | ||
|
||
BASE_PATH = settings.BASE_DIR | ||
|
||
|
||
class MixinBase: | ||
template_name="demo.html" | ||
demo_template = None | ||
subtitle = None | ||
|
||
def get_files(self): | ||
files = defaultdict(list) | ||
path_ = lambda x: open(os.path.join(BASE_PATH, x)).read() | ||
return [dict(src=path_(i[0]), type=i[1], name=i[0]) for i in self.files] | ||
for filename, filetype, pygment_type in self.files: | ||
filesrc = path_(filename) | ||
files[filetype].append({ | ||
'src': filesrc, | ||
'pygment_type': pygment_type, | ||
'filename': filename, | ||
'loc': len(filesrc.split('\n')) | ||
}) | ||
return dict(files) | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context['files'] = self.get_files() | ||
context['demo_template'] = self.demo_template | ||
context['subtitle'] = self.subtitle | ||
return context | ||
|