diff --git a/superglue_rails/lib/generators/superglue/view_collection/templates/js/edit.js b/superglue_rails/lib/generators/superglue/view_collection/templates/js/edit.js index 996269ad..f7a35eb2 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/templates/js/edit.js +++ b/superglue_rails/lib/generators/superglue/view_collection/templates/js/edit.js @@ -1,13 +1,13 @@ import React from 'react' // import { useSelector } from 'react-redux' -export default function <%= plural_table_name.camelize %>Edit ({ +export default function <%= js_plural_table_name(:upper) %>Edit ({ // visit, // remote, form, errors, - <%= singular_table_name.camelize(:lower) %>Path, - <%= plural_table_name.camelize(:lower) %>Path, + <%= js_singular_table_name %>Path, + <%= js_plural_table_name %>Path, }) { const messagesEl = errors && (
@@ -28,8 +28,8 @@ export default function <%= plural_table_name.camelize %>Edit ({ - Path} data-sg-visit>Show - Path} data-sg-visit>Back + Path} data-sg-visit>Show + Path} data-sg-visit>Back
) } diff --git a/superglue_rails/lib/generators/superglue/view_collection/templates/js/index.js b/superglue_rails/lib/generators/superglue/view_collection/templates/js/index.js index 1d61bdce..fd6ca678 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/templates/js/index.js +++ b/superglue_rails/lib/generators/superglue/view_collection/templates/js/index.js @@ -1,24 +1,24 @@ import React from 'react' import { useSelector } from 'react-redux' -export default function <%= plural_table_name.camelize %>Index({ +export default function <%= js_plural_table_name(:upper) %>Index({ // visit, // remote, - new<%= singular_table_name.camelize %>Path, - <%= plural_table_name.camelize(:lower) %> = [], + new<%= js_singular_table_name(:upper) %>Path, + <%= js_plural_table_name %> = [], }) { const flash = useSelector((state) => state.flash) - const <%= singular_table_name.camelize(:lower) %>Items = <%= plural_table_name.camelize(:lower) %>.map((<%= singular_table_name.camelize(:lower) %>, key) => { - const deleteForm = <%=singular_table_name.camelize(:lower)%>.deleteForm; + const <%= js_singular_table_name %>Items = <%= js_plural_table_name %>.map((<%= js_singular_table_name %>, key) => { + const deleteForm = <%=js_singular_table_name%>.deleteForm; return ( - .id}> + .id}> <%- attributes_list.select{|attr| attr != :id }.each do |attr| -%> - {<%=singular_table_name.camelize(:lower)%>.<%=attr.camelize(:lower)%>} + {<%=js_singular_table_name%>.<%=attr.camelize(:lower)%>} <%- end -%> - .<%=singular_table_name.camelize(:lower)%>Path } data-sg-visit>Show - .edit<%=singular_table_name.camelize%>Path } data-sg-visit>Edit + .<%=js_singular_table_name%>Path } data-sg-visit>Show + .edit<%=js_singular_table_name(:upper)%>Path } data-sg-visit>Edit
{Object.values(deleteForm.extras).map((hiddenProps) => ())} @@ -33,7 +33,7 @@ export default function <%= plural_table_name.camelize %>Index({

{flash && flash.notice}

-

<%= plural_table_name.capitalize %>

+

<%= js_plural_table_name(:upper) %>

@@ -50,7 +50,7 @@ export default function <%= plural_table_name.camelize %>Index({

- Path} data-sg-visit>New <%= singular_table_name.capitalize %> + Path} data-sg-visit>New <%= js_singular_table_name(:upper) %>
) } diff --git a/superglue_rails/lib/generators/superglue/view_collection/templates/js/new.js b/superglue_rails/lib/generators/superglue/view_collection/templates/js/new.js index 7926c47f..6444778b 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/templates/js/new.js +++ b/superglue_rails/lib/generators/superglue/view_collection/templates/js/new.js @@ -1,12 +1,12 @@ import React from 'react' // import { useSelector } from 'react-redux' -export default function <%= plural_table_name.camelize %>New({ +export default function <%= js_plural_table_name(:upper) %>New({ // visit, // remote form, errors, - <%= plural_table_name.camelize(:lower) %>Path, + <%= js_plural_table_name %>Path, }) { const messagesEl = errors && (
@@ -27,7 +27,7 @@ export default function <%= plural_table_name.camelize %>New({ - Path} data-sg-visit>Back + Path} data-sg-visit>Back
) } diff --git a/superglue_rails/lib/generators/superglue/view_collection/templates/js/show.js b/superglue_rails/lib/generators/superglue/view_collection/templates/js/show.js index a21b0da0..408f7d3c 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/templates/js/show.js +++ b/superglue_rails/lib/generators/superglue/view_collection/templates/js/show.js @@ -1,14 +1,14 @@ import React from 'react' import { useSelector } from 'react-redux' -export default function <%= plural_table_name.camelize %>Show({ +export default function <%= js_plural_table_name(:upper) %>Show({ // visit, // remote, <%- attributes_list_with_timestamps.select{|attr| attr != :id }.each do |attr| -%> <%=attr.camelize(:lower)%>, <%- end -%> - edit<%= singular_table_name.camelize %>Path, - <%= plural_table_name.camelize(:lower) %>Path + edit<%= js_singular_table_name(:upper) %>Path, + <%= js_plural_table_name %>Path }) { const flash = useSelector((state) => state.flash) @@ -21,8 +21,8 @@ export default function <%= plural_table_name.camelize %>Show({ {<%=attr.camelize(:lower)%>}

<%- end -%> - Path } data-sg-visit>Edit - Path } data-sg-visit>Back + Path } data-sg-visit>Edit + Path } data-sg-visit>Back ) } diff --git a/superglue_rails/lib/generators/superglue/view_collection/templates/props/edit.json.props b/superglue_rails/lib/generators/superglue/view_collection/templates/props/edit.json.props index f0bbe722..3299fd91 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/templates/props/edit.json.props +++ b/superglue_rails/lib/generators/superglue/view_collection/templates/props/edit.json.props @@ -8,5 +8,5 @@ end json.form(partial: 'form') do end -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 +json.<%= js_singular_table_name%>Path <%= singular_table_name%>_path(@<%=singular_table_name%>) +json.<%= js_plural_table_name %>Path <%= plural_table_name %>_path diff --git a/superglue_rails/lib/generators/superglue/view_collection/templates/props/index.json.props b/superglue_rails/lib/generators/superglue/view_collection/templates/props/index.json.props index 3e7f4577..d9c79740 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/templates/props/index.json.props +++ b/superglue_rails/lib/generators/superglue/view_collection/templates/props/index.json.props @@ -1,14 +1,14 @@ -json.<%= plural_table_name.camelize(:lower) %> do +json.<%= js_plural_table_name %> do json.array! @<%= plural_table_name %> do |<%= singular_table_name %>| <%- attributes_list_with_timestamps.each do |attr| -%> - json.<%=attr%> <%= singular_table_name.camelize(:lower) %>.<%=attr%> + json.<%=attr%> <%= js_singular_table_name %>.<%=attr%> <%- end -%> - 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.edit<%=js_singular_table_name(:upper)%>Path edit_<%=singular_table_name%>_path(<%=singular_table_name%>) + json.<%=js_singular_table_name%>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.camelize %>Path new_<%= singular_table_name %>_path +json.new<%= js_singular_table_name(:upper) %>Path new_<%= singular_table_name %>_path diff --git a/superglue_rails/lib/generators/superglue/view_collection/templates/props/new.json.props b/superglue_rails/lib/generators/superglue/view_collection/templates/props/new.json.props index bd2326a0..eadb3c32 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/templates/props/new.json.props +++ b/superglue_rails/lib/generators/superglue/view_collection/templates/props/new.json.props @@ -8,6 +8,6 @@ end json.form(partial: 'form') do end -json.<%= plural_table_name.camelize(:lower) %>Path <%= plural_table_name %>_path +json.<%= js_plural_table_name %>Path <%= plural_table_name %>_path diff --git a/superglue_rails/lib/generators/superglue/view_collection/templates/props/show.json.props b/superglue_rails/lib/generators/superglue/view_collection/templates/props/show.json.props index 727f657f..2e23fb42 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/templates/props/show.json.props +++ b/superglue_rails/lib/generators/superglue/view_collection/templates/props/show.json.props @@ -2,5 +2,5 @@ json.<%=attr.to_s.camelize(:lower)%> @<%= singular_table_name %>.<%=attr%> <%- end -%> -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 %>) +json.<%= js_plural_table_name %>Path <%= plural_table_name %>_path +json.edit<%= js_singular_table_name(:upper) %>Path edit_<%= singular_table_name %>_path(@<%= singular_table_name %>) diff --git a/superglue_rails/lib/generators/superglue/view_collection/view_collection_generator.rb b/superglue_rails/lib/generators/superglue/view_collection/view_collection_generator.rb index b948d59f..2190f8f0 100644 --- a/superglue_rails/lib/generators/superglue/view_collection/view_collection_generator.rb +++ b/superglue_rails/lib/generators/superglue/view_collection/view_collection_generator.rb @@ -61,6 +61,14 @@ def append_mapping protected + def js_singular_table_name(casing = :lower) + singular_table_name.camelize(casing) + end + + def js_plural_table_name(casing = :lower) + plural_table_name.camelize(casing) + end + def available_views %w(index edit show new) end