Skip to content

Commit df3c251

Browse files
Add complete scaffold with routes, controllers, and views
Generated apps now include: - config/routes.cr with home route (GET /) - src/controllers/home_controller.cr - src/views/home/index.slang or index.ecr (based on template choice) - src/views/layouts/application.slang or application.ecr New apps now return 200 on homepage immediately after compile. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 4926ec0 commit df3c251

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

src/amber_cli/commands/new.cr

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ module AmberCLI::Commands
125125
"config", "config/environments", "config/initializers",
126126
"db", "db/migrations", "public", "public/css", "public/js", "public/img",
127127
"spec", "src", "src/controllers", "src/models", "src/views", "src/views/layouts",
128+
"src/views/home",
128129
]
129130

130131
dirs.each do |dir|
@@ -137,6 +138,9 @@ module AmberCLI::Commands
137138
create_amber_yml(path, name)
138139
create_main_file(path, name)
139140
create_config_files(path, name)
141+
create_routes_file(path, name)
142+
create_home_controller(path, name)
143+
create_views(path, name)
140144

141145
info "Created project structure"
142146
end
@@ -245,6 +249,76 @@ module AmberCLI::Commands
245249

246250
File.write(File.join(path, "src/controllers/application_controller.cr"), controller_content)
247251
end
252+
253+
private def create_routes_file(path : String, name : String)
254+
routes_content = <<-ROUTES
255+
Amber::Server.configure do
256+
routes :web do
257+
get "/", HomeController, :index
258+
end
259+
end
260+
ROUTES
261+
262+
File.write(File.join(path, "config/routes.cr"), routes_content)
263+
end
264+
265+
private def create_home_controller(path : String, name : String)
266+
home_controller = <<-CONTROLLER
267+
class HomeController < ApplicationController
268+
def index
269+
render("index.#{template}")
270+
end
271+
end
272+
CONTROLLER
273+
274+
File.write(File.join(path, "src/controllers/home_controller.cr"), home_controller)
275+
end
276+
277+
private def create_views(path : String, name : String)
278+
# Create layout file
279+
if template == "slang"
280+
layout_content = <<-LAYOUT
281+
doctype html
282+
html
283+
head
284+
meta charset="utf-8"
285+
meta name="viewport" content="width=device-width, initial-scale=1"
286+
title #{name}
287+
body
288+
== content
289+
LAYOUT
290+
File.write(File.join(path, "src/views/layouts/application.slang"), layout_content)
291+
292+
# Create home/index view
293+
index_content = <<-VIEW
294+
h1 Welcome to #{name}!
295+
p Your Amber V2 application is running successfully.
296+
VIEW
297+
File.write(File.join(path, "src/views/home/index.slang"), index_content)
298+
else
299+
layout_content = <<-LAYOUT
300+
<!DOCTYPE html>
301+
<html>
302+
<head>
303+
<meta charset="utf-8">
304+
<meta name="viewport" content="width=device-width, initial-scale=1">
305+
<title>#{name}</title>
306+
</head>
307+
<body>
308+
<%= content %>
309+
</body>
310+
</html>
311+
LAYOUT
312+
File.write(File.join(path, "src/views/layouts/application.ecr"), layout_content)
313+
314+
# Create home/index view
315+
index_content = <<-VIEW
316+
<h1>Welcome to #{name}!</h1>
317+
<p>Your Amber V2 application is running successfully.</p>
318+
VIEW
319+
File.write(File.join(path, "src/views/home/index.ecr"), index_content)
320+
end
321+
end
248322
end
249323
end
250324

0 commit comments

Comments
 (0)