superglue 0.54.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/generators/superglue/install/install_generator.rb +119 -0
  3. data/lib/{install/templates/web → generators/superglue/install/templates}/application.json.props +2 -2
  4. data/lib/generators/superglue/install/templates/js/application.jsx +35 -0
  5. data/lib/generators/superglue/install/templates/js/application_visit.js +113 -0
  6. data/lib/generators/superglue/install/templates/js/components.js +2 -0
  7. data/lib/generators/superglue/install/templates/js/flash.js +44 -0
  8. data/lib/generators/superglue/install/templates/js/inputs.jsx +302 -0
  9. data/lib/generators/superglue/install/templates/js/jsconfig.json +9 -0
  10. data/lib/generators/superglue/install/templates/js/layout.jsx +16 -0
  11. data/lib/generators/superglue/install/templates/js/page_to_page_mapping.js +35 -0
  12. data/lib/generators/superglue/install/templates/js/store.js +30 -0
  13. data/lib/{install/templates/web/application.js → generators/superglue/install/templates/ts/application.tsx} +10 -16
  14. data/lib/generators/superglue/install/templates/ts/application_visit.ts +122 -0
  15. data/lib/generators/superglue/install/templates/ts/components.ts +2 -0
  16. data/lib/generators/superglue/install/templates/ts/flash.ts +46 -0
  17. data/lib/generators/superglue/install/templates/ts/inputs.tsx +547 -0
  18. data/lib/generators/superglue/install/templates/ts/layout.tsx +16 -0
  19. data/lib/generators/superglue/install/templates/ts/page_to_page_mapping.ts +34 -0
  20. data/lib/generators/superglue/install/templates/ts/store.ts +34 -0
  21. data/lib/generators/superglue/install/templates/ts/tsconfig.json +27 -0
  22. data/lib/generators/superglue/scaffold/scaffold_generator.rb +16 -0
  23. data/lib/generators/superglue/scaffold_controller/scaffold_controller_generator.rb +61 -0
  24. data/lib/generators/superglue/view_collection/templates/js/edit.jsx +40 -0
  25. data/lib/generators/superglue/view_collection/templates/js/index.jsx +62 -0
  26. data/lib/generators/superglue/view_collection/templates/js/new.jsx +38 -0
  27. data/lib/generators/superglue/view_collection/templates/js/show.jsx +26 -0
  28. data/lib/generators/superglue/view_collection/templates/props/edit.json.props +9 -0
  29. data/lib/generators/superglue/view_collection/templates/props/index.json.props +14 -0
  30. data/lib/generators/superglue/view_collection/templates/props/new.json.props +10 -0
  31. data/lib/generators/superglue/view_collection/templates/props/show.json.props +6 -0
  32. data/lib/generators/superglue/view_collection/templates/ts/edit.tsx +54 -0
  33. data/lib/generators/superglue/view_collection/templates/ts/index.tsx +77 -0
  34. data/lib/generators/superglue/view_collection/templates/ts/new.tsx +50 -0
  35. data/lib/generators/superglue/view_collection/templates/ts/show.tsx +37 -0
  36. data/lib/generators/superglue/view_collection/view_collection_generator.rb +180 -0
  37. data/lib/superglue/helpers.rb +1 -1
  38. data/lib/superglue.rb +2 -1
  39. metadata +60 -43
  40. data/lib/generators/rails/scaffold_controller_generator.rb +0 -12
  41. data/lib/generators/rails/superglue_generator.rb +0 -98
  42. data/lib/generators/rails/templates/controller.rb.tt +0 -68
  43. data/lib/generators/rails/templates/edit.json.props +0 -12
  44. data/lib/generators/rails/templates/index.json.props +0 -14
  45. data/lib/generators/rails/templates/new.json.props +0 -13
  46. data/lib/generators/rails/templates/show.json.props +0 -6
  47. data/lib/generators/rails/templates/web/edit.js +0 -35
  48. data/lib/generators/rails/templates/web/index.js +0 -56
  49. data/lib/generators/rails/templates/web/new.js +0 -33
  50. data/lib/generators/rails/templates/web/show.js +0 -28
  51. data/lib/install/templates/web/actions.js +0 -6
  52. data/lib/install/templates/web/application_visit.js +0 -65
  53. data/lib/install/templates/web/flash.js +0 -19
  54. data/lib/install/templates/web/page_to_page_mapping.js +0 -12
  55. data/lib/install/templates/web/pages.js +0 -15
  56. data/lib/install/templates/web/store.js +0 -32
  57. data/lib/install/web.rb +0 -55
  58. data/lib/tasks/install.rake +0 -9
  59. /data/lib/{install/templates/web → generators/superglue/install/templates}/initializer.rb +0 -0
  60. /data/lib/generators/{rails/templates/web → superglue/view_collection/templates/erb}/edit.html.erb +0 -0
  61. /data/lib/generators/{rails/templates/web → superglue/view_collection/templates/erb}/index.html.erb +0 -0
  62. /data/lib/generators/{rails/templates/web → superglue/view_collection/templates/erb}/new.html.erb +0 -0
  63. /data/lib/generators/{rails/templates/web → superglue/view_collection/templates/erb}/show.html.erb +0 -0
  64. /data/lib/generators/{rails/templates → superglue/view_collection/templates/props}/_form.json.props +0 -0
