superglue 2.0.0.rc.2 → 2.0.0.rc.4
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 +242 -60
- data/lib/generators/superglue/install/templates/bun/bun.config.deepkit.js +1 -0
- data/lib/generators/superglue/install/templates/bun/bun.config.js +1 -0
- data/lib/generators/superglue/install/templates/bun/bun.config.ts.js +1 -0
- data/lib/generators/superglue/install/templates/bun/bun.config.typia.js +3 -2
- data/lib/generators/superglue/install/templates/bun/page_to_page_mapping.js +1 -1
- data/lib/generators/superglue/install/templates/bun/page_to_page_mapping.ts +1 -1
- data/lib/generators/superglue/install/templates/js/application.jsx +5 -8
- data/lib/generators/superglue/install/templates/js/build.mjs +1 -0
- data/lib/generators/superglue/install/templates/js/inputs.jsx +1 -1
- data/lib/generators/superglue/install/templates/js/jsconfig.json +3 -3
- data/lib/generators/superglue/install/templates/js/layout.jsx +2 -3
- data/lib/generators/superglue/install/templates/rollup/rollup.config.deepkit.js +8 -11
- data/lib/generators/superglue/install/templates/rollup/rollup.config.js +2 -6
- data/lib/generators/superglue/install/templates/rollup/rollup.config.ts.js +2 -9
- data/lib/generators/superglue/install/templates/rollup/rollup.config.typia.js +5 -10
- data/lib/generators/superglue/install/templates/ssr/bun.build_ssr.js +1 -0
- data/lib/generators/superglue/install/templates/ssr/esbuild.build_ssr.mjs +1 -0
- data/lib/generators/superglue/install/templates/ssr/rollup.build_ssr.config.js +6 -7
- data/lib/generators/superglue/install/templates/ssr/server_rendering.jsx +6 -4
- data/lib/generators/superglue/install/templates/ssr/server_rendering.tsx +5 -3
- data/lib/generators/superglue/install/templates/ssr/webpack.build_ssr.js +2 -1
- data/lib/generators/superglue/install/templates/ts/application.tsx +5 -8
- data/lib/generators/superglue/install/templates/ts/build.deepkit.mjs +1 -0
- data/lib/generators/superglue/install/templates/ts/build.mjs +1 -0
- data/lib/generators/superglue/install/templates/ts/build.typia.mjs +1 -0
- data/lib/generators/superglue/install/templates/ts/flash.ts +3 -0
- data/lib/generators/superglue/install/templates/ts/inputs.tsx +1 -1
- data/lib/generators/superglue/install/templates/ts/layout.tsx +4 -3
- data/lib/generators/superglue/install/templates/ts/tsconfig.json +3 -4
- data/lib/generators/superglue/install/templates/webpack/webpack.config.deepkit.js +2 -1
- data/lib/generators/superglue/install/templates/webpack/webpack.config.js +2 -1
- data/lib/generators/superglue/install/templates/webpack/webpack.config.ts.js +2 -1
- data/lib/generators/superglue/install/templates/webpack/webpack.config.typia.js +2 -1
- data/lib/generators/superglue/scaffold_controller/scaffold_controller_generator.rb +12 -12
- data/lib/generators/superglue/view_collection/templates/js/edit.html.jsx +2 -4
- data/lib/generators/superglue/view_collection/templates/js/index.html.jsx +3 -4
- data/lib/generators/superglue/view_collection/templates/js/new.html.jsx +2 -4
- data/lib/generators/superglue/view_collection/templates/js/show.html.jsx +2 -4
- data/lib/generators/superglue/view_collection/templates/ts/edit.html.tsx +2 -4
- data/lib/generators/superglue/view_collection/templates/ts/index.html.tsx +3 -4
- data/lib/generators/superglue/view_collection/templates/ts/new.html.tsx +2 -4
- data/lib/generators/superglue/view_collection/templates/ts/show.html.tsx +3 -5
- data/lib/generators/superglue/view_collection/view_collection_generator.rb +8 -35
- metadata +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path"
|
|
2
2
|
import resolve from "@rollup/plugin-node-resolve"
|
|
3
3
|
import commonjs from "@rollup/plugin-commonjs"
|
|
4
|
-
import
|
|
4
|
+
import esbuild from "rollup-plugin-esbuild"
|
|
5
5
|
import alias from "@rollup/plugin-alias"
|
|
6
6
|
import importMetaGlob from "rollup-plugin-import-meta-glob"
|
|
7
7
|
import ttsc from "@ttsc/unplugin"
|
|
@@ -24,15 +24,10 @@ export default {
|
|
|
24
24
|
}),
|
|
25
25
|
resolve({ extensions: [".ts", ".tsx", ".js", ".jsx"] }),
|
|
26
26
|
commonjs(),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"@babel/preset-typescript"
|
|
32
|
-
],
|
|
33
|
-
extensions: [".ts", ".tsx", ".js", ".jsx"]
|
|
34
|
-
}),
|
|
27
|
+
// Before esbuild: it rewrites the TypeScript source, and esbuild compiles
|
|
28
|
+
// its output (rollup runs plugins in order and ignores `enforce`).
|
|
29
|
+
...(process.env.NODE_ENV === 'production' ? [] : [ttscPlugin()]),
|
|
30
|
+
esbuild({ jsx: "automatic" }),
|
|
35
31
|
importMetaGlob(),
|
|
36
|
-
...(process.env.NODE_ENV === 'production' ? [] : [ttscPlugin()])
|
|
37
32
|
]
|
|
38
33
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "path"
|
|
2
2
|
import resolve from "@rollup/plugin-node-resolve"
|
|
3
3
|
import commonjs from "@rollup/plugin-commonjs"
|
|
4
|
-
import
|
|
4
|
+
import esbuild from "rollup-plugin-esbuild"
|
|
5
5
|
import alias from "@rollup/plugin-alias"
|
|
6
6
|
import replace from "@rollup/plugin-replace"
|
|
7
7
|
import importMetaGlob from "rollup-plugin-import-meta-glob"
|
|
@@ -29,14 +29,13 @@ export default {
|
|
|
29
29
|
resolve({
|
|
30
30
|
extensions: [".js", ".jsx", ".ts", ".tsx"],
|
|
31
31
|
browser: true,
|
|
32
|
-
exportConditions: ["browser"]
|
|
32
|
+
exportConditions: ["browser"],
|
|
33
|
+
// Bundle npm polyfills (e.g. "buffer", imported by @deepkit/type)
|
|
34
|
+
// rather than Node built-ins, which MiniRacer does not have.
|
|
35
|
+
preferBuiltins: false
|
|
33
36
|
}),
|
|
34
37
|
commonjs(),
|
|
35
|
-
|
|
36
|
-
babelHelpers: "bundled",
|
|
37
|
-
presets: [["@babel/preset-react", { runtime: "automatic" }]],
|
|
38
|
-
extensions: [".js", ".jsx", ".ts", ".tsx"]
|
|
39
|
-
}),
|
|
38
|
+
esbuild({ jsx: "automatic" }),
|
|
40
39
|
importMetaGlob(),
|
|
41
40
|
]
|
|
42
41
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { createApp } from "@thoughtbot/superglue";
|
|
3
2
|
import { buildVisitAndRemote } from "./application_visit";
|
|
4
3
|
import { pageIdentifierToPageComponent } from "./page_to_page_mapping";
|
|
5
4
|
import { renderToString } from "react-dom/server";
|
|
5
|
+
import { Layout } from "./components";
|
|
6
6
|
|
|
7
7
|
setHumidRenderer((json, baseUrl, path) => {
|
|
8
8
|
const initialState = JSON.parse(json);
|
|
9
|
-
const { Provider, Outlet } = createApp({
|
|
9
|
+
const { Provider, Outlet, ujs } = createApp({
|
|
10
10
|
baseUrl,
|
|
11
11
|
initialPage: initialState,
|
|
12
12
|
path,
|
|
@@ -16,7 +16,9 @@ setHumidRenderer((json, baseUrl, path) => {
|
|
|
16
16
|
|
|
17
17
|
return renderToString(
|
|
18
18
|
<Provider>
|
|
19
|
-
<
|
|
20
|
-
|
|
19
|
+
<Layout onClick={ujs.onClick} onSubmit={ujs.onSubmit}>
|
|
20
|
+
<Outlet />
|
|
21
|
+
</Layout>
|
|
22
|
+
</Provider>
|
|
21
23
|
);
|
|
22
24
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { createApp } from "@thoughtbot/superglue";
|
|
3
2
|
import { buildVisitAndRemote } from "./application_visit";
|
|
4
3
|
import { pageIdentifierToPageComponent } from "./page_to_page_mapping";
|
|
5
4
|
import { renderToString } from "react-dom/server";
|
|
5
|
+
import { Layout } from "./components";
|
|
6
6
|
|
|
7
7
|
declare function setHumidRenderer(
|
|
8
8
|
fn: (json: string, baseUrl: string, path: string) => string,
|
|
@@ -10,7 +10,7 @@ declare function setHumidRenderer(
|
|
|
10
10
|
|
|
11
11
|
setHumidRenderer((json, baseUrl, path) => {
|
|
12
12
|
const initialState = JSON.parse(json);
|
|
13
|
-
const { Provider, Outlet } = createApp({
|
|
13
|
+
const { Provider, Outlet, ujs } = createApp({
|
|
14
14
|
baseUrl,
|
|
15
15
|
initialPage: initialState,
|
|
16
16
|
path,
|
|
@@ -20,7 +20,9 @@ setHumidRenderer((json, baseUrl, path) => {
|
|
|
20
20
|
|
|
21
21
|
return renderToString(
|
|
22
22
|
<Provider>
|
|
23
|
-
<
|
|
23
|
+
<Layout onClick={ujs.onClick} onSubmit={ujs.onSubmit}>
|
|
24
|
+
<Outlet />
|
|
25
|
+
</Layout>
|
|
24
26
|
</Provider>,
|
|
25
27
|
);
|
|
26
28
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import { createRoot, hydrateRoot } from "react-dom/client";
|
|
3
2
|
import { createApp, SaveResponse } from "@thoughtbot/superglue";
|
|
4
3
|
import { buildVisitAndRemote } from "./application_visit";
|
|
@@ -32,13 +31,11 @@ if (typeof window !== "undefined" && window.SUPERGLUE_INITIAL_PAGE_STATE) {
|
|
|
32
31
|
});
|
|
33
32
|
|
|
34
33
|
const app = (
|
|
35
|
-
<
|
|
36
|
-
<
|
|
37
|
-
<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
</Provider>
|
|
41
|
-
</div>
|
|
34
|
+
<Provider>
|
|
35
|
+
<Layout onClick={ujs.onClick} onSubmit={ujs.onSubmit}>
|
|
36
|
+
<Outlet />
|
|
37
|
+
</Layout>
|
|
38
|
+
</Provider>
|
|
42
39
|
);
|
|
43
40
|
|
|
44
41
|
if (appEl.hasChildNodes()) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useFlash } from "@thoughtbot/superglue";
|
|
2
|
+
import type { ValidationErrors } from "@thoughtbot/candy_wrapper";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Customize this type to match the flash keys your application uses.
|
|
@@ -8,6 +9,8 @@ export type AppFlash = {
|
|
|
8
9
|
notice?: string;
|
|
9
10
|
alert?: string;
|
|
10
11
|
error?: string;
|
|
12
|
+
// Form errors the scaffold stores under e.g. flash["postFormErrors"]
|
|
13
|
+
[key: `${string}FormErrors`]: ValidationErrors | undefined;
|
|
11
14
|
[key: string]: unknown;
|
|
12
15
|
};
|
|
13
16
|
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* There is no style and structured with bare necessities. You should modify
|
|
8
8
|
* these components to fit your design needs.
|
|
9
9
|
*/
|
|
10
|
-
import
|
|
10
|
+
import { createContext, ReactNode, useContext, useMemo } from "react";
|
|
11
11
|
|
|
12
12
|
export type {
|
|
13
13
|
CheckboxField as RailsCheckboxFieldProps,
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import type { Handlers } from '@thoughtbot/superglue'
|
|
2
3
|
import { useAppFlash } from '@javascript/flash'
|
|
3
4
|
|
|
4
|
-
export const Layout = ({children}: {children: ReactNode}) => {
|
|
5
|
+
export const Layout = ({children, onClick, onSubmit}: {children: ReactNode} & Partial<Handlers>) => {
|
|
5
6
|
const flash = useAppFlash()
|
|
6
7
|
|
|
7
8
|
return (
|
|
8
|
-
<div>
|
|
9
|
+
<div onClick={onClick} onSubmit={onSubmit}>
|
|
9
10
|
{flash.success && <p>{flash.success}</p>}
|
|
10
11
|
{flash.notice && <p>{flash.notice}</p>}
|
|
11
12
|
{flash.error && <p>{flash.error}</p>}
|
|
@@ -7,17 +7,16 @@
|
|
|
7
7
|
"strictPropertyInitialization": false,
|
|
8
8
|
"noUnusedLocals": true,
|
|
9
9
|
"noUnusedParameters": true,
|
|
10
|
-
"jsx": "
|
|
10
|
+
"jsx": "react-jsx",
|
|
11
11
|
"allowJs": false,
|
|
12
12
|
"target": "ES2021",
|
|
13
13
|
"allowSyntheticDefaultImports": true,
|
|
14
14
|
"esModuleInterop": true,
|
|
15
15
|
"noEmit": true,
|
|
16
16
|
"allowImportingTsExtensions": true,
|
|
17
|
-
"baseUrl": ".", // Usually the root of your project
|
|
18
17
|
"paths": {
|
|
19
|
-
"@javascript/*": ["app/javascript/*"],
|
|
20
|
-
"@views/*": ["app/views/*"]
|
|
18
|
+
"@javascript/*": ["./app/javascript/*"],
|
|
19
|
+
"@views/*": ["./app/views/*"]
|
|
21
20
|
},
|
|
22
21
|
"types": ["node"]
|
|
23
22
|
},
|
|
@@ -18,7 +18,7 @@ module Superglue
|
|
|
18
18
|
|
|
19
19
|
class_option :helper, type: :boolean
|
|
20
20
|
class_option :orm, banner: "NAME", type: :string, required: true,
|
|
21
|
-
|
|
21
|
+
desc: "ORM to generate the controller for"
|
|
22
22
|
|
|
23
23
|
class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
|
|
24
24
|
|
|
@@ -46,17 +46,17 @@ module Superglue
|
|
|
46
46
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
def permitted_params
|
|
50
|
+
attachments, others = attributes_names.partition { |name| attachments?(name) }
|
|
51
|
+
params = others.map { |name| ":#{name}" }
|
|
52
|
+
params += attachments.map { |name| "#{name}: []" }
|
|
53
|
+
params.join(", ")
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def attachments?(name)
|
|
57
|
+
attribute = attributes.find { |attr| attr.name == name }
|
|
58
|
+
attribute&.attachments?
|
|
59
|
+
end
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
end
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
1
|
import {
|
|
3
2
|
Form,
|
|
4
|
-
Layout,
|
|
5
3
|
<%- attributes.each do |attr| -%>
|
|
6
4
|
<%= js_component(attr)%>,
|
|
7
5
|
<%- end -%>
|
|
@@ -26,7 +24,7 @@ export default function <%= js_plural_table_name(:upper) %>Edit() {
|
|
|
26
24
|
const validationErrors = flash["<%= js_singular_table_name%>FormErrors"]
|
|
27
25
|
|
|
28
26
|
return (
|
|
29
|
-
|
|
27
|
+
<>
|
|
30
28
|
<Form {...form} extras={extras} validationErrors={validationErrors} data-sg-visit>
|
|
31
29
|
<%- attributes.each do |attr| -%>
|
|
32
30
|
<<%= js_component(attr)%> {...inputs.<%= attr.column_name.camelize(:lower)%>} label="<%= attr.column_name.humanize %>" errorKey="<%= attr.column_name %>" />
|
|
@@ -36,6 +34,6 @@ export default function <%= js_plural_table_name(:upper) %>Edit() {
|
|
|
36
34
|
|
|
37
35
|
<a href={<%= js_singular_table_name %>Path} data-sg-visit>Show</a>
|
|
38
36
|
<a href={<%= js_plural_table_name %>Path} data-sg-visit>Back</a>
|
|
39
|
-
|
|
37
|
+
</>
|
|
40
38
|
)
|
|
41
39
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Form, Layout } from '@javascript/components'
|
|
1
|
+
import { Form } from '@javascript/components'
|
|
3
2
|
import { useContent } from '@thoughtbot/superglue'
|
|
4
3
|
|
|
5
4
|
export default function <%= js_plural_table_name(:upper) %>Index() {
|
|
@@ -38,7 +37,7 @@ export default function <%= js_plural_table_name(:upper) %>Index() {
|
|
|
38
37
|
})
|
|
39
38
|
|
|
40
39
|
return (
|
|
41
|
-
|
|
40
|
+
<>
|
|
42
41
|
<h1><%= js_plural_table_name(:upper) %></h1>
|
|
43
42
|
|
|
44
43
|
<table>
|
|
@@ -57,6 +56,6 @@ export default function <%= js_plural_table_name(:upper) %>Index() {
|
|
|
57
56
|
</table>
|
|
58
57
|
<br />
|
|
59
58
|
<a href={new<%= js_singular_table_name(:upper) %>Path} data-sg-visit>New <%= singular_table_name.humanize %></a>
|
|
60
|
-
|
|
59
|
+
</>
|
|
61
60
|
)
|
|
62
61
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
1
|
import {
|
|
3
2
|
Form,
|
|
4
|
-
Layout,
|
|
5
3
|
<%- attributes.each do |attr| -%>
|
|
6
4
|
<%= js_component(attr)%>,
|
|
7
5
|
<%- end -%>
|
|
@@ -25,7 +23,7 @@ export default function <%= js_plural_table_name(:upper) %>New() {
|
|
|
25
23
|
const validationErrors = flash["<%= js_singular_table_name%>FormErrors"]
|
|
26
24
|
|
|
27
25
|
return (
|
|
28
|
-
|
|
26
|
+
<>
|
|
29
27
|
<Form {...form} extras={extras} validationErrors={validationErrors} data-sg-visit>
|
|
30
28
|
<%- attributes.each do |attr| -%>
|
|
31
29
|
<<%= js_component(attr)%> {...inputs.<%= attr.column_name.camelize(:lower)%>} label="<%= attr.column_name.humanize %>" errorKey="<%= attr.column_name %>" />
|
|
@@ -34,6 +32,6 @@ export default function <%= js_plural_table_name(:upper) %>New() {
|
|
|
34
32
|
</Form>
|
|
35
33
|
|
|
36
34
|
<a href={<%= js_plural_table_name %>Path} data-sg-visit>Back</a>
|
|
37
|
-
|
|
35
|
+
</>
|
|
38
36
|
)
|
|
39
37
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Layout } from '@javascript/components'
|
|
3
1
|
import { useContent } from '@thoughtbot/superglue'
|
|
4
2
|
|
|
5
3
|
export default function <%= js_plural_table_name(:upper) %>Show() {
|
|
@@ -12,7 +10,7 @@ export default function <%= js_plural_table_name(:upper) %>Show() {
|
|
|
12
10
|
} = useContent()
|
|
13
11
|
|
|
14
12
|
return (
|
|
15
|
-
|
|
13
|
+
<>
|
|
16
14
|
<%- showable_attributes.each do |attr| -%>
|
|
17
15
|
<p>
|
|
18
16
|
<strong><%= attr.column_name.humanize %>:</strong>
|
|
@@ -21,6 +19,6 @@ export default function <%= js_plural_table_name(:upper) %>Show() {
|
|
|
21
19
|
<%- end -%>
|
|
22
20
|
<a href={ edit<%= js_singular_table_name(:upper) %>Path } data-sg-visit>Edit</a>
|
|
23
21
|
<a href={ <%= js_plural_table_name %>Path } data-sg-visit>Back</a>
|
|
24
|
-
|
|
22
|
+
</>
|
|
25
23
|
)
|
|
26
24
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
1
|
import {
|
|
3
2
|
Form,
|
|
4
3
|
FormProps,
|
|
5
|
-
Layout,
|
|
6
4
|
<%- attributes.each do |attr| -%>
|
|
7
5
|
<%= js_component(attr)%>,
|
|
8
6
|
Rails<%= js_component(attr)%>Props,
|
|
@@ -40,7 +38,7 @@ export default function <%= js_plural_table_name(:upper) %>Edit() {
|
|
|
40
38
|
const validationErrors = flash["<%= js_singular_table_name%>FormErrors"]
|
|
41
39
|
|
|
42
40
|
return (
|
|
43
|
-
|
|
41
|
+
<>
|
|
44
42
|
<Form {...form} extras={extras} validationErrors={validationErrors} data-sg-visit>
|
|
45
43
|
<%- attributes.each do |attr| -%>
|
|
46
44
|
<<%= js_component(attr)%> {...inputs.<%= attr.column_name.camelize(:lower)%>} label="<%= attr.column_name.humanize %>" errorKey="<%= attr.column_name %>" />
|
|
@@ -50,6 +48,6 @@ export default function <%= js_plural_table_name(:upper) %>Edit() {
|
|
|
50
48
|
|
|
51
49
|
<a href={<%= js_singular_table_name %>Path} data-sg-visit>Show</a>
|
|
52
50
|
<a href={<%= js_plural_table_name %>Path} data-sg-visit>Back</a>
|
|
53
|
-
|
|
51
|
+
</>
|
|
54
52
|
)
|
|
55
53
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Form, FormProps, Layout } from '@javascript/components'
|
|
1
|
+
import { Form, FormProps } from '@javascript/components'
|
|
3
2
|
import { useContent } from '@thoughtbot/superglue'
|
|
4
3
|
|
|
5
4
|
type ContentProps = {
|
|
@@ -53,7 +52,7 @@ export default function <%= js_plural_table_name(:upper) %>Index() {
|
|
|
53
52
|
})
|
|
54
53
|
|
|
55
54
|
return (
|
|
56
|
-
|
|
55
|
+
<>
|
|
57
56
|
<h1><%= js_plural_table_name(:upper) %></h1>
|
|
58
57
|
|
|
59
58
|
<table>
|
|
@@ -72,6 +71,6 @@ export default function <%= js_plural_table_name(:upper) %>Index() {
|
|
|
72
71
|
</table>
|
|
73
72
|
<br />
|
|
74
73
|
<a href={new<%= js_singular_table_name(:upper) %>Path} data-sg-visit>New <%= singular_table_name.humanize %></a>
|
|
75
|
-
|
|
74
|
+
</>
|
|
76
75
|
)
|
|
77
76
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
1
|
import {
|
|
3
2
|
Form,
|
|
4
3
|
FormProps,
|
|
5
|
-
Layout,
|
|
6
4
|
<%- attributes.each do |attr| -%>
|
|
7
5
|
<%= js_component(attr)%>,
|
|
8
6
|
Rails<%= js_component(attr)%>Props,
|
|
@@ -37,7 +35,7 @@ export default function <%= js_plural_table_name(:upper) %>New() {
|
|
|
37
35
|
const validationErrors = flash["<%= js_singular_table_name%>FormErrors"]
|
|
38
36
|
|
|
39
37
|
return (
|
|
40
|
-
|
|
38
|
+
<>
|
|
41
39
|
<Form {...form} extras={extras} validationErrors={validationErrors} data-sg-visit>
|
|
42
40
|
<%- attributes.each do |attr| -%>
|
|
43
41
|
<<%= js_component(attr)%> {...inputs.<%= attr.column_name.camelize(:lower)%>} label="<%= attr.column_name.humanize %>" errorKey="<%= attr.column_name %>" />
|
|
@@ -46,6 +44,6 @@ export default function <%= js_plural_table_name(:upper) %>New() {
|
|
|
46
44
|
</Form>
|
|
47
45
|
|
|
48
46
|
<a href={<%= js_plural_table_name %>Path} data-sg-visit>Back</a>
|
|
49
|
-
|
|
47
|
+
</>
|
|
50
48
|
)
|
|
51
49
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { Layout } from '@javascript/components'
|
|
3
1
|
import { useContent } from '@thoughtbot/superglue'
|
|
4
2
|
|
|
5
3
|
type ContentProps = {
|
|
6
|
-
id:
|
|
4
|
+
id: number
|
|
7
5
|
<%- attributes.each do |attr| -%>
|
|
8
6
|
<%= attr.column_name.camelize(:lower)%>: <%= json_mappable_type(attr)%>
|
|
9
7
|
<%- end -%>
|
|
@@ -23,7 +21,7 @@ export default function <%= js_plural_table_name(:upper) %>Show() {
|
|
|
23
21
|
} = useContent<ContentProps>()
|
|
24
22
|
|
|
25
23
|
return (
|
|
26
|
-
|
|
24
|
+
<>
|
|
27
25
|
<%- showable_attributes.each do |attr| -%>
|
|
28
26
|
<p>
|
|
29
27
|
<strong><%= attr.column_name.humanize %>:</strong>
|
|
@@ -32,6 +30,6 @@ export default function <%= js_plural_table_name(:upper) %>Show() {
|
|
|
32
30
|
<%- end -%>
|
|
33
31
|
<a href={ edit<%= js_singular_table_name(:upper) %>Path } data-sg-visit>Edit</a>
|
|
34
32
|
<a href={ <%= js_plural_table_name %>Path } data-sg-visit>Back</a>
|
|
35
|
-
|
|
33
|
+
</>
|
|
36
34
|
)
|
|
37
35
|
}
|
|
@@ -13,8 +13,7 @@ module Superglue
|
|
|
13
13
|
class_option :typescript,
|
|
14
14
|
type: :boolean,
|
|
15
15
|
required: false,
|
|
16
|
-
|
|
17
|
-
desc: "Use typescript"
|
|
16
|
+
desc: "Use TypeScript. Defaults to true when tsconfig.json exists."
|
|
18
17
|
|
|
19
18
|
def create_root_folder
|
|
20
19
|
path = File.join("app/views", controller_file_path)
|
|
@@ -34,7 +33,7 @@ module Superglue
|
|
|
34
33
|
def copy_js_files
|
|
35
34
|
available_views.each do |view|
|
|
36
35
|
@action_name = view
|
|
37
|
-
if
|
|
36
|
+
if use_typescript?
|
|
38
37
|
filename = filename_with_tsx_extensions(view)
|
|
39
38
|
template "ts/" + filename, File.join("app/views", controller_file_path, filename)
|
|
40
39
|
else
|
|
@@ -44,34 +43,16 @@ module Superglue
|
|
|
44
43
|
end
|
|
45
44
|
end
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
available_views.each do |action|
|
|
49
|
-
app_js = if options["typescript"]
|
|
50
|
-
"#{app_js_path}/page_to_page_mapping.ts"
|
|
51
|
-
else
|
|
52
|
-
"#{app_js_path}/page_to_page_mapping.js"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
component_name = [plural_table_name, action].map(&:camelcase).join
|
|
56
|
-
|
|
57
|
-
js_ext = options["typescript"] ? "html.tsx" : "html.jsx"
|
|
58
|
-
|
|
59
|
-
if match_file(app_js, /pageIdentifierToPageComponent = {$/)
|
|
60
|
-
prepend_to_file app_js do
|
|
61
|
-
"import #{component_name} from '#{view_path}/#{controller_file_path}/#{action}.#{js_ext}'\n"
|
|
62
|
-
end
|
|
46
|
+
protected
|
|
63
47
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
end
|
|
48
|
+
def use_typescript?
|
|
49
|
+
if options["typescript"].nil?
|
|
50
|
+
File.exist?(File.join(destination_root, "tsconfig.json"))
|
|
51
|
+
else
|
|
52
|
+
options["typescript"]
|
|
70
53
|
end
|
|
71
54
|
end
|
|
72
55
|
|
|
73
|
-
protected
|
|
74
|
-
|
|
75
56
|
def js_component(attribute)
|
|
76
57
|
case attribute.type
|
|
77
58
|
when :string
|
|
@@ -124,14 +105,6 @@ module Superglue
|
|
|
124
105
|
%w[index edit show new]
|
|
125
106
|
end
|
|
126
107
|
|
|
127
|
-
def view_path
|
|
128
|
-
"@views"
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
def app_js_path
|
|
132
|
-
"app/javascript"
|
|
133
|
-
end
|
|
134
|
-
|
|
135
108
|
attr_reader :action_name
|
|
136
109
|
|
|
137
110
|
def attributes_names
|