aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2020-11-02 09:18:24 +0200
committerFilipp Lepalaan <filipp@mac.com>2020-11-02 09:18:24 +0200
commitf7dbe498e966261f94fa62377147c4cdd5a47ea2 (patch)
treee64aeaeff3aefc2a78081972f8900d74624eea29
parent494dedf17035c1699c35cd2559f15a64eaa7eff3 (diff)
downloadhello-f7dbe498e966261f94fa62377147c4cdd5a47ea2.tar.gz
hello-f7dbe498e966261f94fa62377147c4cdd5a47ea2.tar.bz2
hello-f7dbe498e966261f94fa62377147c4cdd5a47ea2.zip
Better
-rw-r--r--README.md46
-rwxr-xr-xhello.py (renamed from client.py)14
-rw-r--r--requirements.txt2
-rw-r--r--templates/nginx.rst6
4 files changed, 59 insertions, 9 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..42f3fd0
--- /dev/null
+++ b/README.md
@@ -0,0 +1,46 @@
+## Introduction
+
+hello is a boilerplate repository.
+
+## Requirements
+
+- nginx with _autoindex_ on and _autoindex_format_ set to _json_ for the repo directory:
+
+ server {
+ listen 8080;
+ server_name localhost;
+
+ location / {
+ root /Users/filipp/Projects/hello/templates;
+ autoindex on;
+ autoindex_format json;
+ }
+ }
+
+- the _requests_ HTTP client library (which everyone probably already has installed). _pip install -r requirements.txt_ to install.
+
+## Setup
+
+- Put your boilerplate on a web server
+- Export an environment variabled called _HELLO_REPO_ which points to the directory that contains your boilerplate templates
+
+
+## Usage
+
+Run _hello.py_ with boilerplate name or without the name to get a list of available templates
+
+The boilerplate templates get rendered with all your environment variables as context so feel free to use stuff like $HOME or $PWD or $USER or whatever inside them.
+
+'Nuff said.
+
+## FAQ
+
+- Why not do this as a snippet collection for <insert editor name here>?
+- I keep switching between 4 different editors so I needed something a bit more universal.
+
+## License
+
+Copyright © 2020 Filipp Lepalaan <filipp@mac.com>
+This work is free. You can redistribute it and/or modify it under the
+terms of the Do What The Fuck You Want To Public License, Version 2,
+as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.
diff --git a/client.py b/hello.py
index 28b9c45..237d975 100755
--- a/client.py
+++ b/hello.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python
import os
import sys
+from string import Template
+
import requests
def main(arg=None):
@@ -12,16 +14,20 @@ def main(arg=None):
templates.append(t['name'])
if arg is None:
- return templates
+ return "\n".join(templates)
if arg in templates:
url = "{0}/{1}".format(repo.rstrip("/"), arg)
- template = requests.get(url).text
- return template
+ template = Template(requests.get(url).text)
+ return template.substitute(**os.environ)
else:
error = "Template for {0} not found".format(arg)
raise Exception(error)
if __name__ == '__main__':
- print(main(sys.argv[1]))
+ arg = None
+ if len(sys.argv) > 1:
+ arg = sys.argv[1]
+
+ print(main(arg))
diff --git a/requirements.txt b/requirements.txt
index ed56b80..f229360 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1 @@
requests
-fastapi
-uvicorn
diff --git a/templates/nginx.rst b/templates/nginx.rst
index 1fd314d..5923225 100644
--- a/templates/nginx.rst
+++ b/templates/nginx.rst
@@ -9,15 +9,15 @@ http {
include mime.types;
default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
+ sendfile on;
+ keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
location / {
- root html;
+ root $PWD/public_html;
index index.html index.htm;
}
}