Skip to content

Commit

Permalink
Merge pull request #629 from neanias/patch-1
Browse files Browse the repository at this point in the history
Use dig in layouts guide ERB
  • Loading branch information
allmarkedup authored Jul 11, 2024
2 parents cdcbbae + 56f35dd commit d35a96c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/src/_extend/other/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ title: Global Data Store
<!-- app/views/layouts/preview.html.erb -->
...
<div><%%= yield %></div>
<p>Built by <%%= params[:lookbook][:data][:company_name] %></p>
<p>Built by <%%= params.dig(:lookbook, :data, :company_name) %></p>
...
```

Expand All @@ -77,4 +77,4 @@ title: Global Data Store
<%% end %>
</ul>
```
<% end %>
<% end %>
12 changes: 6 additions & 6 deletions docs/src/_guide/previews/display.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ title: Display Options
end
```

Display param values can then be accessed via the `params` hash in your preview layout using `params[:lookbook][:display][<key>]`:
Display param values can then be accessed via the `params` hash in your preview layout using `params.dig(:lookbook, :display, <key>)`:

```html
<!DOCTYPE html>
<html style="background-color: <%%= params[:lookbook][:display][:bg_color] %>">
<html style="background-color: <%%= params.dig(:lookbook, :display, :bg_color) %>">
<head>
<title>Preview Layout</title>
</head>
<body>
<div style="max-width: <%%= params[:lookbook][:display][:max_width] || '100%' %>">
<%% if params[:lookbook][:display][:wrapper] == true %>
<div style="max-width: <%%= params.dig(:lookbook, :display, :max_width) || '100%' %>">
<%% if params.dig(:lookbook, :display, :wrapper) == true %>
<div class="wrapper"><%%= yield %></div>
<%% else %> <%%= yield %> <%% end %>
</div>
Expand Down Expand Up @@ -136,7 +136,7 @@ title: Display Options
<!DOCTYPE html>
<html>
<head>
<link href="<%%= params[:lookbook][:display][:theme] %>.css" rel="stylesheet" />
<link href="<%%= params.dig(:lookbook, :display, :theme) %>.css" rel="stylesheet" />
</head>
<body>
<%%= yield %>
Expand All @@ -163,4 +163,4 @@ title: Display Options

Overridden values like these **are not persisted** across other previews.
<% end %>
<% end %>
<% end %>
6 changes: 3 additions & 3 deletions docs/src/_guide/previews/layouts.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ title: Preview Layouts
```erb
<!-- app/views/layouts/component_preview.html.erb -->
<!DOCTYPE html>
<html style="background-color: <%%= params[:lookbook][:display][:bg_color] || "white" %>">
<html style="background-color: <%%= params.dig(:lookbook, :display, :bg_color) || "white" %>">
<head>
<title>Component Preview</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
Expand All @@ -67,7 +67,7 @@ title: Preview Layouts
<div style="
margin-left: auto;
margin-right: auto;
max-width: <%%= params[:lookbook][:display][:max_width] || "100%" %>
max-width: <%%= params.dig(:lookbook, :display, :max_width) || "100%" %>
">
<%%= yield %> <!-- rendered preview will be injected here -->
</div>
Expand All @@ -86,4 +86,4 @@ title: Preview Layouts

<% s.with_block_api_module_methods(:preview_helper) %>

<% end %>
<% end %>

0 comments on commit d35a96c

Please sign in to comment.