uchi 0.1.6 → 0.1.7

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 (32) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +7 -0
  3. data/app/assets/javascripts/controllers/fields/belongs_to_controller.js +130 -0
  4. data/app/assets/javascripts/controllers/fields/has_many_controller.js +146 -0
  5. data/app/assets/javascripts/uchi/application.js +804 -3
  6. data/app/assets/javascripts/uchi.js +9 -0
  7. data/app/assets/stylesheets/uchi/application.css +81 -1549
  8. data/app/assets/tailwind/uchi.css +2 -2
  9. data/app/components/uchi/field/belongs_to/edit.html.erb +73 -1
  10. data/app/components/uchi/field/belongs_to.rb +25 -25
  11. data/app/components/uchi/field/has_and_belongs_to_many/show.html.erb +1 -1
  12. data/app/components/uchi/field/has_many/edit.html.erb +86 -1
  13. data/app/components/uchi/field/has_many/show.html.erb +1 -1
  14. data/app/components/uchi/field/has_many.rb +59 -11
  15. data/app/components/uchi/ui/navigation/navigation.html.erb +1 -1
  16. data/app/components/uchi/ui/page_header/page_header.html.erb +7 -7
  17. data/app/controllers/uchi/belongs_to/associated_records_controller.rb +89 -0
  18. data/app/controllers/uchi/has_many/associated_records_controller.rb +89 -0
  19. data/app/views/layouts/uchi/_javascript.html.erb +1 -0
  20. data/app/views/layouts/uchi/_stylesheets.html.erb +1 -0
  21. data/app/views/layouts/uchi/application.html.erb +4 -4
  22. data/app/views/uchi/belongs_to/associated_records/index.html.erb +13 -0
  23. data/app/views/uchi/has_many/associated_records/index.html.erb +26 -0
  24. data/app/views/uchi/navigation/_main.html.erb +83 -0
  25. data/lib/generators/uchi/controller/controller_generator.rb +0 -4
  26. data/lib/generators/uchi/install/install_generator.rb +1 -1
  27. data/lib/uchi/field/configuration.rb +1 -1
  28. data/lib/uchi/repository.rb +13 -2
  29. data/lib/uchi/routes.rb +45 -0
  30. data/lib/uchi/version.rb +1 -1
  31. data/lib/uchi.rb +4 -1
  32. metadata +10 -1
@@ -2,8 +2,91 @@
2
2
  class="
3
3
  w-64 h-full px-3 py-4 overflow-y-auto shrink-0
4
4
  bg-neutral-secondary-medium
5
+ hidden md:block
5
6
  "
6
7
  aria-label="Main"
7
8
  >
8
9
  <%= render Uchi::Ui::Navigation.new %>
9
10
  </nav>
