aboutsummaryrefslogtreecommitdiffgithub
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/all.go2
-rw-r--r--tools/figlet.go9
-rw-r--r--tools/notfound.go9
-rw-r--r--tools/share/templates/figlet.html2
-rw-r--r--tools/share/templates/notfound.html1
-rw-r--r--tools/share/templates/tools.html46
-rw-r--r--tools/tools.go78
7 files changed, 135 insertions, 12 deletions
diff --git a/tools/all.go b/tools/all.go
index 00989ee..d901e56 100644
--- a/tools/all.go
+++ b/tools/all.go
@@ -36,7 +36,7 @@ var (
)
func All() *tb.ToolBag {
- return tb.NewToolBag(IP, Headers, NewFiglet(), NewNotFound())
+ return tb.NewToolBag(IP, Headers, NewFiglet(), NewNotFound(), NewTools())
}
// nasty hack to remove port numbers and the brackets from ipv6 addresses
diff --git a/tools/figlet.go b/tools/figlet.go
index 26e3318..2e69856 100644
--- a/tools/figlet.go
+++ b/tools/figlet.go
@@ -18,7 +18,6 @@ package tools
import (
"errors"
- "flag"
"html/template"
"net/http"
"strings"
@@ -45,10 +44,10 @@ func NewFiglet() *Figlet {
func (f *Figlet) Name() string { return "figlet" }
func (f *Figlet) Desc() string { return "a web frontend to figlet" }
func (f *Figlet) Path() string { return "/" + f.Name() }
-func (f *Figlet) AddArgs() {
- flag.StringVar(&f.args.template, tb.Arg(f, "template"), "", "path to template")
- flag.StringVar(&f.args.unix, tb.Arg(f, "unix"), "", "path to unix socket to execd")
- flag.StringVar(&f.args.tcp, tb.Arg(f, "tcp"), "", "tcp address to execd")
+func (f *Figlet) AddArgs(toolbag *tb.ToolBag) {
+ toolbag.StringVar(&f.args.template, tb.Arg(f, "template"), "", "path to template")
+ toolbag.StringVar(&f.args.unix, tb.Arg(f, "unix"), "", "path to unix socket to execd")
+ toolbag.StringVar(&f.args.tcp, tb.Arg(f, "tcp"), "", "tcp address to execd")
}
func (f *Figlet) makeClient() (*execd.Client, error) {
diff --git a/tools/notfound.go b/tools/notfound.go
index 9e70cbb..e8c504c 100644
--- a/tools/notfound.go
+++ b/tools/notfound.go
@@ -18,7 +18,6 @@ package tools
import (
"errors"
- "flag"
"html/template"
"io/ioutil"
"math/rand"
@@ -48,14 +47,14 @@ func NewNotFound() *NotFound {
}
func (nf *NotFound) Name() string { return "notfound" }
-func (nf *NotFound) Desc() string { return "not found page showing a random math problem" }
+func (nf *NotFound) Desc() string { return "show a random math problem" }
// be a catch-all
func (nf *NotFound) Path() string { return "/" }
-func (nf *NotFound) AddArgs() {
- flag.StringVar(&nf.args.dir, tb.Arg(nf, "dir"), "", "directory with the math problems")
- flag.StringVar(&nf.args.template, tb.Arg(nf, "template"), "", "path to template")
+func (nf *NotFound) AddArgs(toolbag *tb.ToolBag) {
+ toolbag.StringVar(&nf.args.dir, tb.Arg(nf, "dir"), "", "directory with the math problems")
+ toolbag.StringVar(&nf.args.template, tb.Arg(nf, "template"), "", "path to template")
}
func (nf *NotFound) Init() error {
diff --git a/tools/share/templates/figlet.html b/tools/share/templates/figlet.html
index 48a735d..1d3f4b3 100644
--- a/tools/share/templates/figlet.html
+++ b/tools/share/templates/figlet.html
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
- <title>figlet frontend</title>
+ <title>figlet frontend « austin adams</title>
<style type="text/css">
form {
display: block;
diff --git a/tools/share/templates/notfound.html b/tools/share/templates/notfound.html
index 8150d54..ba99e76 100644
--- a/tools/share/templates/notfound.html
+++ b/tools/share/templates/notfound.html
@@ -24,3 +24,4 @@
<img alt="{{ .Alt }}" src="data:image/png;base64,{{ .Base64 }}" />
</body>
</html>
+<!-- vim: set ts=2 sw=2 et : -->
diff --git a/tools/share/templates/tools.html b/tools/share/templates/tools.html
new file mode 100644
index 0000000..278858e
--- /dev/null
+++ b/tools/share/templates/tools.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>tools « austin adams</title>
+ <style type="text/css">
+ html, body {
+ width: 100%;
+ height: 100%;
+ margin: 0;
+ padding: 0;
+ background-color: white;
+ font-size: 12px;
+ }
+
+ h1 {
+ font-size: 24px;
+ }
+
+ div {
+ display: block;
+ width: 512px;
+ margin: auto;
+ position: relative;
+ top: 128px;
+ }
+
+ li span {
+ width: 85%;
+ float: right;
+ }
+ </style>
+</head>
+<body>
+ <div>
+ <h1>tools</h1>
+ <ul>
+ {{ range .Tools }}
+ <li><a href="{{ .Path }}">{{ .Name }}</a> <span>&mdash; {{ .Desc }}</span></li>
+ {{ end }}
+ </ul>
+ <a href="{{ .Source }}">source</a>
+ </div>
+</body>
+</html>
+<!-- vim: set ts=2 sw=2 et : -->
diff --git a/tools/tools.go b/tools/tools.go
new file mode 100644
index 0000000..c0a355a
--- /dev/null
+++ b/tools/tools.go
@@ -0,0 +1,78 @@
+// toolbag - dynamic tools for my website
+// Copyright (C) 2015 Austin Adams
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+package tools
+
+import (
+ "errors"
+ "html/template"
+ "net/http"
+
+ tb "code.austinjadams.com/toolbag"
+)
+
+type Tools struct {
+ tb *tb.ToolBag
+ templ *template.Template
+
+ args struct {
+ source, template string
+ }
+}
+
+func NewTools() *Tools {
+ return &Tools{}
+}
+
+func (t *Tools) Name() string { return "tools" }
+func (t *Tools) Desc() string { return "list tools" }
+
+// be a catch-all
+func (t *Tools) Path() string { return "/" + t.Name() }
+
+func (t *Tools) AddArgs(toolbag *tb.ToolBag) {
+ // XXX kind of a hack, but no regrets here
+ t.tb = toolbag
+ toolbag.StringVar(&t.args.template, tb.Arg(t, "template"), "", "path to template")
+ toolbag.StringVar(&t.args.source, tb.Arg(t, "source"), "", "url of toolbag source")
+}
+
+func (t *Tools) Init() error {
+ if t.args.template == "" {
+ return errors.New("missing template arg")
+ }
+ if t.args.source == "" {
+ return errors.New("missing source arg")
+ }
+
+ templ, err := template.ParseFiles(t.args.template)
+ if err != nil {
+ return err
+ }
+ t.templ = templ
+ return nil
+}
+
+func (t *Tools) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ err := t.templ.Execute(w, struct {
+ Source string
+ Tools []tb.Tool
+ }{t.args.source, t.tb.Tools})
+
+ if err != nil {
+ tb.LogWhine(t, err)
+ }
+}