terrazzo 0.4.3 → 0.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9c01981599c3325576014fd2ca44698c9436eb31cfb8ce5c35645149da5325a
4
- data.tar.gz: a68ea25983d63d93287d4f04d12b8dcae8b4b24499c32b66d5216df0d96429ce
3
+ metadata.gz: 45571db8ac5c20c765feaf02cfe7be1ab1bba1c84e77be02b8b72ca4a749875e
4
+ data.tar.gz: f221316bc43fe5d871c3603297afb9fceff9a942a07ede4bdade9186ed455598
5
5
  SHA512:
6
- metadata.gz: 87a52cb6ee07fdde5f04d375a20b82845dadf5976af86c9ad03246f6a85fc2330b28514be072780d6f6a0893028cc36ef44ddc2c39ccf989c42671b6a5989057
7
- data.tar.gz: f55b4ceceb0cc05519f15d724f52fbe3ee4dedbd022e07b22a3509cba973ef82fff601d4aaaf54461dfc8c1d3f89c86c6146ea1662b5e119b74651fb5b3108df
6
+ metadata.gz: ce93ab9c2c0a420128006d9cf67e33f083bcf5298cfbe493884970c255153e6ef71d948691ad10c5838c47cfe98c5fa46fb8de4c878eb154ae8ed29a5ff17b15
7
+ data.tar.gz: 5d98160ec096c04a93a4aa5a5a8aadb3390126e2cddf9a780f519ad16eff2d2783b2e6843d91adbb15bbb4e23c06a7d2e95ad96e615d4204860e0ed84bd6f151
@@ -191,18 +191,17 @@ module Terrazzo
191
191
  @_resource_name ||= resolver.resource_title
192
192
  end
193
193
 
194
- # Build a page identifier that matches the user's namespace, not the
195
- # engine's internal template path. The React page-to-component mapping
196
- # keys off this identifier (e.g. "admin/application/index").
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
- "#{ns}/application/#{mapped_action}"
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
- export const pageToPageMapping = {
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.json.props"
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 "../components";
5
- import { FieldRenderer } from "../fields";
6
- import { Table, TableHeader, TableBody, TableRow, TableHead, TableCell } from "../components/ui";
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 "../components";
5
+ import { SearchBar, Pagination } from "terrazzo/components";
6
6
  import { AdminCollection } from "./_collection";
7
- import { Button } from "../components/ui";
7
+ import { Button } from "terrazzo/ui";
8
8
 
9
9
  export default function AdminIndex() {
10
10
  const Layout = getLayout();
@@ -1,3 +1,3 @@
1
1
  module Terrazzo
2
- VERSION = "0.4.3"
2
+ VERSION = "0.5.0"
3
3
  end
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.3
4
+ version: 0.5.0
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