@@ -14,7 +14,7 @@ module Superglue
14
14
  end
15
15
  end
16
16
 
17
- def param_to_search_path(param)
17
+ def param_to_dig_path(param)
18
18
  if param
19
19
  param
20
20
  .gsub(/[^\da-zA-Z_=.]+/, "")
data/lib/superglue.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "superglue/helpers"
2
2
  require "superglue/redirection"
3
3
  require "props_template"
4
+ require "form_props"
4
5
 
5
6
  module Superglue
6
7
  module Controller
@@ -9,7 +10,7 @@ module Superglue
9
10
 
10
11
  def self.included(base)
11
12
  if base.respond_to?(:helper_method)
12
- base.helper_method :param_to_search_path
13
+ base.helper_method :param_to_dig_path
13
14
  end
14
15
  end
15
16
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: superglue
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.54.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-09 00:00:00.000000000 Z
10
+ date: 2025-01-06 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: actionpack
@@ -16,83 +15,102 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 7.0.0
18
+ version: '7.0'
19
+ - - "<"
20
+ - !ruby/object:Gem::Version
21
+ version: '9.0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: 7.0.0
28
+ version: '7.0'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '9.0'
27
32
  - !ruby/object:Gem::Dependency
28
33
  name: props_template
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - ">="
36
+ - - "~>"
32
37
  - !ruby/object:Gem::Version
33
- version: 0.32.0
38
+ version: '0.37'
34
39
  type: :runtime
35
40
  prerelease: false
36
41
  version_requirements: !ruby/object:Gem::Requirement
37
42
  requirements:
38
- - - ">="
43
+ - - "~>"
39
44
  - !ruby/object:Gem::Version
40
- version: 0.32.0
45
+ version: '0.37'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: form_props
43
48
  requirement: !ruby/object:Gem::Requirement
44
49
  requirements:
45
- - - ">="
50
+ - - "~>"
46
51
  - !ruby/object:Gem::Version
47
- version: 0.0.5
52
+ version: '0.2'
48
53
  type: :runtime
49
54
  prerelease: false
50
55
  version_requirements: !ruby/object:Gem::Requirement
51
56
  requirements:
52
- - - ">="
57
+ - - "~>"
53
58
  - !ruby/object:Gem::Version
54
- version: 0.0.5
59
+ version: '0.2'
55
60
  description: Rails integration for SuperglueJS
56
61
  email: jho406@gmail.com
57
62
  executables: []
58
63
  extensions: []
59
64
  extra_rdoc_files: []
60
65
  files:
