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
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
rice-box.go binary
2 changes: 1 addition & 1 deletion fileserver/fileserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func localRedirect(w http.ResponseWriter, r *http.Request, newPath string) {
// To use the operating system's file system implementation,
// use http.Dir:
//
// http.Handle("/", &fileserver.FileServer{Root: http.Dir("/tmp")})
// http.Handle("/", &fileserver.FileServer{Root: http.Dir("/tmp")})
type FileServer struct {
Version string
Root http.FileSystem
Expand Down
20 changes: 10 additions & 10 deletions fileserver/fileserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"testing"
"time"

rice "github.com/GeertJohan/go.rice"
"github.com/cortesi/devd/fstmpl"
"github.com/cortesi/devd/inject"
"github.com/cortesi/devd/ricetemp"
"github.com/cortesi/devd/routespec"
"github.com/cortesi/devd/templates"
"github.com/cortesi/termlog"
)

Expand All @@ -40,7 +40,7 @@ func ServeFile(w http.ResponseWriter, r *http.Request, name string) {
"version",
http.Dir(dir),
inject.CopyInject{},
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
fstmpl.MustMakeTemplates(templates.FS),
[]routespec.RouteSpec{},
"",
}
Expand Down Expand Up @@ -168,7 +168,7 @@ func TestFSRedirect(t *testing.T) {
"version",
http.Dir("."),
inject.CopyInject{},
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
fstmpl.MustMakeTemplates(templates.FS),
[]routespec.RouteSpec{},
"",
},
Expand Down Expand Up @@ -208,7 +208,7 @@ func _TestFileServerCleans(t *testing.T) {
},
},
inject.CopyInject{},
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
fstmpl.MustMakeTemplates(templates.FS),
[]routespec.RouteSpec{},
"",
}
Expand Down Expand Up @@ -250,7 +250,7 @@ func TestFileServerImplicitLeadingSlash(t *testing.T) {
"version",
http.Dir(tempDir),
inject.CopyInject{},
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
fstmpl.MustMakeTemplates(templates.FS),
[]routespec.RouteSpec{},
"",
}
Expand Down Expand Up @@ -415,7 +415,7 @@ func TestServeIndexHtml(t *testing.T) {
"version",
http.Dir("."),
inject.CopyInject{},
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
fstmpl.MustMakeTemplates(templates.FS),
[]routespec.RouteSpec{},
"",
}
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestFileServerZeroByte(t *testing.T) {
"version",
http.Dir("."),
inject.CopyInject{},
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
fstmpl.MustMakeTemplates(templates.FS),
[]routespec.RouteSpec{},
"",
}
Expand Down Expand Up @@ -539,7 +539,7 @@ func TestNotFoundOverride(t *testing.T) {
"version",
fsys,
inject.CopyInject{},
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
fstmpl.MustMakeTemplates(templates.FS),
[]routespec.RouteSpec{
{Host: "", Path: "/", Value: "foo.html"},
},
Expand Down Expand Up @@ -611,7 +611,7 @@ func TestDirectoryIfNotModified(t *testing.T) {
"version",
fsys,
inject.CopyInject{},
ricetemp.MustMakeTemplates(rice.MustFindBox("../templates")),
fstmpl.MustMakeTemplates(templates.FS),
[]routespec.RouteSpec{},
"",
}
Expand Down
37 changes: 22 additions & 15 deletions ricetemp/ricetemp.go → fstmpl/fstmpl.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Package ricetemp makes templates from a ricebox.
package ricetemp
// Package fstmpl makes templates from a fs.FS
package fstmpl

import (
"html/template"
"io"
"io/fs"
"os"
"strings"

"github.com/GeertJohan/go.rice"
"github.com/dustin/go-humanize"
)

Expand All @@ -25,16 +26,16 @@ func fileType(f os.FileInfo) string {
}

// MustMakeTemplates makes templates, and panic on error
func MustMakeTemplates(rb *rice.Box) *template.Template {
templates, err := MakeTemplates(rb)
func MustMakeTemplates(fs fs.ReadDirFS) *template.Template {
templates, err := MakeTemplates(fs)
if err != nil {
panic(err)
}
return templates
}

// MakeTemplates takes a rice.Box and returns a html.Template
func MakeTemplates(rb *rice.Box) (*template.Template, error) {
// MakeTemplates takes a fs.ReadDirFS and returns a html.Template
func MakeTemplates(fs fs.ReadDirFS) (*template.Template, error) {
tmpl := template.New("")

funcMap := template.FuncMap{
Expand All @@ -44,14 +45,20 @@ func MakeTemplates(rb *rice.Box) (*template.Template, error) {
}
tmpl.Funcs(funcMap)

err := rb.Walk("", func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
_, err := tmpl.New(path).Parse(rb.MustString(path))
if err != nil {
return err
}
ds, err := fs.ReadDir(".")
if err != nil {
return nil, err
}

for _, d := range ds {
f, _ := fs.Open(d.Name())
fbs, _ := io.ReadAll(f)

_, err := tmpl.New(d.Name()).Parse(string(fbs))
if err != nil {
return nil, err
}
return nil
})
}

return tmpl, err
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/cortesi/devd
go 1.25.0

require (
github.com/GeertJohan/go.rice v1.0.3
github.com/cortesi/moddwatch v0.1.0
github.com/cortesi/termlog v0.0.0-20250523085554-f86697764bb0
github.com/dustin/go-humanize v1.0.1
Expand All @@ -21,7 +20,7 @@ require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/daaku/go.zipexe v1.0.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
Expand Down
10 changes: 0 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
github.com/GeertJohan/go.incremental v1.0.0/go.mod h1:6fAjUhbVuX1KcMD3c8TEgVUqmo4seqhv0i0kdATSkM0=
github.com/GeertJohan/go.rice v1.0.3 h1:k5viR+xGtIhF61125vCE1cmJ5957RQGXG6dmbaWZSmI=
github.com/GeertJohan/go.rice v1.0.3/go.mod h1:XVdrU4pW00M4ikZed5q56tPf1v2KwnIKeIdc9CBYNt4=
github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafoB+tBA3gMyHYHrpOtNuDiK/uB5uXxq5wM=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
Expand All @@ -13,8 +9,6 @@ github.com/cortesi/moddwatch v0.1.0/go.mod h1:PFkhcmmwsRMQ76IMjKbaIIMcGQt7BSMtFO
github.com/cortesi/termlog v0.0.0-20250523085554-f86697764bb0 h1:i6kD96U0+1ht4pxADqe3Vz+P44SN8TeBS4A5bPidu90=
github.com/cortesi/termlog v0.0.0-20250523085554-f86697764bb0/go.mod h1:GjgJh2CGR2AEiiH4po295B0ZEKRrt+0P1mlLrGwos+w=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/daaku/go.zipexe v1.0.2 h1:Zg55YLYTr7M9wjKn8SY/WcpuuEi+kR2u4E8RhvpyXmk=
github.com/daaku/go.zipexe v1.0.2/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -29,7 +23,6 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/juju/ratelimit v1.0.2 h1:sRxmtRiajbvrcLQT7S+JbqU0ntsb9W2yhSdNN8tWfaI=
github.com/juju/ratelimit v1.0.2/go.mod h1:qapgC/Gy+xNh9UxzV13HGGl/6UXNN+ct+vwSgWNm/qk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -44,7 +37,6 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/nkovacs/streamquote v1.0.0/go.mod h1:BN+NaZ2CmdKqUuTUXUEm9j95B2TRbpOWpxbJYzzgUsc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZeY=
Expand All @@ -55,8 +47,6 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/toqueteos/webbrowser v1.2.0 h1:tVP/gpK69Fx+qMJKsLE7TD8LuGWPnEV71wBN9rrstGQ=
github.com/toqueteos/webbrowser v1.2.0/go.mod h1:XWoZq4cyp9WeUeak7w7LXRUQf1F1ATJMir8RTqb4ayM=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0=
golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw=
golang.org/x/sys v0.0.0-20180926160741-c2ed4eda69e7/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down
File renamed without changes.
File renamed without changes.
11 changes: 8 additions & 3 deletions livereload/livereload.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@
package livereload

import (
_ "embed"
"net/http"
"regexp"
"strings"
"sync"

"github.com/GeertJohan/go.rice"
"github.com/cortesi/devd/inject"
"github.com/cortesi/termlog"
"github.com/gorilla/websocket"
)

//go:embed client.js
var clientJS []byte

//go:embed LICENSE
var license []byte

// Reloader triggers a reload
type Reloader interface {
Reload(paths []string)
Expand Down Expand Up @@ -130,8 +136,7 @@ func (s *Server) Watch(ch chan []string) {
// ServeScript is a handler function that serves the livereload JavaScript file
func (s *Server) ServeScript(rw http.ResponseWriter, req *http.Request) {
rw.Header().Set("Content-Type", "application/javascript")
clientBox := rice.MustFindBox("static")
_, err := rw.Write(clientBox.MustBytes("client.js"))
_, err := rw.Write(clientJS)
if err != nil {
s.logger.Warn("Error serving livereload script: %s", err)
}
Expand Down
Loading