superglue 0.53.2 → 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.
- checksums.yaml +4 -4
- data/lib/generators/superglue/install/install_generator.rb +119 -0
- data/lib/{install/templates/web → generators/superglue/install/templates}/application.json.props +2 -2
- data/lib/generators/superglue/install/templates/js/application.jsx +35 -0
- data/lib/generators/superglue/install/templates/js/application_visit.js +113 -0
- data/lib/generators/superglue/install/templates/js/components.js +2 -0
- data/lib/generators/superglue/install/templates/js/flash.js +44 -0
- data/lib/generators/superglue/install/templates/js/inputs.jsx +302 -0
- data/lib/generators/superglue/install/templates/js/jsconfig.json +9 -0
- data/lib/generators/superglue/install/templates/js/layout.jsx +16 -0
- data/lib/generators/superglue/install/templates/js/page_to_page_mapping.js +35 -0
- data/lib/generators/superglue/install/templates/js/store.js +30 -0
- data/lib/{install/templates/web/application.js → generators/superglue/install/templates/ts/application.tsx} +10 -16
- data/lib/generators/superglue/install/templates/ts/application_visit.ts +122 -0
- data/lib/generators/superglue/install/templates/ts/components.ts +2 -0
- data/lib/generators/superglue/install/templates/ts/flash.ts +46 -0
- data/lib/generators/superglue/install/templates/ts/inputs.tsx +547 -0
- data/lib/generators/superglue/install/templates/ts/layout.tsx +16 -0
- data/lib/generators/superglue/install/templates/ts/page_to_page_mapping.ts +34 -0
- data/lib/generators/superglue/install/templates/ts/store.ts +34 -0
- data/lib/generators/superglue/install/templates/ts/tsconfig.json +27 -0
- data/lib/generators/superglue/scaffold/scaffold_generator.rb +16 -0
- data/lib/generators/superglue/scaffold_controller/scaffold_controller_generator.rb +61 -0
- data/lib/generators/{rails/templates/web → superglue/view_collection/templates/erb}/edit.html.erb +1 -1
- data/lib/generators/{rails/templates/web → superglue/view_collection/templates/erb}/index.html.erb +1 -1
- data/lib/generators/{rails/templates/web → superglue/view_collection/templates/erb}/new.html.erb +1 -1
- data/lib/generators/{rails/templates/web → superglue/view_collection/templates/erb}/show.html.erb +1 -1
- data/lib/generators/superglue/view_collection/templates/js/edit.jsx +40 -0
- data/lib/generators/superglue/view_collection/templates/js/index.jsx +62 -0
- data/lib/generators/superglue/view_collection/templates/js/new.jsx +38 -0
- data/lib/generators/superglue/view_collection/templates/js/show.jsx +26 -0
- data/lib/generators/superglue/view_collection/templates/props/edit.json.props +9 -0
- data/lib/generators/superglue/view_collection/templates/props/index.json.props +14 -0
- data/lib/generators/superglue/view_collection/templates/props/new.json.props +10 -0
- data/lib/generators/superglue/view_collection/templates/props/show.json.props +6 -0
- data/lib/generators/superglue/view_collection/templates/ts/edit.tsx +54 -0
- data/lib/generators/superglue/view_collection/templates/ts/index.tsx +77 -0
- data/lib/generators/superglue/view_collection/templates/ts/new.tsx +50 -0
- data/lib/generators/superglue/view_collection/templates/ts/show.tsx +37 -0
- data/lib/generators/superglue/view_collection/view_collection_generator.rb +180 -0
- data/lib/superglue/helpers.rb +1 -1
- data/lib/superglue.rb +2 -1
- metadata +60 -43
- data/lib/generators/rails/scaffold_controller_generator.rb +0 -12
- data/lib/generators/rails/superglue_generator.rb +0 -98
- data/lib/generators/rails/templates/controller.rb.tt +0 -82
- data/lib/generators/rails/templates/edit.json.props +0 -12
- data/lib/generators/rails/templates/index.json.props +0 -14
- data/lib/generators/rails/templates/new.json.props +0 -13
- data/lib/generators/rails/templates/show.json.props +0 -6
- data/lib/generators/rails/templates/web/edit.js +0 -35
- data/lib/generators/rails/templates/web/index.js +0 -56
- data/lib/generators/rails/templates/web/new.js +0 -33
- data/lib/generators/rails/templates/web/show.js +0 -28
- data/lib/install/templates/web/actions.js +0 -6
- data/lib/install/templates/web/application_visit.js +0 -65
- data/lib/install/templates/web/flash.js +0 -19
- data/lib/install/templates/web/page_to_page_mapping.js +0 -12
- data/lib/install/templates/web/pages.js +0 -15
- data/lib/install/templates/web/store.js +0 -32
- data/lib/install/web.rb +0 -55
- data/lib/tasks/install.rake +0 -9
- /data/lib/{install/templates/web → generators/superglue/install/templates}/initializer.rb +0 -0
- /data/lib/generators/{rails/templates → superglue/view_collection/templates/props}/_form.json.props +0 -0
@@ -0,0 +1,180 @@
|
|
1
|
+
require "rails/generators/named_base"
|
2
|
+
require "rails/generators/resource_helpers"
|
3
|
+
|
4
|
+
module Superglue
|
5
|
+
module Generators
|
6
|
+
class ViewCollectionGenerator < Rails::Generators::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
|
+
class_option :typescript,
|
14
|
+
type: :boolean,
|
15
|
+
required: false,
|
16
|
+
default: false,
|
17
|
+
desc: "Use typescript"
|
18
|
+
|
19
|
+
def create_root_folder
|
20
|
+
path = File.join("app/views", controller_file_path)
|
21
|
+
empty_directory path unless File.directory?(path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def copy_erb_files
|
25
|
+
available_views.each do |view|
|
26
|
+
@action_name = view
|
27
|
+
filename = filename_with_html_extensions(view)
|
28
|
+
template "erb/" + filename, File.join("app/views", controller_file_path, filename)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def copy_prop_files
|
33
|
+
available_views.each do |view|
|
34
|
+
@action_name = view
|
35
|
+
filename = filename_with_extensions(view)
|
36
|
+
template "props/" + filename, File.join("app/views", controller_file_path, filename)
|
37
|
+
end
|
38
|
+
|
39
|
+
template "props/_form.json.props", File.join("app/views", controller_file_path, "_form.json.props")
|
40
|
+
end
|
41
|
+
|
42
|
+
def copy_js_files
|
43
|
+
available_views.each do |view|
|
44
|
+
@action_name = view
|
45
|
+
if options["typescript"]
|
46
|
+
filename = filename_with_tsx_extensions(view)
|
47
|
+
template "ts/" + filename, File.join("app/views", controller_file_path, filename)
|
48
|
+
else
|
49
|
+
filename = filename_with_jsx_extensions(view)
|
50
|
+
template "js/" + filename, File.join("app/views", controller_file_path, filename)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def append_mapping
|
56
|
+
available_views.each do |action|
|
57
|
+
app_js = if options["typescript"]
|
58
|
+
"#{app_js_path}/page_to_page_mapping.ts"
|
59
|
+
else
|
60
|
+
"#{app_js_path}/page_to_page_mapping.js"
|
61
|
+
end
|
62
|
+
|
63
|
+
component_name = [plural_table_name, action].map(&:camelcase).join
|
64
|
+
|
65
|
+
if match_file(app_js, /pageIdentifierToPageComponent = {$/)
|
66
|
+
prepend_to_file app_js do
|
67
|
+
"import #{component_name} from '#{view_path}/#{controller_file_path}/#{action}'\n"
|
68
|
+
end
|
69
|
+
|
70
|
+
inject_into_file app_js, after: /pageIdentifierToPageComponent = {$/ do
|
71
|
+
"\n '#{[controller_file_path, action].join("/")}': #{component_name},"
|
72
|
+
end
|
73
|
+
else
|
74
|
+
say "Skipping appending to #{app_js}, you may be using a bundler that supports globing."
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
def js_component(attribute)
|
82
|
+
case attribute.type
|
83
|
+
when :string
|
84
|
+
"TextField"
|
85
|
+
when :text, :rich_text
|
86
|
+
"TextArea"
|
87
|
+
when :integer, :float, :decimal
|
88
|
+
"NumberField"
|
89
|
+
when :datetime, :timestamp, :time
|
90
|
+
"DatetimeLocalField"
|
91
|
+
when :date
|
92
|
+
"DateField"
|
93
|
+
when :boolean
|
94
|
+
"Checkbox"
|
95
|
+
when :attachments, :attachment
|
96
|
+
"File"
|
97
|
+
else
|
98
|
+
"TextField"
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def json_mappable_type(attribute)
|
103
|
+
case attribute.type
|
104
|
+
when :string
|
105
|
+
"string"
|
106
|
+
when :text, :rich_text
|
107
|
+
"string"
|
108
|
+
when :integer, :float, :decimal
|
109
|
+
"number"
|
110
|
+
when :datetime, :timestamp, :time
|
111
|
+
"string"
|
112
|
+
when :date
|
113
|
+
"string"
|
114
|
+
when :boolean
|
115
|
+
"boolean"
|
116
|
+
else
|
117
|
+
"string"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def js_singular_table_name(casing = :lower)
|
122
|
+
singular_table_name.camelize(casing)
|
123
|
+
end
|
124
|
+
|
125
|
+
def js_plural_table_name(casing = :lower)
|
126
|
+
plural_table_name.camelize(casing)
|
127
|
+
end
|
128
|
+
|
129
|
+
def available_views
|
130
|
+
%w[index edit show new]
|
131
|
+
end
|
132
|
+
|
133
|
+
def view_path
|
134
|
+
"@views"
|
135
|
+
end
|
136
|
+
|
137
|
+
def app_js_path
|
138
|
+
"app/javascript"
|
139
|
+
end
|
140
|
+
|
141
|
+
attr_reader :action_name
|
142
|
+
|
143
|
+
def attributes_names
|
144
|
+
[:id] + super
|
145
|
+
end
|
146
|
+
|
147
|
+
def filename_with_extensions(name)
|
148
|
+
[name, :json, :props].join(".")
|
149
|
+
end
|
150
|
+
|
151
|
+
def filename_with_jsx_extensions(name)
|
152
|
+
[name, :jsx].join(".")
|
153
|
+
end
|
154
|
+
|
155
|
+
def filename_with_tsx_extensions(name)
|
156
|
+
[name, :tsx].join(".")
|
157
|
+
end
|
158
|
+
|
159
|
+
def filename_with_html_extensions(name)
|
160
|
+
[name, :html, :erb].join(".")
|
161
|
+
end
|
162
|
+
|
163
|
+
def showable_attributes
|
164
|
+
attributes.reject { |attr| %w[password password_confirmation].include? attr.name }
|
165
|
+
end
|
166
|
+
|
167
|
+
def attributes_list_with_timestamps
|
168
|
+
attributes_list(attributes_names + %w[created_at updated_at])
|
169
|
+
end
|
170
|
+
|
171
|
+
def attributes_list(attributes = attributes_names)
|
172
|
+
if self.attributes.any? { |attr| attr.name == "password" && attr.type == :digest }
|
173
|
+
attributes = attributes.reject { |name| %w[password password_confirmation].include? name }
|
174
|
+
end
|
175
|
+
|
176
|
+
attributes
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
data/lib/superglue/helpers.rb
CHANGED
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 :
|
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.
|
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:
|
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
|
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
|
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.
|
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.
|
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.
|
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.
|
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/
|
62
|
-
- lib/generators/
|
63
|
-
- lib/generators/
|
64
|
-
- lib/generators/
|
65
|
-
- lib/generators/
|
66
|
-
- lib/generators/
|
67
|
-
- lib/generators/
|
68
|
-
- lib/generators/
|
69
|
-
- lib/generators/
|
70
|
-
- lib/generators/
|
71
|
-
- lib/generators/
|
72
|
-
- lib/generators/
|
73
|
-
- lib/generators/
|
74
|
-
- lib/generators/
|
75
|
-
- lib/generators/
|
76
|
-
- lib/generators/
|
77
|
-
- lib/install/templates/
|
78
|
-
- lib/install/templates/
|
79
|
-
- lib/install/templates/
|
80
|
-
- lib/install/templates/
|
81
|
-
- lib/install/templates/
|
82
|
-
- lib/
|
83
|
-
- lib/
|
84
|
-
- lib/
|
85
|
-
- lib/
|
86
|
-
- lib/
|
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.
|
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,82 +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
|
-
<%- if options[:platform] == 'mobile' -%>
|
33
|
-
redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully created.'" %>
|
34
|
-
<%- else -%>
|
35
|
-
redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %>
|
36
|
-
<%- end -%>
|
37
|
-
else
|
38
|
-
response.set_header("content-location", new_<%= singular_table_name %>_path)
|
39
|
-
render :new
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# PATCH/PUT <%= route_url %>/1
|
44
|
-
def update
|
45
|
-
if @<%= orm_instance.update("#{singular_table_name}_params") %>
|
46
|
-
<%- if options[:platform] == 'mobile' -%>
|
47
|
-
redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully updated.'" %>
|
48
|
-
<%- else -%>
|
49
|
-
redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %>
|
50
|
-
<%- end -%>
|
51
|
-
else
|
52
|
-
response.set_header("content-location", edit_<%= singular_table_name %>_path(@<%= singular_table_name %>))
|
53
|
-
render :edit
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# DELETE <%= route_url %>/1
|
58
|
-
def destroy
|
59
|
-
@<%= orm_instance.destroy %>
|
60
|
-
<%- if options[:platform] == 'mobile' -%>
|
61
|
-
redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
|
62
|
-
<%- else -%>
|
63
|
-
redirect_to <%= index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
|
64
|
-
<%- end -%>
|
65
|
-
end
|
66
|
-
|
67
|
-
private
|
68
|
-
# Use callbacks to share common setup or constraints between actions.
|
69
|
-
def set_<%= singular_table_name %>
|
70
|
-
@<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
|
71
|
-
end
|
72
|
-
|
73
|
-
# Only allow a trusted parameter "white list" through.
|
74
|
-
def <%= "#{singular_table_name}_params" %>
|
75
|
-
<%- if attributes_names.empty? -%>
|
76
|
-
params.fetch(:<%= singular_table_name %>, {})
|
77
|
-
<%- else -%>
|
78
|
-
params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
79
|
-
<%- end -%>
|
80
|
-
end
|
81
|
-
end
|
82
|
-
<% 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
|
-
}
|