11
+
12
+ <div
13
+ class="md:hidden">
14
+ <button
15
+ aria-controls="main-navigation"
16
+ class="
17
+ text-body bg-transparent hover:text-heading
18
+ hover:bg-neutral-tertiary rounded-base w-9 h-9
19
+ flex items-center justify-center
20
+ "
21
+ popovertarget="main-navigation"
22
+ type="button"
23
+ >
24
+ <svg
25
+ aria-hidden="true"
26
+ class="w-6 h-6"
27
+ xmlns="http://www.w3.org/2000/svg"
28
+ width="24"
29
+ height="24"
30
+ fill="none"
31
+ viewBox="0 0 24 24"
32
+ >
33
+ <path
34
+ stroke="currentColor"
35
+ stroke-linecap="round"
36
+ stroke-width="2"
37
+ d="M5 7h14M5 12h14M5 17h14"
38
+ />
39
+ </svg>
40
+ </button>
41
+ </div>
42
+
43
+ <nav
44
+ aria-label="Main"
45
+ class="
46
+ fixed top-0 left-0 z-40 h-screen p-2
47
+ flex-col
48
+ bg-neutral-primary-soft w-80
49
+ border-e border-default
50
+ backdrop:bg-dark-backdrop/70
51
+ "
52
+ id="main-navigation"
53
+ popover
54
+ tabindex="-1"
55
+ >
56
+ <div>
57
+ <button
58
+ aria-controls="main-navigation"
59
+ class="
60
+ text-body bg-transparent hover:text-heading
61
+ hover:bg-neutral-tertiary rounded-base w-9 h-9
62
+ flex items-center justify-center
63
+ "
64
+ popovertarget="main-navigation"
65
+ type="button"
66
+ >
67
+ <svg
68
+ aria-hidden="true"
69
+ class="w-5 h-5"
70
+ fill="none"
71
+ height="24"
72
+ viewBox="0 0 24 24"
73
+ width="24"
74
+ xmlns="http://www.w3.org/2000/svg"
75
+ >
76
+ <path
77
+ stroke="currentColor"
78
+ stroke-linecap="round"
79
+ stroke-linejoin="round"
80
+ stroke-width="2"
81
+ d="M6 18 17.94 6M18 18 6.06 6"
82
+ />
83
+ </svg>
84
+
85
+ <span class="sr-only">Close menu</span>
86
+ </button>
87
+ </div>
88
+
89
+ <div class="overflow-y-auto max-h-full">
90
+ <%= render Uchi::Ui::Navigation.new %>
91
+ </div>
92
+ </nav>
@@ -8,9 +8,5 @@ module Uchi
8
8
  destination = File.join("app/controllers/uchi")
9
9
  template "controller.rb", File.join(destination, "#{plural_file_name}_controller.rb")
10
10
  end
11
-
12
- def add_route
13
- route "resources :#{plural_file_name}", namespace: :uchi
14
- end
15
11
  end
16
12
  end
@@ -7,7 +7,7 @@ module Uchi
7
7
  end
8
8
 
9
9
  def mount_engine
10
- route "mount Uchi::Engine, at: \"/uchi\""
10
+ route "Uchi.routes.mount(self)"
11
11
  end
12
12
  end
13
13
  end
@@ -5,7 +5,7 @@ module Uchi
5
5
  module Configuration
6
6
  class Unset; end
7
7
 
8
- DEFAULT_READER = ->(record, field_name) { record.public_send(field_name) }
8
+ DEFAULT_READER = ->(record, field_name) { record&.public_send(field_name) }
9
9
 
10
10
  def initialize(*args)
11
11
  super
@@ -12,6 +12,13 @@ module Uchi
12
12
  }
13
13
  end
14
14
 
15
+ # Returns the "name" of the controller that handles requests for this
16
+ # repository. Note that this is different from the controllers class name
17
+ # and is intended for generating URLs.
18
+ def controller_name
19
+ model_param_key.pluralize
20
+ end
21
+
15
22
  # Returns the repository for the given model, or nil if none is found.
16
23
  def for_model(model)
17
24
  all.find { |repository| repository.model.to_s == model.to_s }
@@ -21,6 +28,10 @@ module Uchi
21
28
  def model
22
29
  @model ||= name.demodulize.constantize
23
30
  end
31
+
32
+ def model_param_key
33
+ model.model_name.param_key
34
+ end
24
35
  end
25
36
 
26
37
  # Returns a new, unsaved instance of the model this repository manages.
@@ -32,7 +43,7 @@ module Uchi
32
43
  # repository. Note that this is different from the controllers class name
33
44
  # and is intended for generating URLs.
34
45
  def controller_name
35
- model_param_key.pluralize
46
+ self.class.controller_name
36
47
  end
37
48
 
38
49
  def default_sort_order
@@ -104,7 +115,7 @@ module Uchi
104
115
  end
105
116
 
106
117
  def model_param_key
107
- model.model_name.param_key
118
+ self.class.model_param_key
108
119
  end
109
120
 
110
121
  # Returns an instance of Uchi::Repository::Routes for this repository,