61
- - lib/generators/rails/scaffold_controller_generator.rb
62
- - lib/generators/rails/superglue_generator.rb
63
- - lib/generators/rails/templates/_form.json.props
64
- - lib/generators/rails/templates/controller.rb.tt
65
- - lib/generators/rails/templates/edit.json.props
66
- - lib/generators/rails/templates/index.json.props
67
- - lib/generators/rails/templates/new.json.props
68
- - lib/generators/rails/templates/show.json.props
69
- - lib/generators/rails/templates/web/edit.html.erb
70
- - lib/generators/rails/templates/web/edit.js
71
- - lib/generators/rails/templates/web/index.html.erb
72
- - lib/generators/rails/templates/web/index.js
73
- - lib/generators/rails/templates/web/new.html.erb
74
- - lib/generators/rails/templates/web/new.js
75
- - lib/generators/rails/templates/web/show.html.erb
76
- - lib/generators/rails/templates/web/show.js
77
- - lib/install/templates/web/actions.js
78
- - lib/install/templates/web/application.js
79
- - lib/install/templates/web/application.json.props
80
- - lib/install/templates/web/application_visit.js
81
- - lib/install/templates/web/flash.js
82
- - lib/install/templates/web/initializer.rb
83
- - lib/install/templates/web/page_to_page_mapping.js
84
- - lib/install/templates/web/pages.js
85
- - lib/install/templates/web/store.js
86
- - lib/install/web.rb
66
+ - lib/generators/superglue/install/install_generator.rb
67
+ - lib/generators/superglue/install/templates/application.json.props
68
+ - lib/generators/superglue/install/templates/initializer.rb
69
+ - lib/generators/superglue/install/templates/js/application.jsx
70
+ - lib/generators/superglue/install/templates/js/application_visit.js
71
+ - lib/generators/superglue/install/templates/js/components.js
72
+ - lib/generators/superglue/install/templates/js/flash.js
73
+ - lib/generators/superglue/install/templates/js/inputs.jsx
74
+ - lib/generators/superglue/install/templates/js/jsconfig.json
75
+ - lib/generators/superglue/install/templates/js/layout.jsx
76
+ - lib/generators/superglue/install/templates/js/page_to_page_mapping.js
77
+ - lib/generators/superglue/install/templates/js/store.js
78
+ - lib/generators/superglue/install/templates/ts/application.tsx
79
+ - lib/generators/superglue/install/templates/ts/application_visit.ts
80
+ - lib/generators/superglue/install/templates/ts/components.ts
81
+ - lib/generators/superglue/install/templates/ts/flash.ts
82
+ - lib/generators/superglue/install/templates/ts/inputs.tsx
83
+ - lib/generators/superglue/install/templates/ts/layout.tsx
84
+ - lib/generators/superglue/install/templates/ts/page_to_page_mapping.ts
85
+ - lib/generators/superglue/install/templates/ts/store.ts
86
+ - lib/generators/superglue/install/templates/ts/tsconfig.json
87
+ - lib/generators/superglue/scaffold/scaffold_generator.rb
88
+ - lib/generators/superglue/scaffold_controller/scaffold_controller_generator.rb
89
+ - lib/generators/superglue/view_collection/templates/erb/edit.html.erb
90
+ - lib/generators/superglue/view_collection/templates/erb/index.html.erb
91
+ - lib/generators/superglue/view_collection/templates/erb/new.html.erb
92
+ - lib/generators/superglue/view_collection/templates/erb/show.html.erb
93
+ - lib/generators/superglue/view_collection/templates/js/edit.jsx
94
+ - lib/generators/superglue/view_collection/templates/js/index.jsx
95
+ - lib/generators/superglue/view_collection/templates/js/new.jsx
96
+ - lib/generators/superglue/view_collection/templates/js/show.jsx
97
+ - lib/generators/superglue/view_collection/templates/props/_form.json.props
98
+ - lib/generators/superglue/view_collection/templates/props/edit.json.props
99
+ - lib/generators/superglue/view_collection/templates/props/index.json.props
100
+ - lib/generators/superglue/view_collection/templates/props/new.json.props
101
+ - lib/generators/superglue/view_collection/templates/props/show.json.props
102
+ - lib/generators/superglue/view_collection/templates/ts/edit.tsx
103
+ - lib/generators/superglue/view_collection/templates/ts/index.tsx
104
+ - lib/generators/superglue/view_collection/templates/ts/new.tsx
105
+ - lib/generators/superglue/view_collection/templates/ts/show.tsx
106
+ - lib/generators/superglue/view_collection/view_collection_generator.rb
87
107
  - lib/superglue.rb
88
108
  - lib/superglue/helpers.rb
89
109
  - lib/superglue/redirection.rb
90
- - lib/tasks/install.rake
91
110
  homepage: https://github.com/thoughtbot/superglue/
92
111
  licenses:
93
112
  - MIT
94
113
  metadata: {}
95
- post_install_message:
96
114
  rdoc_options: []
97
115
  require_paths:
98
116
  - lib
