summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--svc/cache.go27
-rw-r--r--svc/conf_test.go1
-rw-r--r--svc/handlers_test.go1
-rw-r--r--svc/init.go1
-rw-r--r--svc/init_test.go12
5 files changed, 5 insertions, 37 deletions
diff --git a/svc/cache.go b/svc/cache.go
index e2078d7..20c3953 100644
--- a/svc/cache.go
+++ b/svc/cache.go
@@ -33,33 +33,6 @@ func initTemplates() *template.Template {
 	return template.Must(template.ParseFiles(assetsDir + "/tmpl/index.html"))
 }
 
-func initAssets() *staticAssets {
-	confObj.Mu.RLock()
-	defer confObj.Mu.RUnlock()
-
-	css, err := os.Open(confObj.AssetsDir + "/style.css")
-	errLog("", err)
-	cssStat, err := css.Stat()
-	errLog("", err)
-	cssData, err := ioutil.ReadAll(css)
-	errLog("", err)
-
-	indStat, err := os.Stat(confObj.AssetsDir + "/tmpl/index.html")
-	errLog("", err)
-
-	var b []byte
-	buf := bytes.NewBuffer(b)
-	errLog("", tmpls.ExecuteTemplate(buf, "index.html", confObj.Instance))
-
-	return &staticAssets{
-		mu:       sync.RWMutex{},
-		index:    buf.Bytes(),
-		indexMod: indStat.ModTime(),
-		css:      cssData,
-		cssMod:   cssStat.ModTime(),
-	}
-}
-
 func cacheTimer() bool {
 	confObj.Mu.RLock()
 	answer := time.Since(confObj.LastCache) > confObj.CacheInterval
diff --git a/svc/conf_test.go b/svc/conf_test.go
index 37e64a6..5956fa1 100644
--- a/svc/conf_test.go
+++ b/svc/conf_test.go
@@ -19,4 +19,5 @@ func Test_initConfig(t *testing.T) {
 			}
 		}
 	})
+	testConfig()
 }