@@ -0,0 +1,45 @@
1
+ module Uchi
2
+ class Routes
3
+ # Mounts the Uchi engine routes onto the host application's routes.
4
+ #
5
+ # Example usage in host application's routes.rb that install Uchi at /uchi:
6
+ #
7
+ # Rails.application.routes.draw do
8
+ # Uchi.routes.mount(self)
9
+ # end
10
+ def mount(host_routes, at: default_at)
11
+ host_routes.mount(
12
+ Uchi::Engine,
13
+ at: at
14
+ )
15
+
16
+ draw_repository_routes(host_routes, at: at)
17
+ end
18
+
19
+ def draw_root_route(routes, repository:, at: default_at)
20
+ return unless repository
21
+
22
+ routes.namespace(at) do
23
+ routes.root to: "#{repository.controller_name}#index"
24
+ end
25
+ end
26
+
27
+ def draw_repository_routes(routes, at: default_at)
28
+ repositories = Uchi::Repository.all
29
+ repositories.each do |repository_class|
30
+ resources_name = repository_class.controller_name
31
+ routes.namespace(at) do
32
+ routes.resources(resources_name)
33
+ end
34
+ end
35
+
36
+ draw_root_route(routes, at: at, repository: repositories.first)
37
+ end
38
+
39
+ private
40
+
41
+ def default_at
42
+ "uchi"
43
+ end
44
+ end
45
+ end
data/lib/uchi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uchi
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.7"
5
5
  end
data/lib/uchi.rb CHANGED
@@ -12,9 +12,12 @@ require "uchi/action_response"
12
12
  require "uchi/field"
13
13
  require "uchi/i18n"
14
14
  require "uchi/repository"
15
+ require "uchi/routes"
15
16
  require "uchi/sort_order"
16
17
  require "uchi/repository/translate"
17
18
 
18
19
  module Uchi
19
- # Your code goes here...
20
+ def self.routes
21
+ @routes ||= Routes.new
22
+ end
20
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uchi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jakob Skjerning
@@ -63,6 +63,8 @@ extra_rdoc_files: []
63
63
  files:
64
64
  - README.md
65
65
  - app/assets/config/uchi_manifest.js
66
+ - app/assets/javascripts/controllers/fields/belongs_to_controller.js
67
+ - app/assets/javascripts/controllers/fields/has_many_controller.js
66
68
  - app/assets/javascripts/uchi.js
67
69
  - app/assets/javascripts/uchi/application.js
68
70
  - app/assets/stylesheets/uchi/application.css
@@ -211,13 +213,19 @@ files:
211
213
  - app/components/uchi/ui/spinner/spinner.html.erb
212
214
  - app/controllers/uchi/actions/executions_controller.rb
213
215
  - app/controllers/uchi/application_controller.rb
216
+ - app/controllers/uchi/belongs_to/associated_records_controller.rb
214
217
  - app/controllers/uchi/controller.rb
218
+ - app/controllers/uchi/has_many/associated_records_controller.rb
215
219
  - app/controllers/uchi/repository_controller.rb
216
220
  - app/helpers/uchi/application_helper.rb
217
221
  - app/jobs/uchi/application_job.rb
218
222
  - app/mailers/uchi/application_mailer.rb
219
223
  - app/views/layouts/uchi/_flash_messages.html.erb
224
+ - app/views/layouts/uchi/_javascript.html.erb
225
+ - app/views/layouts/uchi/_stylesheets.html.erb
220
226
  - app/views/layouts/uchi/application.html.erb
227
+ - app/views/uchi/belongs_to/associated_records/index.html.erb
228
+ - app/views/uchi/has_many/associated_records/index.html.erb
221
229
  - app/views/uchi/navigation/_main.html.erb
222
230
  - app/views/uchi/repository/edit.html.erb
223
231
  - app/views/uchi/repository/index.html.erb
@@ -257,6 +265,7 @@ files:
257
265
  - lib/uchi/repository.rb
258
266
  - lib/uchi/repository/routes.rb
259
267
  - lib/uchi/repository/translate.rb
268
+ - lib/uchi/routes.rb
260
269
  - lib/uchi/sort_order.rb
261
270
  - lib/uchi/version.rb
262
271
  - uchi.gemspec