summary refs log tree commit diff stats
path: root/svc/cache.go
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-06-09 04:00:21 -0400
committerBen Morrison <ben@gbmor.dev>2019-06-09 04:00:21 -0400
commit7410b8cd74d0f702b087577b1793bcf541ac8371 (patch)
treedbc1aa568abc43fd7048d0587eecbb2a4d950cbb /svc/cache.go
parent7f76158b9565d804ada682c1a9aa83c22cb8de71 (diff)
downloadgetwtxt-7410b8cd74d0f702b087577b1793bcf541ac8371.tar.gz
init staticAssets explicitly on startup
Diffstat (limited to 'svc/cache.go')
-rw-r--r--svc/cache.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/svc/cache.go b/svc/cache.go
index 0963892..e2078d7 100644
--- a/svc/cache.go
+++ b/svc/cache.go
@@ -2,6 +2,7 @@ package svc // import "github.com/getwtxt/getwtxt/svc"
 
 import (
 	"bytes"
+	"html/template"
 	"io/ioutil"
 	"os"
 	"sync"
@@ -24,6 +25,41 @@ type staticAssets struct {
 	cssMod   time.Time
 }
 
+func initTemplates() *template.Template {
+	confObj.Mu.RLock()
+	assetsDir := confObj.AssetsDir
+	confObj.Mu.RUnlock()
+
+	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
s='oid'>a66c4a26 ^
f027adc0 ^
b289f679 ^

5c210a96 ^

3de15ddd ^

fb275079 ^

5c210a96 ^
3d566884 ^
e30d16cb ^
621a1a39 ^
c44b726e ^
465bff73 ^




f8e96a97 ^
b289f679 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
                    
              
 

                                                                 
 











                                                                       
 

                                                                              

                                                                 
     
               
                                                                               


                                                                

        
 

          

                                                                

                                                           

                                                              
                              
    
                                        
                   
                                                              




                                                               
     
                        
#!/usr/bin/python -O
# coding=utf-8
#
# Ranger: Explore your forest of files from inside your terminal
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# ----------------------------------------------------------------------------
#
# An embedded shell script. It allows you to change the directory
# after you exit ranger by starting it with: source ranger ranger
"""":
if [ $1 ]; then
	$@ --fail-unless-cd && cd "$(grep \^\' ~/.ranger/bookmarks | cut -b3-)"
else
	echo "usage: source path/to/ranger.py path/to/ranger.py"
fi
return 1
"""

import sys

# Redefine the docstring, since the previous one was hijacked to
# embed a shellscript.
__doc__ = """Ranger - file browser for the unix terminal"""

# Importing the main method may fail if the ranger directory
# is neither in the same directory as this file, nor in one of
# pythons global import paths.
try:
	from ranger.__main__ import main
except ImportError:
	if '-d' not in sys.argv and '--debug' not in sys.argv:
		print("Can't import the main module.")
		print("To run an uninstalled copy of ranger,")
		print("launch ranger.py in the top directory.")
	else:
		raise
else:
	sys.exit(main())