@@ -107,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
125
  - !ruby/object:Gem::Version
108
126
  version: '0'
109
127
  requirements: []
110
- rubygems_version: 3.4.6
111
- signing_key:
128
+ rubygems_version: 3.6.2
112
129
  specification_version: 4
113
130
  summary: Rails integration for SuperglueJS
114
131
  test_files: []
@@ -1,12 +0,0 @@
1
- require "rails/generators"
2
- require "rails/generators/rails/scaffold_controller/scaffold_controller_generator"
3
-
4
- module Rails
5
- module Generators
6
- class ScaffoldControllerGenerator
7
- source_paths << File.expand_path("../templates", __FILE__)
8
-
9
- hook_for :superglue, type: :boolean, default: true
10
- end
11
- end
12
- end
@@ -1,98 +0,0 @@
1
- require "rails/generators/named_base"
2
- require "rails/generators/resource_helpers"
3
-
4
- module Rails
5
- module Generators
6
- class SuperglueGenerator < NamedBase
7
- include Rails::Generators::ResourceHelpers
8
-
9
- source_root File.expand_path("../templates", __FILE__)
10
-
11
- argument :attributes, type: :array, default: [], banner: "field:type field:type"
12
-
13
- def create_root_folder
14
- path = File.join("app/views", controller_file_path)
15
- empty_directory path unless File.directory?(path)
16
- end
17
-
18
- def copy_view_files
19
- %w[index show new edit].each do |view|
20
- @action_name = view
21
- filename = filename_with_extensions(view)
22
- template filename, File.join("app/views", controller_file_path, filename)
23
- end
24
- template "_form.json.props", File.join("app/views", controller_file_path, "_form.json.props")
25
-
26
- %w[index show new edit].each do |view|
27
- @action_name = view
28
- filename = filename_with_js_extensions(view)
29
- template "web/" + filename, File.join("app/views", controller_file_path, filename)
30
- end
31
-
32
- %w[index show new edit].each do |view|
33
- @action_name = view
34
- filename = filename_with_html_extensions(view)
35
- template "web/" + filename, File.join("app/views", controller_file_path, filename)
36
- end
37
-
38
- %w[index show new edit].each do |view|
39
- append_mapping(view)
40
- end
41
- end
42
-
43
- protected
44
-
45
- def view_path
46
- "../views"
47
- end
48
-
49
- def app_js_path
50
- "app/javascript/"
51
- end
52
-
53
- def append_mapping(action)
54
- app_js = "#{app_js_path}/page_to_page_mapping.js"
55
-
56
- component_name = [plural_table_name, action].map(&:camelcase).join
57
-
58
- prepend_to_file app_js do
59
- "\nimport #{component_name} from '#{view_path}/#{controller_file_path}/#{action}'"
60
- end
61
-
62
- inject_into_file app_js, after: "pageIdentifierToPageComponent = {" do
63
- "\n '#{[controller_file_path, action].join("/")}': #{component_name},"
64
- end
65
- end
66
-
67
- attr_reader :action_name
68
-
69
- def attributes_names
70
- [:id] + super
71
- end
72
-
73
- def filename_with_extensions(name)
74
- [name, :json, :props].join(".")
75
- end
76
-
77
- def filename_with_js_extensions(name)
78
- [name, :js].join(".")
79
- end
80
-
81
- def filename_with_html_extensions(name)
82
- [name, :html, :erb].join(".")
83
- end
84
-
85
- def attributes_list_with_timestamps
86
- attributes_list(attributes_names + %w[created_at updated_at])
87
- end
88
-
89
- def attributes_list(attributes = attributes_names)
90
- if self.attributes.any? { |attr| attr.name == "password" && attr.type == :digest }
91
- attributes = attributes.reject { |name| %w[password password_confirmation].include? name }
92
- end
93
-
94
- attributes
95
- end
96
- end
97
- end
98
- end
@@ -1,68 +0,0 @@
1
- <% if namespaced? -%>
2
- require_dependency "<%= namespaced_path %>/application_controller"
3
-
4
- <% end -%>
5
- <% module_namespacing do -%>
6
- class <%= controller_class_name %>Controller < ApplicationController
7
- before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
8
-
9
- # GET <%= route_url %>
10
- def index
11
- @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
12
- end
13
-
14
- # GET <%= route_url %>/1
15
- def show
16
- end
17
-
18
- # GET <%= route_url %>/new
19
- def new
20
- @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
21
- end
22
-
23
- # GET <%= route_url %>/1/edit
24
- def edit
25
- end
26
-
27
- # POST <%= route_url %>
28
- def create
29
- @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
30
-
31
- if @<%= orm_instance.save %>
32
- redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
33
- else
34
- render :new
35
- end
36
- end
37
-
38
- # PATCH/PUT <%= route_url %>/1
39
- def update
40
- if @<%= orm_instance.update("#{singular_table_name}_params") %>
41
- redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
42
- else
43
- render :edit
44
- end
45
- end
46
-
47
- # DELETE <%= route_url %>/1
48
- def destroy
49
- @<%= orm_instance.destroy %>
50
- redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
51
- end
52
-
53
- private
54
- # Use callbacks to share common setup or constraints between actions.
55
- def set_<%= singular_table_name %>
56
- @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
57
- end
58
-
59
- # Only allow a trusted parameter "white list" through.
60
- def <%= "#{singular_table_name}_params" %>
61
- <%- if attributes_names.empty? -%>
62
- params.fetch(:<%= singular_table_name %>, {})
63
- <%- else -%>
64
- params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
65
- <%- end -%>
66
- end
67
- end
68
- <% end -%>
@@ -1,12 +0,0 @@
1
- if @<%= singular_table_name %>.errors.any?
2
- json.errors({
3
- explanation: "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:",
4
- messages: @<%= singular_table_name %>.errors.full_messages.map{|msg| {body: msg}}
5
- })
6
- end
7
-
8
- json.form(partial: 'form') do
9
- end
10
-
11
- json.<%= singular_table_name.camelize(:lower)%>Path <%= singular_table_name%>_path(@<%=singular_table_name%>)
12
- json.<%= plural_table_name.camelize(:lower) %>Path <%= plural_table_name %>_path
@@ -1,14 +0,0 @@
1
- json.<%= plural_table_name.camelize(:lower) %> do
2
- json.array! @<%= plural_table_name %> do |<%= singular_table_name %>|
3
- <%- attributes_list_with_timestamps.each do |attr| -%>
4
- json.<%=attr%> <%= singular_table_name.camelize(:lower) %>.<%=attr%>
5
- <%- end -%>
6
- json.edit<%=singular_table_name.camelize%>Path edit_<%=singular_table_name%>_path(<%=singular_table_name%>)
7
- json.<%=singular_table_name.camelize(:lower)%>Path <%=singular_table_name%>_path(<%=singular_table_name%>)
8
- json.deleteForm do
9
- form_props(model: <%=singular_table_name%>, method: :delete)
10
- end
11
- end
12
- end
13
-
14
- json.new<%= singular_table_name.camelize %>Path new_<%= singular_table_name %>_path
@@ -1,13 +0,0 @@
1
- if @<%= singular_table_name %>.errors.any?
2
- json.errors({
3
- explanation: "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:",
4
- messages: @<%= singular_table_name %>.errors.full_messages.map{|msg| {body: msg}}
5
- })
6
- end
7
-
8
- json.form(partial: 'form') do
9
- end
10
-
11
- json.<%= plural_table_name.camelize(:lower) %>Path <%= plural_table_name %>_path
12
-
13
-
@@ -1,6 +0,0 @@
1
- <%- attributes_list_with_timestamps.each do |attr|-%>
2
- json.<%=attr.to_s.camelize(:lower)%> @<%= singular_table_name %>.<%=attr%>
3
- <%- end -%>
4
-
5
- json.<%= plural_table_name.camelize(:lower) %>Path <%= plural_table_name %>_path
6
- json.edit<%= singular_table_name.camelize %>Path edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
@@ -1,35 +0,0 @@
1
- import React from 'react'
2
- // import { useSelector } from 'react-redux'
3
-
4
- export default function <%= plural_table_name.camelize %>Edit ({
5
- // visit,
6
- // remote,
7
- form,
8
- errors,
9
- <%= singular_table_name.camelize(:lower) %>Path,
10
- <%= plural_table_name.camelize(:lower) %>Path,
11
- }) {
12
- const messagesEl = errors && (
13
- <div id="error_explanation">
14
- <h2>{ errors.explanation }</h2>
15
- <ul>{ errors.messages.map(({body})=> <li key={body}>{body}</li>) }</ul>
16
- </div>
17
- )
18
-
19
- return (
20
- <div>
21
- {messagesEl}
22
- <form {...form.props} data-sg-visit>
23
- {Object.values(form.extras).map((hiddenProps) => (<input {...hiddenProps} key={hiddenProps.id} type="hidden"/>))}
24
- <%- attributes.each do |attr| -%>
25
- <input {...form.inputs.<%= attr.column_name %>} type="text"/>
26
- <label htmlFor={form.inputs.<%= attr.column_name %>.id}><%= attr.column_name %></label>
27
- <%- end -%>
28
- <button {...form.inputs.submit} type="submit"> {...form.inputs.submit.text} </button>
29
- </form>
30
-
31
- <a href={<%= singular_table_name.camelize(:lower) %>Path} data-sg-visit>Show</a>
32
- <a href={<%= plural_table_name.camelize(:lower) %>Path} data-sg-visit>Back</a>
33
- </div>
34
- )
35
- }
@@ -1,56 +0,0 @@
1
- import React from 'react'
2
- import { useSelector } from 'react-redux'
3
-
4
- export default function <%= plural_table_name.camelize %>Index({
5
- // visit,
6
- // remote,
7
- new<%= singular_table_name.camelize %>Path,
8
- <%= plural_table_name.camelize(:lower) %> = [],
9
- }) {
10
- const flash = useSelector((state) => state.flash)
11
-
12
- const <%= singular_table_name.camelize(:lower) %>Items = <%= plural_table_name.camelize(:lower) %>.map((<%= singular_table_name.camelize(:lower) %>, key) => {
13
- const deleteForm = <%=singular_table_name.camelize(:lower)%>.deleteForm;
14
-
15
- return (
16
- <tr key={<%= singular_table_name.camelize(:lower) %>.id}>
17
- <%- attributes_list.select{|attr| attr != :id }.each do |attr| -%>
18
- <td>{<%=singular_table_name.camelize(:lower)%>.<%=attr.camelize(:lower)%>}</td>
19
- <%- end -%>
20
- <td><a href={ <%=singular_table_name%>.<%=singular_table_name.camelize(:lower)%>Path } data-sg-visit>Show</a></td>
21
- <td><a href={ <%=singular_table_name%>.edit<%=singular_table_name.camelize%>Path } data-sg-visit>Edit</a></td>
22
- <td>
23
- <form {...deleteForm.props} data-sg-visit>
24
- {Object.values(deleteForm.extras).map((hiddenProps) => (<input {...hiddenProps} key={hiddenProps.id} type="hidden"/>))}
25
- <button type="submit">Delete</button>
26
- </form>
27
- </td>
28
- </tr>
29
- )
30
- })
31
-
32
- return (
33
- <div>
34
- <p id="notice">{flash && flash.notice}</p>
35
-
36
- <h1><%= plural_table_name.capitalize %></h1>
37
-
38
- <table>
39
- <thead>
40
- <%- attributes_list.select{|attr| attr != :id }.each do |attr| -%>
41
- <tr><th><%=attr.capitalize%></th></tr>
42
- <%- end -%>
43
- <tr>
44
- <th colSpan="3"></th>
45
- </tr>
46
- </thead>
47
-
48
- <tbody>
49
- {<%= singular_table_name %>Items}
50
- </tbody>
51
- </table>
52
- <br />
53
- <a href={new<%= singular_table_name.camelize %>Path} data-sg-visit>New <%= singular_table_name.capitalize %></a>
54
- </div>
55
- )
56
- }
@@ -1,33 +0,0 @@
1
- import React from 'react'
2
- // import { useSelector } from 'react-redux'
3
-
4
- export default function <%= plural_table_name.camelize %>New({
5
- // visit,
6
- // remote
7
- form,
8
- errors,
9
- <%= plural_table_name.camelize(:lower) %>Path,
10
- }) {
11
- const messagesEl = errors && (
12
- <div id="error_explanation">
13
- <h2>{ errors.explanation }</h2>
14
- <ul>{ errors.messages.map(({body})=> <li key={body}>{body}</li>) }</ul>
15
- </div>
16
- )
17
-
18
- return (
19
- <div>
20
- {messagesEl}
21
- <form {...form.props} data-sg-visit>
22
- {Object.values(form.extras).map((hiddenProps) => (<input {...hiddenProps} key={hiddenProps.id} type="hidden"/>))}
23
- <%- attributes.each do |attr| -%>
24
- <input {...form.inputs.<%= attr.column_name %>} type="text"/>
25
- <label htmlFor={form.inputs.<%= attr.column_name %>.id}><%= attr.column_name %></label>
26
- <%- end -%>
27
- <button {...form.inputs.submit} type="submit"> {...form.inputs.submit.text} </button>
28
- </form>
29
-
30
- <a href={<%= plural_table_name.camelize(:lower) %>Path} data-sg-visit>Back</a>
31
- </div>
32
- )
33
- }
@@ -1,28 +0,0 @@
1
- import React from 'react'
2
- import { useSelector } from 'react-redux'
3
-
4
- export default function <%= plural_table_name.camelize %>Show({
5
- // visit,
6
- // remote,
7
- <%- attributes_list_with_timestamps.select{|attr| attr != :id }.each do |attr| -%>
8
- <%=attr.camelize(:lower)%>,
9
- <%- end -%>
10
- edit<%= singular_table_name.camelize %>Path,
11
- <%= plural_table_name.camelize(:lower) %>Path
12
- }) {
13
- const flash = useSelector((state) => state.flash)
14
-
15
- return (
16
- <div>
17
- <p id="notice">{flash && flash.notice}</p>
18
- <%- attributes_list_with_timestamps.select{|attr| attr != :id }.each do |attr| -%>
19
- <p>
20
- <strong><%= attr.capitalize %>:</strong>
21
- {<%=attr.camelize(:lower)%>}
22
- </p>
23
- <%- end -%>
24
- <a href={ edit<%= singular_table_name.camelize %>Path } data-sg-visit>Edit</a>
25
- <a href={ <%= plural_table_name.camelize(:lower) %>Path } data-sg-visit>Back</a>
26
- </div>
27
- )
28
- }
@@ -1,6 +0,0 @@
1
- import { createAction } from '@reduxjs/toolkit'
2
- import { SAVE_RESPONSE, BEFORE_VISIT, UPDATE_FRAGMENTS } from '@thoughtbot/superglue'
3
-
4
- export const saveResponse = createAction(SAVE_RESPONSE)
5
- export const beforeVisit = createAction(BEFORE_VISIT)
6
- export const updateFragments = createAction(UPDATE_FRAGMENTS)
@@ -1,65 +0,0 @@
1
- import { visit, remote } from '@thoughtbot/superglue/action_creators'
2
-
3
- export function buildVisitAndRemote(ref, store) {
4
- const appRemote = (...args) => {
5
- return store.dispatch(remote(...args))
6
- }
7
-
8
- const appVisit = (...args) => {
9
- // Do something before
10
- // e.g, show loading state, you can access the current pageKey
11
- // via store.getState().superglue.currentPageKey
12
- let { action } = args
13
-
14
- return store
15
- .dispatch(visit(...args))
16
- .then((meta) => {
17
- // The assets fingerprints changed, instead of transitioning
18
- // just go to the URL directly to retrieve new assets
19
- if (meta.needsRefresh) {
20
- window.location = meta.url
21
- return
22
- }
23
-
24
- ref.current.navigateTo(meta.pageKey, {
25
- action: meta.suggestedAction,
26
- })
27
-
28
- // always return meta
29
- return meta
30
- })
31
- .finally(() => {
32
- // Do something after
33
- // e.g, hide loading state, you can access the changed pageKey
34
- // via getState().superglue.currentPageKey
35
- })
36
- .catch((err) => {
37
- const response = err.response
38
-
39
- if (!response) {
40
- console.error(err)
41
- return
42
- }
43
-
44
- if (response.ok) {
45
- // err gets thrown, but if the response is ok,
46
- // it must be an html body that
47
- // superglue can't parse, just go to the location
48
- window.location = response.url
49
- } else {
50
- if (response.status >= 400 && response.status < 500) {
51
- window.location = '/400.html'
52
- return
53
- }
54
-
55
- if (response.status >= 500) {
56
- window.location = '/500.html'
57
- return
58
- }
59
- }
60
- })
61
- }
62
-
63
- return { visit: appVisit, remote: appRemote }
64
- }
65
-