Skip to content

Commit

Permalink
Refine CRUD templates
Browse files Browse the repository at this point in the history
  • Loading branch information
zw963 committed Mar 30, 2023
1 parent 376379a commit 65d15ad
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ class <%= pluralized_name %>::EditPage < MainLayout
quick_def page_title, "Edit <%= resource %> with id: #{<%= underscored_resource %>.id}"

def content
link "Back to all <%= pluralized_name %>", <%= pluralized_name %>::Index
link "Back to all <%= pluralized_name %>", Index
h1 "Edit <%= resource %> with id: #{<%= underscored_resource %>.id}"
render_<%= underscored_resource %>_form(operation)
end

def render_<%= underscored_resource %>_form(op)
form_for <%= pluralized_name %>::Update.with(<%= underscored_resource %>.id) do
form_for Update.with(<%= underscored_resource %>.id) do
# Edit fields in src/components/<%= folder_name %>/form_fields.cr
mount <%= pluralized_name %>::FormFields, op
mount FormFields, op

submit "Update", data_disable_with: "Updating..."
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ class <%= pluralized_name %>::IndexPage < MainLayout

def content
h1 "All <%= pluralized_name %>"
link "New <%= resource %>", to: <%= pluralized_name %>::New
link "New <%= resource %>", New
render_<%= pluralized_name.underscore %>
end

def render_<%= pluralized_name.underscore %>
ul do
<%= pluralized_name.underscore %>.each do |<%= underscored_resource %>|
li do
link <%= underscored_resource %>.<%= columns.first.name %>, <%= pluralized_name %>::Show.with(<%= underscored_resource %>)
link <%= underscored_resource %>.<%= columns.first.name %>, Show.with(<%= underscored_resource %>)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ class <%= pluralized_name %>::NewPage < MainLayout
end

def render_<%= underscored_resource %>_form(op)
form_for <%= pluralized_name %>::Create do
form_for Create do
# Edit fields in src/components/<%= folder_name %>/form_fields.cr
mount <%= pluralized_name %>::FormFields, op
mount FormFields, op

submit "Save", data_disable_with: "Saving..."
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ class <%= pluralized_name %>::ShowPage < MainLayout
quick_def page_title, "<%= resource %> with id: #{<%= underscored_resource %>.id}"

def content
link "Back to all <%= pluralized_name %>", <%= pluralized_name %>::Index
link "Back to all <%= pluralized_name %>", Index
h1 "<%= resource %> with id: #{<%= underscored_resource %>.id}"
render_actions
render_<%= underscored_resource %>_fields
end

def render_actions
section do
link "Edit", <%= pluralized_name %>::Edit.with(<%= underscored_resource %>.id)
link "Edit", Edit.with(<%= underscored_resource %>.id)
text " | "
link "Delete",
<%= pluralized_name %>::Delete.with(<%= underscored_resource %>.id),
Delete.with(<%= underscored_resource %>.id),
data_confirm: "Are you sure?"
end
end
Expand Down

0 comments on commit 65d15ad

Please sign in to comment.