Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added api/__init__.py
Empty file.
90 changes: 90 additions & 0 deletions api/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
"""Flask Application."""

import os, subprocess, sys

# load libaries
from flask import Flask, render_template

from goto import GotoMagic
from goto.the_real_goto import run_command, parse_args

# init Flask app
app = Flask(__name__)

project = None


# view functions
@app.route('/', defaults={'project': project})
@app.route('/map', defaults={'project': project})
@app.route('/map/<project>')
def map(project):
"""Show magic."""
project = detect(project)
magic = GotoMagic(project)
shortcuts = magic.magic.items()
return render_template('map.html', project=project, shortcuts=shortcuts)


@app.route('/projects')
def projects():
"""Show the magic projects!"""
project = detect(None)
projects = list_projects()
return render_template('projects.html', projects=projects, project=project)


@app.route('/<magicword>', defaults={'project': project})
@app.route('/<magicword>/<project>')
def goto(magicword, project):
return run_goto(magicword, project)


@app.route('/project/<project>')
def project(project):
return subprocess.check_output(
f"project {project}",
shell=True
).decode(sys.stdout.encoding)

def detect(project):
if project is None:
return subprocess.check_output('project').rstrip().decode(sys.stdout.encoding)
else:
return project

def list_projects():
projects = subprocess.check_output('project list', shell=True).decode(sys.stdout.encoding).split('\n')
return projects

def run_goto(magicword, project=None):

project = detect(project)

magic = GotoMagic(project)
argv = [magicword]
command, args, options = parse_args(argv)

if command is None:
options = ["--open"]

output, err = run_command(magic, command, args, options)

if err:
return err.message
if output is not None:
return output

try:
uri = magic.get_uri(magicword)
return uri
except:
return "something is off."
return "something is off."


if __name__ == "__main__":
####################
# FOR DEVELOPMENT
####################
app.run(host='0.0.0.0', port=80, debug=True)
Binary file added api/static/favicon.ico
Binary file not shown.
Empty file added api/static/main.js
Empty file.
80 changes: 80 additions & 0 deletions api/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*- Screen Sizes*/
/* COLOR HEX */
/* COLOR Gradient */
/*import fonts*/
@import url("https://fonts.googleapis.com/css2?family=Abril+Fatface&display=swap");
@import url("https://fonts.googleapis.com/css2?family=Montserrat&display=swap");
/*media queries*/
html {
box-sizing: border-box;
}

*, *:before, *:after {
box-sizing: inherit;
}

body {
background-color: #eaeaeaff;
font-family: "Montserrat", sans-serif;
font-size: 0.875em;
color: #444444;
line-height: 1.5;
}



.dl-blurbs {
display: grid;
margin: 0 10rem;
}
@media (min-width: 768px) {
.dl-blurbs {
grid-template-columns: repeat(2, 1fr);
gap: 2vw;
}
}

/* LIST */
dl {
counter-reset: count;
background: linear-gradient(90deg, rgba(0, 0, 0, 0.04) 20%, rgba(255, 255, 255, 0) 0%);
padding-left: 4vw;
padding-right: 4vw;
margin: 0;
}
@media (min-width: 768px) {
dl {
padding-left: 2vw;
}
}
@media (min-width: 1024px) {
dl {
padding-top: 3vw;
padding-bottom: 3vw;
}
}

dl + dl {
counter-reset: counter 4;
}

dt {
counter-increment: count;
color: #4f6d7aff;
font-family: "Montserrat", sans-serif;
font-size: 4vw;
text-transform: uppercase;
}

dt::before {
content: counter(count, decimal-leading-zero) ".";
font-family: "Abril Fatface", cursive;
color: #5ea5b8ff;
margin-left: -1vw;
padding-right: 12px;
}

dd {
margin-left: 5vw;
margin-bottom: 2vh;
}
1 change: 1 addition & 0 deletions api/static/terminal.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions api/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<title>{{ title }}</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='terminal.min.css') }}">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
<script src="{{url_for('static', filename='main.js')}}"></script>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
19 changes: 19 additions & 0 deletions api/templates/map.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends 'base.html' %}

{% set title = project %}

{% block content %}
<code>project</code>

<b>{{ project }}</b>
<section class="dl-blurbs">
<dl>
{% for shortcut, uri in shortcuts %}
<!-- <li><a href="{{uri}}"> {{shortcut}} <a/> </li> -->
<a href="{{ url_for('goto', magicword=shortcut, project=project) }}"><dt>{{shortcut}}</dt><a/>
<dd><a href="{{uri}}">{{uri}}</a></dd>
{% endfor %}
</dl>

</section>
{% endblock %}
19 changes: 19 additions & 0 deletions api/templates/projects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends 'base.html' %}

{% set title = "projects" %}

{% block content %}
<code>project</code>

<b>{{ project }}</b>
<section class="dl-blurbs">
<dl>
{% for p in projects %}
<!-- <li><a href="{{uri}}"> {{shortcut}} <a/> </li> -->
<a href="{{ url_for('map', project=p) }}"><dt>{{p}}</dt><a/>
<!--<dd></dd>-->
{% endfor %}
</dl>

</section>
{% endblock %}
Loading