Skip to content

Commit

Permalink
Use form_props active_template_virtual_path (#39)
Browse files Browse the repository at this point in the history
This reverts an earlier removal of of the method `virtual_path_of_template`.
Unfortunately, a combination of `controller_path` and `action_name` caused
some unintended consequences of some actions rendering the wrong template.

Using `controller_path` and `action_name` would've been a nice way to DRY
things up, but we're going to revert for now until we find a better method.
  • Loading branch information
jho406 authored Dec 10, 2023
1 parent 39b8e44 commit 857fb88
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 64 deletions.
1 change: 0 additions & 1 deletion docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

- Recipes
- [Modals](recipes/modals.md)
- [Default HTML template](recipes/default-html-template.md)
- [Server-Side Rendering](recipes/server-side-rendering.md)
- [Loading content later](recipes/load-content-later.md)
- [Loading a tab onClick](recipes/load-tab-onclick.md)
Expand Down
8 changes: 5 additions & 3 deletions docs/page-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ merged when [navigating](./react-redux.md#navigateto)

### `componentIdentifier`
A `string` to instruct Superglue which component to render. The generated
`application.json.props` will set this to the `controller_path` and
`action_name`, but you can customize this to fit your needs.
`application.json.props` will set this to the `active_template_virtual_path`
(added by [props_template]), but you can customize this to fit your needs.

```ruby
# application.json.props
json.componentIdentifier "#{controller_path}/#{action_name}"
json.componentIdentifier active_template_virtual_path
```

You can control which `componentIdentifier` will render which component in the
Expand Down Expand Up @@ -100,3 +100,5 @@ An object merged with the `initialState` when implementing `buildStore` inside
of `application.js`. You can use this as the initial state for redux slices.
Take advantage of the `SAVE_RESPONSE` to continually update your slice everytime
superglue recieves a new page request.

[props_template]: https://github.com/thoughtbot/props_template
53 changes: 0 additions & 53 deletions docs/recipes/default-html-template.md

This file was deleted.

2 changes: 1 addition & 1 deletion docs/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ superglue knows which component to render with which response by modifying
<!-- tabs:start -->
#### **Example greet.json**
The layout for `show.json.props` is located at `app/views/layouts/application.json.props`. It
conforms to superglue's [payload] response, and uses the `controller_path` and `action` as the
conforms to superglue's [payload] response, and uses the `active_template_virtual_path` as the
`componentIdentifier`.

```json
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%% initial_state = controller.render_to_string(formats: [:json], locals: local_assigns, layout: true) %>
<%% initial_state = controller.render_to_string(active_template_virtual_path, formats: [:json], locals: local_assigns, layout: true) %>

<script type="text/javascript">
window.SUPERGLUE_INITIAL_PAGE_STATE=<%%= initial_state.html_safe %>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%% initial_state = controller.render_to_string(formats: [:json], locals: local_assigns, layout: true) %>
<%% initial_state = controller.render_to_string(active_template_virtual_path, formats: [:json], locals: local_assigns, layout: true) %>

<script type="text/javascript">
window.SUPERGLUE_INITIAL_PAGE_STATE=<%%= initial_state.html_safe %>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%% initial_state = controller.render_to_string(formats: [:json], locals: local_assigns, layout: true) %>
<%% initial_state = controller.render_to_string(active_template_virtual_path, formats: [:json], locals: local_assigns, layout: true) %>

<script type="text/javascript">
window.SUPERGLUE_INITIAL_PAGE_STATE=<%%= initial_state.html_safe %>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%% initial_state = controller.render_to_string(formats: [:json], locals: local_assigns, layout: true) %>
<%% initial_state = controller.render_to_string(active_template_virtual_path, formats: [:json], locals: local_assigns, layout: true) %>

<script type="text/javascript">
window.SUPERGLUE_INITIAL_PAGE_STATE=<%%= initial_state.html_safe %>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ json.data(search: path) do
yield json
end

json.componentIdentifier "#{controller_path}/#{action_name}"
json.componentIdentifier active_template_virtual_path
json.defers json.deferred!
json.fragments json.fragments!
json.assets [ asset_path('application.js') ]
Expand Down
2 changes: 1 addition & 1 deletion superglue_rails/superglue.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |s|
s.files = Dir["MIT-LICENSE", "README.md", "lib/**/*", "app/**/*"]

s.add_dependency "actionpack", ">= 7.0.0"
s.add_dependency "props_template", ">= 0.31.0"
s.add_dependency "props_template", ">= 0.32.0"
s.add_dependency "form_props", ">= 0.0.5"

s.add_development_dependency "activerecord", ">= 7.0"
Expand Down

0 comments on commit 857fb88

Please sign in to comment.