Skip to content

Commit

Permalink
misc: enhance views
Browse files Browse the repository at this point in the history
  • Loading branch information
nervo committed May 26, 2024
1 parent 67dfc70 commit cb5bbc0
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions app/views.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ package app
// NewProjectView create a project view
func NewProjectView(project Project) *ProjectView {
return &ProjectView{
Dir: project.Dir(),
Vars: project.Vars(),
Recipe: NewRecipeView(project.Recipe()),
}
}

// ProjectView is a secure and lightweight facade of a project, dedicated to template usage
type ProjectView struct {
Vars map[string]any
Recipe *RecipeView
Dir string `json:"dir"`
Vars map[string]any `json:"vars"`
Recipe *RecipeView `json:"recipe"`
}

/**********/
Expand All @@ -27,25 +29,29 @@ func NewRecipeView(recipe Recipe) *RecipeView {
return &RecipeView{
Name: recipe.Name(),
Description: recipe.Description(),
Icon: recipe.Icon(),
Repository: NewRepositoryView(recipe.Repository()),
}
}

// RecipeView is a secure and lightweight facade of a recipe, dedicated to template usage
type RecipeView struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Icon string `json:"icon,omitempty"`
Repository *RepositoryView `json:"-"`
}

// NewRecipesView create a slice of recipes view
func NewRecipesView(recipes []Recipe) []*RecipeView {
views := make([]*RecipeView, len(recipes))
func NewRecipesView(recipes []Recipe) RecipesView {
views := make(RecipesView, len(recipes))
for i := range recipes {
views[i] = NewRecipeView(recipes[i])
}
return views
}

// RecipeView is a secure and lightweight facade of a recipe, dedicated to template usage
type RecipeView struct {
Name string
Description string
Repository *RepositoryView
}
type RecipesView []*RecipeView

/**************/
/* Repository */
Expand Down

0 comments on commit cb5bbc0

Please sign in to comment.