Skip to content

Commit

Permalink
runtime/command/new/controller: Fix links when generating controllers…
Browse files Browse the repository at this point in the history
… and views. Closes: #82
  • Loading branch information
matthewmueller committed May 23, 2022
1 parent cf2a242 commit 63f64db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
26 changes: 14 additions & 12 deletions runtime/command/new/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,13 @@ type Action struct {
}

type View struct {
template string
Path string
Title string
Variable string
Singular string
Plural string
template string
Controller *Controller
Path string
Title string
Variable string
Singular string
Plural string
}

func (c *Command) Run(ctx context.Context) (err error) {
Expand Down Expand Up @@ -160,12 +161,13 @@ func (c *Command) view(controller *Controller, action *Action) *View {
template = defaultView
}
return &View{
template: template,
Path: filepath.Join("view", controller.key, action.Name+".svelte"),
Title: text.Title(controller.Struct),
Variable: text.Camel(action.Result),
Singular: text.Camel(text.Singular(action.Result)),
Plural: text.Camel(text.Plural(action.Result)),
template: template,
Controller: controller,
Path: filepath.Join("view", controller.key, action.Name+".svelte"),
Title: text.Title(controller.Struct),
Variable: text.Camel(action.Result),
Singular: text.Camel(text.Singular(action.Result)),
Plural: text.Camel(text.Plural(action.Result)),
}
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/command/new/controller/view/index.gotext
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
{#each {{ $.Plural }} as {{ $.Singular -}} }
<tr>
{#each Object.keys({{ $.Singular }}) as key}
{#if key === "id"}
<td><a href={`/${ {{- $.Singular }}[key]}`}>{ {{- $.Singular }}[key]}</a></td>
{#if key.toLowerCase() === "id"}
<td><a href={`{{ $.Controller.Route }}/${ {{- $.Singular }}[key]}`}>{ {{- $.Singular }}[key]}</a></td>
{:else}
<td>{ {{- $.Singular }}[key]}</td>
{/if}
Expand Down
2 changes: 1 addition & 1 deletion runtime/command/new/controller/view/show.gotext
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<br />

<a href="..">Back</a>
<a href="{{ $.Controller.Route }}">Back</a>

<style>
table {
Expand Down

0 comments on commit 63f64db

Please sign in to comment.