diff --git a/svc/handlers_test.go b/svc/handlers_test.go
index 7f2e7d7..36c795a 100644
--- a/svc/handlers_test.go
+++ b/svc/handlers_test.go
@@ -15,6 +15,7 @@ import (
 // they'll need more than a barebones test environment to
 // get any real information. The HTTP responses are being
 // tested by me by hand, mostly.
+
 func Test_indexHandler(t *testing.T) {
 	initTestConf()
 	t.Run("indexHandler", func(t *testing.T) {
diff --git a/svc/init.go b/svc/init.go
index d585bfa..e9c64af 100644
--- a/svc/init.go
+++ b/svc/init.go
@@ -67,7 +67,6 @@ func initSvc() {
 	initDatabase()
 	go cacheAndPush()
 	tmpls = initTemplates()
-	staticCache = initAssets()
 	watchForInterrupt()
 	pingAssets()
 }
diff --git a/svc/init_test.go b/svc/init_test.go
index 8fd8e95..a9fe624 100644
--- a/svc/init_test.go
+++ b/svc/init_test.go
@@ -2,7 +2,6 @@ package svc // import "github.com/getwtxt/getwtxt/svc"
 
 import (
 	"fmt"
-	"html/template"
 	"log"
 	"os"
 	"strings"
@@ -20,16 +19,15 @@ var (
 
 func initTestConf() {
 	initTestOnce.Do(func() {
+		logToNull()
 
 		testConfig()
-		tmpls = testTemplates()
-		staticCache = initAssets()
+		tmpls = initTemplates()
+		pingAssets()
 
 		confObj.Mu.RLock()
 		defer confObj.Mu.RUnlock()
 		testport = fmt.Sprintf(":%v", confObj.Port)
-
-		logToNull()
 	})
 }
 
@@ -47,10 +45,6 @@ func logToNull() {
 	log.SetOutput(hush)
 }
 
-func testTemplates() *template.Template {
-	return template.Must(template.ParseFiles("../assets/tmpl/index.html"))
-}
-
 func testConfig() {
 
 	viper.SetConfigName("getwtxt")
color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Mu - edit.mu</title>
<meta name="Generator" content="Vim/7.4">
<meta name="plugin-version" content="vim7.4_v1">
<meta name="syntax" content="none">
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
<meta name="colorscheme" content="minimal">
<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #eeeeee; background-color: #080808; }
body { font-family: monospace; color: #eeeeee; background-color: #080808; }
* { font-size: 1em; }
.Delimiter { color: #c000c0; }
.Comment { color: #8080ff; }
.Constant { color: #008080; }
.Special { color: #ff6060; }
.CommentedCode { color: #6c6c6c; }
.muControl { color: #804000; }
.muRecipe { color: #ff8700; }
-->
</style>

<script type='text/javascript'>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="muRecipe">recipe</span> main [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  switch-to-display
  width:number<span class="Special"> &lt;- </span>display-width
  <span class="Delimiter">{</span>
    wide-enough?:boolean<span class="Special"> &lt;- </span>greater-than width:number, <span class="Constant">100:literal</span>
    <span class="muControl">break-if</span> wide-enough?:boolean
    return-to-console
    assert wide-enough?:boolean, <span class="Constant">[screen too narrow; we don't support less than 100 characters yet]</span>
  <span class="Delimiter">}</span>
  divider:number, _<span class="Special"> &lt;- </span>divide-with-remainder width:number, <span class="Constant">2:literal</span>
  draw-column <span class="Constant">0:literal/screen</span>, divider:number
  x:address:array:character<span class="Special"> &lt;- </span>new <span class="Constant">[1:integer &lt;- add 2:literal, 2:literal]</span>
  y:address:array:character<span class="Special"> &lt;- </span>edit x:address:array:character, <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal</span>, <span class="Constant">0:literal</span>, <span class="Constant">5:literal</span>, divider:number
<span class="CommentedCode">#?   draw-bounding-box 0:literal/screen, 0:literal, 0:literal, 5:literal, divider:number</span>
  left:number<span class="Special"> &lt;- </span>add divider:number, <span class="Constant">1:literal</span>
  y:address:array:character<span class="Special"> &lt;- </span>edit <span class="Constant">0:literal</span>, <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal</span>, left:number, <span class="Constant">2:literal</span>, width:number
  move-cursor <span class="Constant">0:literal/screen</span>, <span class="Constant">0:literal</span>, <span class="Constant">0:literal</span>
  wait-for-key-from-keyboard
  return-to-console
]

<span class="muRecipe">recipe</span> draw-column [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  col:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  curr:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  max:number<span class="Special"> &lt;- </span>screen-height screen:address
  <span class="Delimiter">{</span>
    continue?:boolean<span class="Special"> &lt;- </span>lesser-than curr:number, max:number
    <span class="muControl">break-unless</span> continue?:boolean
    move-cursor screen:address, curr:number, col:number
    print-character screen:address, <span class="Constant">9474:literal/vertical</span>, <span class="Constant">245:literal/grey</span>
    curr:number<span class="Special"> &lt;- </span>add curr:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  move-cursor screen:address, <span class="Constant">0:literal</span>, <span class="Constant">0:literal</span>
]

<span class="muRecipe">recipe</span> edit [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  in:address:array:character<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  top:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  left:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  bottom:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  right:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># draw bottom boundary</span>
  curr:number<span class="Special"> &lt;- </span>copy left:number
  <span class="Delimiter">{</span>
    continue?:boolean<span class="Special"> &lt;- </span>lesser-than curr:number, right:number
    <span class="muControl">break-unless</span> continue?:boolean
    move-cursor screen:address, bottom:number, curr:number
    print-character screen:address, <span class="Constant">9472:literal/vertical</span>, <span class="Constant">245:literal/grey</span>
    curr:number<span class="Special"> &lt;- </span>add curr:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  move-cursor screen:address, top:number, left:number
]

<span class="muRecipe">recipe</span> draw-bounding-box [
  <span class="Constant">default-space</span>:address:array:location<span class="Special"> &lt;- </span>new location:type, <span class="Constant">30:literal</span>
  screen:address<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Comment"># sanity-check the box bounds</span>
  top:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    out?:boolean<span class="Special"> &lt;- </span>lesser-than top:number, <span class="Constant">0:literal</span>
    <span class="muControl">break-unless</span> out?:boolean
    top:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  <span class="Delimiter">}</span>
  left:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    out?:boolean<span class="Special"> &lt;- </span>lesser-than left:number, <span class="Constant">0:literal</span>
    <span class="muControl">break-unless</span> out?:boolean
    left:number<span class="Special"> &lt;- </span>copy <span class="Constant">0:literal</span>
  <span class="Delimiter">}</span>
  bottom:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    height:number<span class="Special"> &lt;- </span>screen-height screen:address
    out?:boolean<span class="Special"> &lt;- </span>greater-or-equal bottom:number, height:number
    <span class="muControl">break-unless</span> out?:boolean
    bottom:number<span class="Special"> &lt;- </span>subtract height:number, <span class="Constant">1:literal</span>
  <span class="Delimiter">}</span>
  right:number<span class="Special"> &lt;- </span><span class="Constant">next-ingredient</span>
  <span class="Delimiter">{</span>
    width:number<span class="Special"> &lt;- </span>screen-width screen:address
    out?:boolean<span class="Special"> &lt;- </span>greater-or-equal right:number, width:number
    <span class="muControl">break-unless</span> out?:boolean
    right:number<span class="Special"> &lt;- </span>subtract width:number, <span class="Constant">1:literal</span>
  <span class="Delimiter">}</span>
<span class="CommentedCode">#?   print-integer screen:address, bottom:number</span>
<span class="CommentedCode">#?   print-character screen:address, 32:literal/space</span>
<span class="CommentedCode">#?   print-integer screen:address, right:number</span>
  <span class="Comment"># top border</span>
  move-cursor screen:address, top:number, left:number
  print-character screen:address, <span class="Constant">9484:literal/down-right</span>, <span class="Constant">245:literal/grey</span>
  x:number<span class="Special"> &lt;- </span>add left:number, <span class="Constant">1:literal</span>  <span class="Comment"># exclude corner</span>
  <span class="Delimiter">{</span>
    continue?:boolean<span class="Special"> &lt;- </span>lesser-than x:number, right:number
    <span class="muControl">break-unless</span> continue?:boolean
    print-character screen:address, <span class="Constant">9472:literal/horizontal</span>, <span class="Constant">245:literal/grey</span>
    x:number<span class="Special"> &lt;- </span>add x:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  print-character screen:address, <span class="Constant">9488:literal/down-left</span>, <span class="Constant">245:literal/grey</span>
  <span class="Comment"># bottom border</span>
  move-cursor screen:address, bottom:number, left:number
  print-character screen:address, <span class="Constant">9492:literal/up-right</span>, <span class="Constant">245:literal/grey</span>
  x:number<span class="Special"> &lt;- </span>add left:number, <span class="Constant">1:literal</span>  <span class="Comment"># exclude corner</span>
  <span class="Delimiter">{</span>
    continue?:boolean<span class="Special"> &lt;- </span>lesser-than x:number, right:number
    <span class="muControl">break-unless</span> continue?:boolean
    print-character screen:address, <span class="Constant">9472:literal/horizontal</span>, <span class="Constant">245:literal/grey</span>
    x:number<span class="Special"> &lt;- </span>add x:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  print-character screen:address, <span class="Constant">9496:literal/up-left</span>, <span class="Constant">245:literal/grey</span>
  <span class="Comment"># left and right borders</span>
  x:number<span class="Special"> &lt;- </span>add top:number, <span class="Constant">1:literal</span>  <span class="Comment"># exclude corner</span>
  <span class="Delimiter">{</span>
    continue?:boolean<span class="Special"> &lt;- </span>lesser-than x:number, bottom:number
    <span class="muControl">break-unless</span> continue?:boolean
    move-cursor screen:address, x:number, left:number
    print-character screen:address, <span class="Constant">9474:literal/vertical</span>, <span class="Constant">245:literal/grey</span>
    move-cursor screen:address, x:number, right:number
    print-character screen:address, <span class="Constant">9474:literal/vertical</span>, <span class="Constant">245:literal/grey</span>
    x:number<span class="Special"> &lt;- </span>add x:number, <span class="Constant">1:literal</span>
    <span class="muControl">loop</span>
  <span class="Delimiter">}</span>
  <span class="Comment"># position cursor inside box</span>
  move-cursor screen:address, top:number, left:number
  cursor-down screen:address
  cursor-right screen:address
]
</pre>
</body>
</html>
<!-- vim: set foldmethod=manual : -->