Skip to content

Commit

Permalink
Update generated layout to use explicit cased keys (#30)
Browse files Browse the repository at this point in the history
PropsTemplate will no longer camelize(:lower). Instead we must explicitly case
our keys. This commit updates the generated layout to reflect that. The change
on PropsTemplate was backward breaking.

You can use the following to bring back the previous behavior while you upgrade.

```ruby
module PropsTemplateOverride
  def format_key(key)
    @key_cache ||= {}
    @key_cache[key] ||= key.camelize(:lower)
    @key_cache[key]
  end

  def result!
    result = super
    @key_cache = {}
    result
  end

  ::Props::BaseWithExtensions.prepend self
end
```
  • Loading branch information
jho406 authored Nov 26, 2023
1 parent e087e60 commit cbff9d1
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/page-response.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ you can customize this to fit your needs.

```ruby
# application.json.props
json.component_identifier virtual_path_of_template
json.componentIdentifier virtual_path_of_template
```

You can control which `componentIdentifier` will render which component in the
Expand Down
2 changes: 1 addition & 1 deletion superglue/lib/components/Nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Nav extends React.Component {
let reminder = ''
if (!identifier) {
reminder =
'Did you forget to add `json.component_identifier` in your application.json.props layout?'
'Did you forget to add `json.componentIdentifier` in your application.json.props layout?'
}

const error = new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ end
json.form(partial: 'form') do
end

json.<%= singular_table_name%>_path <%= singular_table_name%>_path(@<%=singular_table_name%>)
json.<%= plural_table_name %>_path <%= plural_table_name %>_path
json.<%= singular_table_name.camelize(:lower)%>Path <%= singular_table_name%>_path(@<%=singular_table_name%>)
json.<%= plural_table_name.camelize(:lower) %>Path <%= plural_table_name %>_path
13 changes: 6 additions & 7 deletions superglue_rails/lib/generators/rails/templates/index.json.props
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
json.<%= plural_table_name %> do
json.<%= plural_table_name.camelize(:lower) %> do
json.array! @<%= plural_table_name %> do |<%= singular_table_name %>|
<%- attributes_list_with_timestamps.each do |attr| -%>
json.<%=attr%> <%= singular_table_name %>.<%=attr%>
json.<%=attr%> <%= singular_table_name.camelize(:lower) %>.<%=attr%>
<%- end -%>
json.edit_<%=singular_table_name%>_path edit_<%=singular_table_name%>_path(<%=singular_table_name%>)
json.<%=singular_table_name%>_path <%=singular_table_name%>_path(<%=singular_table_name%>)
json.delete_form do
json.edit<%=singular_table_name.camelize%>Path edit_<%=singular_table_name%>_path(<%=singular_table_name%>)
json.<%=singular_table_name.camelize(:lower)%>Path <%=singular_table_name%>_path(<%=singular_table_name%>)
json.deleteForm do
form_props(model: <%=singular_table_name%>, method: :delete)
end
end
end


json.new_<%= singular_table_name %>_path new_<%= singular_table_name %>_path
json.new<%= singular_table_name.camelize %>Path new_<%= singular_table_name %>_path
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ end
json.form(partial: 'form') do
end

json.<%= plural_table_name %>_path <%= plural_table_name %>_path
json.<%= plural_table_name.camelize(:lower) %>Path <%= plural_table_name %>_path


Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<%- attributes_list_with_timestamps.each do |attr|-%>
json.<%=attr%> @<%= singular_table_name %>.<%=attr%>
json.<%=attr.to_s.camelize(:lower)%> @<%= singular_table_name %>.<%=attr%>
<%- end -%>


json.<%= plural_table_name %>_path <%= plural_table_name %>_path
json.edit_<%= singular_table_name %>_path edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
json.<%= plural_table_name.camelize(:lower) %>Path <%= plural_table_name %>_path
json.edit<%= singular_table_name.camelize %>Path edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ json.data(search: path) do
yield json
end

json.component_identifier virtual_path_of_template
json.componentIdentifier virtual_path_of_template
json.defers json.deferred!
json.fragments json.fragments!
json.assets [ asset_path('application.js') ]

if protect_against_forgery?
json.csrf_token form_authenticity_token
json.csrfToken form_authenticity_token
end

if path
json.action 'graft'
json.path search_path_to_camelized_param(path)
end

json.restore_strategy 'fromCacheAndRevisitInBackground'
json.restoreStrategy 'fromCacheAndRevisitInBackground'

json.rendered_at Time.now.to_i
json.renderedAt Time.now.to_i

json.slices do
json.flash flash.to_h
Expand Down
4 changes: 2 additions & 2 deletions superglue_rails/superglue.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ 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.24.0"
s.add_dependency "form_props", ">= 0.0.3"
s.add_dependency "props_template", ">= 0.30.0"
s.add_dependency "form_props", ">= 0.0.5"

s.add_development_dependency "activerecord", ">= 7.0"
s.add_development_dependency "rake", " ~> 12.0"
Expand Down

0 comments on commit cbff9d1

Please sign in to comment.