forked from gnolang/gno
-
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.
refactor(gnoweb): improve layouts and reduce code duplication (gnolan…
…g#3569) This PR aims to improve the HTML composability of gnoweb and avoid DRY issues across templates and layouts. The changes include: - Refactoring HTML components for better reusability. - Reducing code duplication in views. - Removing static data from the layout - Enhancing code maintainability and readability. --------- Signed-off-by: gfanton <[email protected]> Co-authored-by: gfanton <[email protected]>
- Loading branch information
1 parent
400c7cd
commit 6e4a92a
Showing
65 changed files
with
1,171 additions
and
952 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
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
package components | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
type Component interface { | ||
Render(w io.Writer) error | ||
} | ||
|
||
type TemplateComponent struct { | ||
name string | ||
data any | ||
} | ||
|
||
func (c *TemplateComponent) Render(w io.Writer) error { | ||
return tmpl.ExecuteTemplate(w, c.name, c.data) | ||
} | ||
|
||
func NewTemplateComponent(name string, data any) Component { | ||
return &TemplateComponent{name: name, data: data} | ||
} | ||
|
||
type readerComponent struct { | ||
io.Reader | ||
} | ||
|
||
func NewReaderComponent(reader io.Reader) Component { | ||
return &readerComponent{reader} | ||
} | ||
|
||
func (c *readerComponent) Render(w io.Writer) (err error) { | ||
_, err = io.Copy(w, c) | ||
return err | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.