-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
67 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package views | ||
|
||
import "time" | ||
|
||
const Track View[TrackData] = "track.html" | ||
|
||
type TrackData struct { | ||
Title string | ||
Artist string | ||
Length time.Duration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="track"> | ||
<div class="track__title">{{ .Title }}</div> | ||
<div class="track__artist">{{ .Artist }}</div> | ||
<div class="track__length">{{ .Length }}</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package views | ||
|
||
import ( | ||
"embed" | ||
"html/template" | ||
"io" | ||
) | ||
|
||
type View[E any] string | ||
|
||
//go:embed *.html | ||
var assets embed.FS | ||
|
||
var tmpls = template.Must(template.ParseFS(assets, "*.html")) | ||
|
||
func (view View[E]) Render(dst io.Writer, args *E) error { | ||
return tmpls.ExecuteTemplate(dst, string(view), args) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package views_test | ||
|
||
import ( | ||
"io" | ||
"testing" | ||
|
||
"github.com/ninedraft/substream/views" | ||
) | ||
|
||
func TestViews(t *testing.T) { | ||
t.Parallel() | ||
t.Log( | ||
"Rendering views should not return an error.", | ||
) | ||
|
||
testView(t, views.Track) | ||
} | ||
|
||
func testView[E any](t *testing.T, view views.View[E]) { | ||
t.Helper() | ||
|
||
t.Run(string(view)+".Render", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
if err := view.Render(io.Discard, new(E)); err != nil { | ||
t.Errorf("render: %v", err) | ||
} | ||
}) | ||
} |