aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-10-01 13:10:03 -0400
committerBobby <[email protected]>2022-10-01 13:10:03 -0400
commit1baaddc8096ee2ff1a51db39ce6133a372d2a3ef (patch)
tree79a7b225f471b440dc90b24d8fc7cde34c932379
parent6aea05e6c6d26371e6f32ea7b260b65e759c1a6a (diff)
downloadthatcomputerscientist-1baaddc8096ee2ff1a51db39ce6133a372d2a3ef.tar.xz
thatcomputerscientist-1baaddc8096ee2ff1a51db39ce6133a372d2a3ef.zip
Added source code visualizer
-rw-r--r--dev_status/__init__.py0
-rw-r--r--dev_status/admin.py3
-rw-r--r--dev_status/apps.py6
-rw-r--r--dev_status/migrations/__init__.py0
-rw-r--r--dev_status/models.py3
-rw-r--r--dev_status/tests.py3
-rw-r--r--dev_status/urls.py11
-rw-r--r--dev_status/views.py52
-rw-r--r--requirements.txt1
-rw-r--r--static/css/main.css48
-rw-r--r--static/images/icons/Folder.icobin0 -> 1078 bytes
-rw-r--r--static/images/icons/file.icobin0 -> 766 bytes
-rw-r--r--templates/blog/partials/base.html5
-rw-r--r--templates/dev_status/home.html43
-rw-r--r--thatcomputerscientist/settings.py1
-rw-r--r--thatcomputerscientist/urls.py1
16 files changed, 175 insertions, 2 deletions
diff --git a/dev_status/__init__.py b/dev_status/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev_status/__init__.py
diff --git a/dev_status/admin.py b/dev_status/admin.py
new file mode 100644
index 00000000..8c38f3f3
--- /dev/null
+++ b/dev_status/admin.py
@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.
diff --git a/dev_status/apps.py b/dev_status/apps.py
new file mode 100644
index 00000000..132122b0
--- /dev/null
+++ b/dev_status/apps.py
@@ -0,0 +1,6 @@
+from django.apps import AppConfig
+
+
+class DevStatusConfig(AppConfig):
+ default_auto_field = 'django.db.models.BigAutoField'
+ name = 'dev_status'
diff --git a/dev_status/migrations/__init__.py b/dev_status/migrations/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/dev_status/migrations/__init__.py
diff --git a/dev_status/models.py b/dev_status/models.py
new file mode 100644
index 00000000..71a83623
--- /dev/null
+++ b/dev_status/models.py
@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.
diff --git a/dev_status/tests.py b/dev_status/tests.py
new file mode 100644
index 00000000..7ce503c2
--- /dev/null
+++ b/dev_status/tests.py
@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.
diff --git a/dev_status/urls.py b/dev_status/urls.py
new file mode 100644
index 00000000..c9bcf35a
--- /dev/null
+++ b/dev_status/urls.py
@@ -0,0 +1,11 @@
+from django.urls import path
+from django.views.generic import RedirectView
+from . import views
+
+app_name = 'dev_status'
+urlpatterns = [
+ path('', views.home, name='home'),
+ path('tree/', views.tree, name='roottree'),
+ path('tree/<path:path>', views.tree, name='tree'),
+ path('raw/<path:path>', views.raw, name='raw'),
+]
diff --git a/dev_status/views.py b/dev_status/views.py
new file mode 100644
index 00000000..1d511293
--- /dev/null
+++ b/dev_status/views.py
@@ -0,0 +1,52 @@
+from django.shortcuts import render
+from github import Github
+from dotenv import load_dotenv
+import os
+
+load_dotenv()
+
+# Create your views here.
+
+def home(request):
+ g = Github(os.getenv('GH_TOKEN'))
+ repo = g.get_repo('luciferreeves/thatcomputerscientist')
+ contents = repo.get_contents('')
+ files = []
+ while contents:
+ file_content = contents.pop(0)
+ files.append(file_content)
+ context = {
+ 'title': 'Source Code',
+ 'files': files,
+ }
+ return render(request, 'dev_status/home.html', context)
+
+def tree(request, path=None):
+ g = Github(os.getenv('GH_TOKEN'))
+ repo = g.get_repo('luciferreeves/thatcomputerscientist')
+ path = '' if not path else path
+ parent = '' if len(path.split('/')) == 1 else '/'.join(path.split('/')[:-1])
+ contents = repo.get_contents(path)
+ files = []
+ while contents:
+ file_content = contents.pop(0)
+ files.append(file_content)
+ context = {
+ 'title': 'Tree - {}'.format(path),
+ 'files': files,
+ 'parent': parent,
+ }
+ return render(request, 'dev_status/home.html', context)
+
+def raw(request, path):
+ g = Github(os.getenv('GH_TOKEN'))
+ repo = g.get_repo('luciferreeves/thatcomputerscientist')
+ path = '' if not path else path
+ parent = '' if len(path.split('/')) == 1 else '/'.join(path.split('/')[:-1])
+ contents = repo.get_contents(path)
+ context = {
+ 'title': 'File - {}'.format(path),
+ 'file': contents.html_url,
+ 'parent': parent,
+ }
+ return render(request, 'dev_status/home.html', context) \ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 35143047..2312d149 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,3 +6,4 @@ whitenoise==6.2.0
six==1.16.0
cryptocode==0.1
captcha==0.4
+PyGithub==1.55
diff --git a/static/css/main.css b/static/css/main.css
index 47ba85a3..469d4484 100644
--- a/static/css/main.css
+++ b/static/css/main.css
@@ -366,3 +366,51 @@ li.new::before{
border-radius: 0 0 0 5px;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
+
+.file {
+ padding: 4px 0px;
+ display: flex;
+ flex-direction: row;
+ flex-wrap: wrap;
+ width: 100%;
+}
+
+.file > div {
+ color: #cecece;
+}
+
+.file > a {
+ color: #cecece;
+ text-decoration: none;
+}
+
+.ft-file {
+ width: 32px;
+ background-image: url('../images/icons/file.ico');
+ background-repeat: no-repeat;
+ background-position: center;
+ margin-right: 10px;
+ background-size: contain;
+}
+
+.ft-dir {
+ width: 32px;
+ background-image: url('../images/icons/folder.ico');
+ background-repeat: no-repeat;
+ background-position: center;
+ background-size: contain;
+ margin-right: 10px;
+}
+
+.file-name:hover {
+ cursor: pointer;
+ text-decoration: underline;
+}
+
+.file-meta.file-meta-dark {
+ display: none;
+}
+
+.hljs-style-github-dark-dimmed .hljs {
+ background: rgb(34 39 46 / 0%) !important;
+}
diff --git a/static/images/icons/Folder.ico b/static/images/icons/Folder.ico
new file mode 100644
index 00000000..c015841c
--- /dev/null
+++ b/static/images/icons/Folder.ico
Binary files differ
diff --git a/static/images/icons/file.ico b/static/images/icons/file.ico
new file mode 100644
index 00000000..94c8a295
--- /dev/null
+++ b/static/images/icons/file.ico
Binary files differ
diff --git a/templates/blog/partials/base.html b/templates/blog/partials/base.html
index 82350e32..d15ef0af 100644
--- a/templates/blog/partials/base.html
+++ b/templates/blog/partials/base.html
@@ -39,12 +39,13 @@
<div style="width: 1000px; margin: 20px auto;">
<ul class="topnav">
{% comment %} <img src="{% static 'images/gifs/new.gif' %}" alt="new" style="margin-left: 5px;"> {% endcomment %}
- <li class="new"><a href="#">
- Dev Status
+ <li class="new"><a href="{% url 'dev_status:home' %}">
+ Source Code
</a></li>
{% if user.is_authenticated %}
<li><a href="{% url 'users:logout' %}">Logout</a></li>
{% endif %}
+ </ul>
<hr>
</div>
<div class="mc">
diff --git a/templates/dev_status/home.html b/templates/dev_status/home.html
new file mode 100644
index 00000000..4736b712
--- /dev/null
+++ b/templates/dev_status/home.html
@@ -0,0 +1,43 @@
+{% extends 'blog/partials/base.html' %} {% block content %}
+<div class="main">
+ <h3 style="margin-bottom: 0px">
+ <em>Source Code</em>
+ <ul class="topnav" style="float:right;">
+ <li><a href="#">Commit History</a></li>
+ <li><a href="#">Build History</a></li>
+ <li><a href="#">Issues</a></li>
+ <li><a href="#">Pull Requests</a></li>
+ </ul>
+ </h3>
+ <hr>
+ <br>
+ <div class="files">
+ {% if parent %}
+ <div class="file">
+ <div class="ft-dir"></div>
+ <a class="file-name" href="{% url 'dev_status:tree' parent %}">..</a>
+ </div>
+ {% endif %}
+ {% if parent == '' %}
+ <div class="file">
+ <div class="ft-dir"></div>
+ <a class="file-name" href="{% url 'dev_status:home' %}">..</a>
+ </div>
+ {% endif %}
+ {% if files %}
+ {% for file in files %}
+ <div class="file">
+ <div class="ft-{{ file.type }}"></div>
+ {% if file.type == 'dir' %}
+ <a class="file-name" href="{% url 'dev_status:tree' file.path %}">{{ file.name }}</a>
+ {% else %}
+ <a class="file-name" href="{% url 'dev_status:raw' file.path %}">{{ file.name }}</a>
+ {% endif %}
+ </div>
+ {% endfor %}
+ {% endif %}
+ {% if file %}
+ <script src = "https://emgithub.com/embed-v2.js?target={{ file }}&style=github-dark-dimmed&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on&showFullPath=on&showCopy=on"></script>
+ {% endif %}
+</div>
+{% endblock %}
diff --git a/thatcomputerscientist/settings.py b/thatcomputerscientist/settings.py
index efd01fe3..43dbdd17 100644
--- a/thatcomputerscientist/settings.py
+++ b/thatcomputerscientist/settings.py
@@ -49,6 +49,7 @@ INSTALLED_APPS = [
'users',
'userpages',
'blog_admin',
+ 'dev_status',
]
MIDDLEWARE = [
diff --git a/thatcomputerscientist/urls.py b/thatcomputerscientist/urls.py
index be0018f0..92828e7c 100644
--- a/thatcomputerscientist/urls.py
+++ b/thatcomputerscientist/urls.py
@@ -24,6 +24,7 @@ urlpatterns = [
path('users/', include('users.urls', namespace='users')),
path('blog-admin/', include('blog_admin.urls', namespace='blog-admin')),
path('', include(('userpages.urls', 'userpages'), namespace='userpages')),
+ path('source/', include(('dev_status.urls', 'dev_status'), namespace='dev_status')),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)