This repository has been archived by the owner on Apr 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
8 changed files
with
106 additions
and
15 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 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package page | ||
|
||
type Component interface { | ||
GetSection() string | ||
// render returns a html template string with the content of the field | ||
Render() string | ||
} |
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 |
---|---|---|
@@ -1,7 +1,47 @@ | ||
package component | ||
|
||
import "github.com/markustenghamn/beubo/pkg/structs/page" | ||
import ( | ||
"bytes" | ||
"fmt" | ||
"github.com/markustenghamn/beubo/pkg/structs/page" | ||
"html/template" | ||
"log" | ||
) | ||
|
||
type Form struct { | ||
Fields []page.Field | ||
Section string | ||
Fields []page.Field | ||
Theme string | ||
Template string | ||
T *template.Template | ||
Method string | ||
Action string | ||
} | ||
|
||
func (f Form) GetSection() string { | ||
return f.Section | ||
} | ||
|
||
func (f Form) Render() string { | ||
tmpl := "component.form" | ||
if f.Template != "" { | ||
tmpl = f.Template | ||
} | ||
theme := "default" | ||
if f.Theme != "" { | ||
theme = f.Theme | ||
} | ||
path := fmt.Sprintf("%s.%s", theme, tmpl) | ||
var foundTemplate *template.Template | ||
if foundTemplate = f.T.Lookup(path); foundTemplate == nil { | ||
log.Printf("Component file not found %s\n", path) | ||
return "" | ||
} | ||
buf := &bytes.Buffer{} | ||
err := foundTemplate.Execute(buf, f) | ||
if err != nil { | ||
log.Printf("Component file error executing template %s\n", path) | ||
return "" | ||
} | ||
return buf.String() | ||
} |
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
Submodule default
updated
from 00a562 to 324d97