diff --git a/docs/_sidebar.md b/docs/_sidebar.md index 4452d1d0..713c579b 100644 --- a/docs/_sidebar.md +++ b/docs/_sidebar.md @@ -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) diff --git a/docs/page-response.md b/docs/page-response.md index 8af0c41d..f4fd9885 100644 --- a/docs/page-response.md +++ b/docs/page-response.md @@ -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 @@ -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 diff --git a/docs/recipes/default-html-template.md b/docs/recipes/default-html-template.md deleted file mode 100644 index f13f8efd..00000000 --- a/docs/recipes/default-html-template.md +++ /dev/null @@ -1,53 +0,0 @@ -# Default HTML template - -Superglue splits a template into 3 parts. - -```treeview -app/ -|-- controllers/ -|-- views/ -| |-- dashboard/ -| | |-- index.js -| | |-- index.json.props -| | |-- index.html.erb -``` - -The majority of logic lives on the `json` and `js`, but the `.erb` file is near -empty. Your project can quickly become littered with `erb` files that add -little to no value. - -To clean this up, you can override Rails' `default_render` method to explicitly -render a shared template. - -```ruby -class ApplicationController < ActionController::Base - def default_render - if request.format.html? - template_does_not_exist = !template_exists?(action_name.to_s, _prefixes, variants: request.variant) - other_templates_exists = any_templates?(action_name.to_s, _prefixes) - - if template_does_not_exist && other_templates_exists - render template: "superglue" - else - super - end - else - super - end - end -end -``` - -In this example, we're placing the template `superglue.html.erb` to the top -level of the `views` path. - -```treeview -app/ -|-- controllers/ -|-- views/ -| |-- superglue.html.erb -| |-- dashboard/ -| | |-- index.js -| | |-- index.json.props -| | |-- index.html.erb -``` diff --git a/docs/tutorial.md b/docs/tutorial.md index f0aeb48c..fdd976c2 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -140,7 +140,7 @@ superglue knows which component to render with which response by modifying #### **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 diff --git a/superglue_rails/lib/generators/rails/templates/web/edit.html.erb b/superglue_rails/lib/generators/rails/templates/web/edit.html.erb index e33f734e..b18638b1 100644 --- a/superglue_rails/lib/generators/rails/templates/web/edit.html.erb +++ b/superglue_rails/lib/generators/rails/templates/web/edit.html.erb @@ -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) %>