Skip to content

Commit 731bbd0

Browse files
committed
- fix hotwire setup
1 parent 5ebd18a commit 731bbd0

File tree

20 files changed

+234
-2
lines changed

20 files changed

+234
-2
lines changed

src/content/tutorial/15-css-and-js/1-propshaft/content.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ section.product img {
7070

7171
Then we'll update `app/views/products/show.html.erb` to use these new styles.
7272

73-
```erb#1,3,6,18-19
73+
```erb {1,3,6,18-19}
7474
<p><%= link_to "Back", products_path %></p>
7575
7676
<section class="product">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../../../../templates/stock-notifications"
3+
}

src/content/tutorial/15-css-and-js/2-importmap/_files/workspace/.keep

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
body {
2+
font-family: Arial, Helvetica, sans-serif;
3+
padding: 1rem;
4+
}
5+
6+
nav {
7+
justify-content: flex-end;
8+
display: flex;
9+
font-size: 0.875em;
10+
gap: 0.5rem;
11+
max-width: 1024px;
12+
margin: 0 auto;
13+
padding: 1rem;
14+
}
15+
16+
nav a {
17+
display: inline-block;
18+
}
19+
20+
main {
21+
max-width: 1024px;
22+
margin: 0 auto;
23+
}
24+
25+
.notice {
26+
color: green;
27+
}
28+
29+
section.product {
30+
display: flex;
31+
gap: 1rem;
32+
flex-direction: row;
33+
}
34+
35+
section.product img {
36+
border-radius: 8px;
37+
flex-basis: 50%;
38+
max-width: 50%;
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<p><%= link_to "Back", products_path %></p>
2+
3+
<section class="product">
4+
<%= image_tag @product.featured_image if @product.featured_image.attached? %>
5+
6+
<section class="product-info">
7+
<% cache @product do %>
8+
<h1><%= @product.name %></h1>
9+
<%= @product.description %>
10+
<% end %>
11+
12+
<%= render "inventory", product: @product %>
13+
14+
<% if authenticated? %>
15+
<%= link_to "Edit", edit_product_path(@product) %>
16+
<%= button_to "Delete", @product, method: :delete, data: { turbo_confirm: "Are you sure?" } %>
17+
<% end %>
18+
</section>
19+
</section>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
type: lesson
3+
title: Import Maps
4+
focus: /workspace/store/config/importmap.rb
5+
previews:
6+
- 3000
7+
custom:
8+
shell:
9+
workdir: "/workspace/store"
10+
---
11+
12+
### Import Maps
13+
14+
Rails uses import maps for JavaScript by default. This allows you to write
15+
modern JavaScript modules with no build steps.
16+
17+
You can find the JavaScript pins in `config/importmap.rb`. This file maps the
18+
JavaScript package names with the source file which is used to generate the
19+
importmap tag in the browser.
20+
21+
```ruby
22+
# Pin npm packages by running ./bin/importmap
23+
24+
pin "application"
25+
pin "@hotwired/turbo-rails", to: "turbo.min.js"
26+
pin "@hotwired/stimulus", to: "stimulus.min.js"
27+
pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"
28+
pin_all_from "app/javascript/controllers", under: "controllers"
29+
pin "trix"
30+
pin "@rails/actiontext", to: "actiontext.esm.js"
31+
```
32+
33+
:::tip
34+
Each pin maps a JavaScript package name (e.g., `"@hotwired/turbo-rails"`)
35+
to a specific file or URL (e.g., `"turbo.min.js"`). `pin_all_from` maps all
36+
files in a directory (e.g., `app/javascript/controllers`) to a namespace (e.g.,
37+
`"controllers"`).
38+
:::
39+
40+
Import maps keep the setup clean and minimal, while still supporting modern
41+
JavaScript features.
42+
43+
What are these JavaScript files already in our import map? They are a frontend
44+
framework called Hotwire that Rails uses by default.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../../../../templates/stock-notifications"
3+
}

src/content/tutorial/15-css-and-js/3-hotwire/_files/workspace/.keep

Whitespace-only changes.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
body {
2+
font-family: Arial, Helvetica, sans-serif;
3+
padding: 1rem;
4+
}
5+
6+
nav {
7+
justify-content: flex-end;
8+
display: flex;
9+
font-size: 0.875em;
10+
gap: 0.5rem;
11+
max-width: 1024px;
12+
margin: 0 auto;
13+
padding: 1rem;
14+
}
15+
16+
nav a {
17+
display: inline-block;
18+
}
19+
20+
main {
21+
max-width: 1024px;
22+
margin: 0 auto;
23+
}
24+
25+
.notice {
26+
color: green;
27+
}
28+
29+
section.product {
30+
display: flex;
31+
gap: 1rem;
32+
flex-direction: row;
33+
}
34+
35+
section.product img {
36+
border-radius: 8px;
37+
flex-basis: 50%;
38+
max-width: 50%;
39+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<p><%= link_to "Back", products_path %></p>
2+
3+
<section class="product">
4+
<%= image_tag @product.featured_image if @product.featured_image.attached? %>
5+
6+
<section class="product-info">
7+
<% cache @product do %>
8+
<h1><%= @product.name %></h1>
9+
<%= @product.description %>
10+
<% end %>
11+
12+
<%= render "inventory", product: @product %>
13+
14+
<% if authenticated? %>
15+
<%= link_to "Edit", edit_product_path(@product) %>
16+
<%= button_to "Delete", @product, method: :delete, data: { turbo_confirm: "Are you sure?" } %>
17+
<% end %>
18+
</section>
19+
</section>

0 commit comments

Comments
 (0)