terrazzo 0.4.4 → 0.5.1
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/app/controllers/terrazzo/application_controller.rb +4 -5
- data/lib/generators/terrazzo/install/templates/page_to_page_mapping.js.erb +15 -1
- data/lib/generators/terrazzo/views/edit_generator.rb +5 -0
- data/lib/generators/terrazzo/views/index_generator.rb +4 -0
- data/lib/generators/terrazzo/views/new_generator.rb +5 -0
- data/lib/generators/terrazzo/views/page_mapping_helper.rb +29 -0
- data/lib/generators/terrazzo/views/show_generator.rb +6 -1
- data/lib/generators/terrazzo/views/templates/pages/_collection.jsx +3 -3
- data/lib/generators/terrazzo/views/templates/pages/index.jsx +2 -2
- data/lib/terrazzo/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 60ad22a772a614c37195f4695a9dd9b41b2c28b4c2516edc2ab07ffb257253e2
|
|
4
|
+
data.tar.gz: 41449e6a9e4c590db843dac6d9f0836bd32c92ee362e4a92b502207f183cd7fc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c07a8cc98e237208dede3049baf12c7edb3145c7745d69cb2996880594738bdd3ff9d1fbcd88da7d9b7e6f149abc289e1acd1f76331214016252bc2e7ec3c61
|
|
7
|
+
data.tar.gz: fe5c60e8af68eadb129ae735c266ca3958e4f88471a5692acbaea17edfa821b2809ad3c86c14ca13d9ea8790645f80eac97516c8431b12d88df328775c031cf9
|
|
@@ -191,18 +191,17 @@ module Terrazzo
|
|
|
191
191
|
@_resource_name ||= resolver.resource_title
|
|
192
192
|
end
|
|
193
193
|
|
|
194
|
-
# Build a page identifier
|
|
195
|
-
#
|
|
196
|
-
#
|
|
194
|
+
# Build a page identifier for the React page-to-component mapping.
|
|
195
|
+
# Returns a resource-specific identifier (e.g. "admin/orders/index")
|
|
196
|
+
# which the JS mapping resolves with fallback to "admin/application/index".
|
|
197
197
|
#
|
|
198
198
|
# Map create → new and update → edit so that failed validations
|
|
199
199
|
# (which render :new / :edit) resolve to the correct React component.
|
|
200
200
|
TERRAZZO_ACTION_MAP = { "create" => "new", "update" => "edit" }.freeze
|
|
201
201
|
|
|
202
202
|
def terrazzo_page_identifier
|
|
203
|
-
ns = controller_path.split("/").first
|
|
204
203
|
mapped_action = TERRAZZO_ACTION_MAP[action_name] || action_name
|
|
205
|
-
"#{
|
|
204
|
+
"#{controller_path}/#{mapped_action}"
|
|
206
205
|
end
|
|
207
206
|
|
|
208
207
|
def route_exists?(action)
|
|
@@ -3,9 +3,23 @@ import AdminShow from "../../views/<%= namespace_name %>/application/show";
|
|
|
3
3
|
import AdminNew from "../../views/<%= namespace_name %>/application/new";
|
|
4
4
|
import AdminEdit from "../../views/<%= namespace_name %>/application/edit";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const pages = {
|
|
7
7
|
'<%= namespace_name %>/application/index': AdminIndex,
|
|
8
8
|
'<%= namespace_name %>/application/show': AdminShow,
|
|
9
9
|
'<%= namespace_name %>/application/new': AdminNew,
|
|
10
10
|
'<%= namespace_name %>/application/edit': AdminEdit,
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
// Resolves resource-specific page identifiers (e.g. "admin/orders/index")
|
|
14
|
+
// with fallback to the shared application component (e.g. "admin/application/index").
|
|
15
|
+
export const pageToPageMapping = new Proxy(pages, {
|
|
16
|
+
get(target, prop) {
|
|
17
|
+
if (prop in target) return target[prop]
|
|
18
|
+
if (typeof prop === "string") {
|
|
19
|
+
const action = prop.split("/").pop()
|
|
20
|
+
const fallback = "<%= namespace_name %>/application/" + action
|
|
21
|
+
if (fallback in target) return target[fallback]
|
|
22
|
+
}
|
|
23
|
+
return undefined
|
|
24
|
+
}
|
|
25
|
+
})
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
require "rails/generators"
|
|
2
|
+
require_relative "page_mapping_helper"
|
|
2
3
|
|
|
3
4
|
module Terrazzo
|
|
4
5
|
module Generators
|
|
5
6
|
module Views
|
|
6
7
|
class EditGenerator < Rails::Generators::Base
|
|
8
|
+
include PageMappingHelper
|
|
9
|
+
|
|
7
10
|
source_root File.expand_path("templates", __dir__)
|
|
8
11
|
|
|
9
12
|
argument :resource, type: :string, required: false,
|
|
@@ -17,6 +20,7 @@ module Terrazzo
|
|
|
17
20
|
eject_json_props
|
|
18
21
|
copy_file "pages/edit.jsx", "app/views/#{namespace_name}/#{resource_path}/edit.jsx"
|
|
19
22
|
copy_file "pages/_form.jsx", "app/views/#{namespace_name}/#{resource_path}/_form.jsx"
|
|
23
|
+
register_page_mapping("edit")
|
|
20
24
|
eject_new_view if should_eject_new?
|
|
21
25
|
else
|
|
22
26
|
copy_file "pages/edit.jsx", "app/views/#{namespace_name}/application/edit.jsx"
|
|
@@ -50,6 +54,7 @@ module Terrazzo
|
|
|
50
54
|
if resource.present?
|
|
51
55
|
eject_new_json_props
|
|
52
56
|
copy_file "pages/new.jsx", "app/views/#{namespace_name}/#{resource_path}/new.jsx"
|
|
57
|
+
register_page_mapping("new")
|
|
53
58
|
else
|
|
54
59
|
copy_file "pages/new.jsx", "app/views/#{namespace_name}/application/new.jsx"
|
|
55
60
|
end
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
require "rails/generators"
|
|
2
|
+
require_relative "page_mapping_helper"
|
|
2
3
|
|
|
3
4
|
module Terrazzo
|
|
4
5
|
module Generators
|
|
5
6
|
module Views
|
|
6
7
|
class IndexGenerator < Rails::Generators::Base
|
|
8
|
+
include PageMappingHelper
|
|
9
|
+
|
|
7
10
|
source_root File.expand_path("templates", __dir__)
|
|
8
11
|
|
|
9
12
|
argument :resource, type: :string, required: false,
|
|
@@ -17,6 +20,7 @@ module Terrazzo
|
|
|
17
20
|
eject_json_props
|
|
18
21
|
copy_file "pages/index.jsx", "app/views/#{namespace_name}/#{resource_path}/index.jsx"
|
|
19
22
|
copy_file "pages/_collection.jsx", "app/views/#{namespace_name}/#{resource_path}/_collection.jsx"
|
|
23
|
+
register_page_mapping("index")
|
|
20
24
|
else
|
|
21
25
|
copy_file "pages/index.jsx", "app/views/#{namespace_name}/application/index.jsx"
|
|
22
26
|
copy_file "pages/_collection.jsx", "app/views/#{namespace_name}/application/_collection.jsx"
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
require "rails/generators"
|
|
2
|
+
require_relative "page_mapping_helper"
|
|
2
3
|
|
|
3
4
|
module Terrazzo
|
|
4
5
|
module Generators
|
|
5
6
|
module Views
|
|
6
7
|
class NewGenerator < Rails::Generators::Base
|
|
8
|
+
include PageMappingHelper
|
|
9
|
+
|
|
7
10
|
source_root File.expand_path("templates", __dir__)
|
|
8
11
|
|
|
9
12
|
argument :resource, type: :string, required: false,
|
|
@@ -17,6 +20,7 @@ module Terrazzo
|
|
|
17
20
|
eject_json_props
|
|
18
21
|
copy_file "pages/new.jsx", "app/views/#{namespace_name}/#{resource_path}/new.jsx"
|
|
19
22
|
copy_file "pages/_form.jsx", "app/views/#{namespace_name}/#{resource_path}/_form.jsx"
|
|
23
|
+
register_page_mapping("new")
|
|
20
24
|
eject_edit_view if should_eject_edit?
|
|
21
25
|
else
|
|
22
26
|
copy_file "pages/new.jsx", "app/views/#{namespace_name}/application/new.jsx"
|
|
@@ -50,6 +54,7 @@ module Terrazzo
|
|
|
50
54
|
if resource.present?
|
|
51
55
|
eject_edit_json_props
|
|
52
56
|
copy_file "pages/edit.jsx", "app/views/#{namespace_name}/#{resource_path}/edit.jsx"
|
|
57
|
+
register_page_mapping("edit")
|
|
53
58
|
else
|
|
54
59
|
copy_file "pages/edit.jsx", "app/views/#{namespace_name}/application/edit.jsx"
|
|
55
60
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module Terrazzo
|
|
2
|
+
module Generators
|
|
3
|
+
module Views
|
|
4
|
+
module PageMappingHelper
|
|
5
|
+
private
|
|
6
|
+
|
|
7
|
+
def register_page_mapping(action)
|
|
8
|
+
mapping_path = File.join(destination_root, "app/javascript/#{namespace_name}/page_to_page_mapping.js")
|
|
9
|
+
return unless File.exist?(mapping_path)
|
|
10
|
+
|
|
11
|
+
component_name = "#{resource.gsub('::', '')}#{action.capitalize}"
|
|
12
|
+
import_path = "../../views/#{namespace_name}/#{resource_path}/#{action}"
|
|
13
|
+
key = "'#{namespace_name}/#{resource_path}/#{action}'"
|
|
14
|
+
|
|
15
|
+
content = File.read(mapping_path)
|
|
16
|
+
return if content.include?(key)
|
|
17
|
+
|
|
18
|
+
# Add import before the pages object declaration
|
|
19
|
+
import_line = "import #{component_name} from \"#{import_path}\";\n"
|
|
20
|
+
inject_into_file mapping_path, import_line, before: "\nconst pages"
|
|
21
|
+
|
|
22
|
+
# Add mapping entry inside the pages object (before its closing brace)
|
|
23
|
+
entry_line = " #{key}: #{component_name},\n"
|
|
24
|
+
inject_into_file mapping_path, entry_line, before: "}\n\n//"
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
require "rails/generators"
|
|
2
|
+
require_relative "page_mapping_helper"
|
|
2
3
|
|
|
3
4
|
module Terrazzo
|
|
4
5
|
module Generators
|
|
5
6
|
module Views
|
|
6
7
|
class ShowGenerator < Rails::Generators::Base
|
|
8
|
+
include PageMappingHelper
|
|
9
|
+
|
|
7
10
|
source_root File.expand_path("templates", __dir__)
|
|
8
11
|
|
|
9
12
|
argument :resource, type: :string, required: false,
|
|
10
|
-
desc: "Resource model (e.g., User) to eject a resource-specific show
|
|
13
|
+
desc: "Resource model (e.g., User) to eject a resource-specific show view"
|
|
11
14
|
|
|
12
15
|
class_option :namespace, type: :string, default: "admin",
|
|
13
16
|
desc: "Admin namespace"
|
|
@@ -15,6 +18,8 @@ module Terrazzo
|
|
|
15
18
|
def copy_show_template
|
|
16
19
|
if resource.present?
|
|
17
20
|
eject_json_props
|
|
21
|
+
copy_file "pages/show.jsx", "app/views/#{namespace_name}/#{resource_path}/show.jsx"
|
|
22
|
+
register_page_mapping("show")
|
|
18
23
|
else
|
|
19
24
|
copy_file "pages/show.jsx", "app/views/#{namespace_name}/application/show.jsx"
|
|
20
25
|
end
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React, { useContext } from "react";
|
|
2
2
|
import { NavigationContext } from "@thoughtbot/superglue";
|
|
3
3
|
|
|
4
|
-
import { SortableHeader, CollectionItemActions } from "
|
|
5
|
-
import { FieldRenderer } from "
|
|
6
|
-
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "
|
|
4
|
+
import { SortableHeader, CollectionItemActions } from "terrazzo/components";
|
|
5
|
+
import { FieldRenderer } from "terrazzo/fields";
|
|
6
|
+
import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "terrazzo/ui";
|
|
7
7
|
|
|
8
8
|
export function AdminCollection({ table }) {
|
|
9
9
|
const { visit } = useContext(NavigationContext);
|
|
@@ -2,9 +2,9 @@ import React from "react";
|
|
|
2
2
|
import { useContent } from "@thoughtbot/superglue";
|
|
3
3
|
|
|
4
4
|
import { getLayout } from "terrazzo";
|
|
5
|
-
import { SearchBar, Pagination } from "
|
|
5
|
+
import { SearchBar, Pagination } from "terrazzo/components";
|
|
6
6
|
import { AdminCollection } from "./_collection";
|
|
7
|
-
import { Button } from "
|
|
7
|
+
import { Button } from "terrazzo/ui";
|
|
8
8
|
|
|
9
9
|
export default function AdminIndex() {
|
|
10
10
|
const Layout = getLayout();
|
data/lib/terrazzo/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: terrazzo
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Terrazzo Contributors
|
|
@@ -156,6 +156,7 @@ files:
|
|
|
156
156
|
- lib/generators/terrazzo/views/layout_generator.rb
|
|
157
157
|
- lib/generators/terrazzo/views/navigation_generator.rb
|
|
158
158
|
- lib/generators/terrazzo/views/new_generator.rb
|
|
159
|
+
- lib/generators/terrazzo/views/page_mapping_helper.rb
|
|
159
160
|
- lib/generators/terrazzo/views/show_generator.rb
|
|
160
161
|
- lib/generators/terrazzo/views/templates/components/FlashMessages.jsx
|
|
161
162
|
- lib/generators/terrazzo/views/templates/components/Layout.jsx
|