avo 2.17.0 → 2.17.1.pre.1.zeitwerk.eager.load.dir
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of avo might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Gemfile +3 -1
- data/Gemfile.lock +41 -8
- data/app/components/avo/panel_component.html.erb +2 -4
- data/app/components/avo/panel_component.rb +2 -4
- data/app/components/avo/tab_switcher_component.html.erb +1 -1
- data/app/components/avo/tab_switcher_component.rb +2 -0
- data/app/controllers/avo/associations_controller.rb +14 -0
- data/app/helpers/avo/application_helper.rb +4 -0
- data/avo.gemspec +2 -2
- data/config/i18n-tasks.yml +159 -0
- data/config/master.key +1 -0
- data/config/routes.rb +1 -1
- data/lib/avo/app.rb +6 -0
- data/lib/avo/dynamic_router.rb +19 -15
- data/lib/avo/engine.rb +9 -0
- data/lib/avo/services/authorization_service.rb +17 -3
- data/lib/avo/version.rb +1 -1
- data/lib/generators/avo/templates/locales/avo.en.yml +107 -106
- data/lib/generators/avo/templates/locales/avo.fr.yml +107 -107
- data/lib/generators/avo/templates/locales/avo.nb.yml +111 -110
- data/lib/generators/avo/templates/locales/avo.nn.yml +111 -110
- data/lib/generators/avo/templates/locales/avo.pt-BR.yml +109 -84
- data/lib/generators/avo/templates/locales/avo.ro.yml +109 -81
- data/lib/generators/avo/templates/locales/avo.tr.yml +107 -107
- data/public/avo-assets/avo.base.css +12 -6
- metadata +10 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ce480a1789187841a9bcca025afdb3cfab7f153ba672409d23e7f8cefdfbfa3
|
4
|
+
data.tar.gz: 5737e02acb4959d6a5313dc9534ebb7a6903efeba06b1b923a9902ceaf64c2ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c6dd37752b3279c05f68bd1c78751303b517339ecd06c93d35b33d1384527556e046a5680bff507f48a37f8d7a737e9687692d88623e39631d33cbe1266765f
|
7
|
+
data.tar.gz: b29f21327fb24141d7acb656f031decf4320e19944eb7e47d47d5d9fd6bf72148af7a46cc2ec7e0042717940b64d748ad176b0eab2e8f13145020338751c51dc
|
data/Gemfile
CHANGED
@@ -90,6 +90,7 @@ end
|
|
90
90
|
group :development, :test do
|
91
91
|
gem "awesome_print"
|
92
92
|
gem "faker", require: false
|
93
|
+
gem "i18n-tasks", "~> 1.0.12"
|
93
94
|
end
|
94
95
|
|
95
96
|
group :test do
|
@@ -113,7 +114,7 @@ end
|
|
113
114
|
gem "rubocop"
|
114
115
|
gem "rubocop-shopify", require: false
|
115
116
|
|
116
|
-
gem "zeitwerk", "~> 2.3"
|
117
|
+
# gem "zeitwerk", "~> 2.3"
|
117
118
|
|
118
119
|
gem "httparty"
|
119
120
|
|
@@ -152,3 +153,4 @@ gem 'acts-as-taggable-on', '~> 9.0'
|
|
152
153
|
gem "bundler-integrity", "~> 1.0"
|
153
154
|
|
154
155
|
gem 'erb-formatter'
|
156
|
+
gem "zeitwerk", github: "fxn/zeitwerk"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,13 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/fxn/zeitwerk.git
|
3
|
+
revision: 50515063d309bf50cb1fdcffa7558ca26d124b3f
|
4
|
+
specs:
|
5
|
+
zeitwerk (2.6.1)
|
6
|
+
|
1
7
|
PATH
|
2
8
|
remote: .
|
3
9
|
specs:
|
4
|
-
avo (2.17.
|
10
|
+
avo (2.17.1.pre.1.zeitwerk.eager.load.dir)
|
5
11
|
active_link_to
|
6
12
|
addressable
|
7
13
|
breadcrumbs_on_rails
|
@@ -17,8 +23,7 @@ PATH
|
|
17
23
|
pundit
|
18
24
|
rails (>= 6.0)
|
19
25
|
turbo-rails
|
20
|
-
view_component
|
21
|
-
zeitwerk
|
26
|
+
view_component
|
22
27
|
|
23
28
|
GEM
|
24
29
|
remote: https://rubygems.org/
|
@@ -119,6 +124,13 @@ GEM
|
|
119
124
|
aws-sigv4 (1.5.1)
|
120
125
|
aws-eventstream (~> 1, >= 1.0.2)
|
121
126
|
bcrypt (3.1.18)
|
127
|
+
better_html (2.0.1)
|
128
|
+
actionview (>= 6.0)
|
129
|
+
activesupport (>= 6.0)
|
130
|
+
ast (~> 2.0)
|
131
|
+
erubi (~> 1.4)
|
132
|
+
parser (>= 2.4)
|
133
|
+
smart_properties
|
122
134
|
bindex (0.8.1)
|
123
135
|
bootsnap (1.13.0)
|
124
136
|
msgpack (~> 1.2)
|
@@ -189,6 +201,7 @@ GEM
|
|
189
201
|
groupdate (6.1.0)
|
190
202
|
activesupport (>= 5.2)
|
191
203
|
hashdiff (1.0.1)
|
204
|
+
highline (2.0.3)
|
192
205
|
hightop (0.3.0)
|
193
206
|
activesupport (>= 5.2)
|
194
207
|
hotwire-livereload (1.2.2)
|
@@ -200,6 +213,17 @@ GEM
|
|
200
213
|
multi_xml (>= 0.5.2)
|
201
214
|
i18n (1.12.0)
|
202
215
|
concurrent-ruby (~> 1.0)
|
216
|
+
i18n-tasks (1.0.12)
|
217
|
+
activesupport (>= 4.0.2)
|
218
|
+
ast (>= 2.1.0)
|
219
|
+
better_html (>= 1.0, < 3.0)
|
220
|
+
erubi
|
221
|
+
highline (>= 2.0.0)
|
222
|
+
i18n
|
223
|
+
parser (>= 2.2.3.0)
|
224
|
+
rails-i18n
|
225
|
+
rainbow (>= 2.2.2, < 4.0)
|
226
|
+
terminal-table (>= 1.5.1)
|
203
227
|
image_processing (1.12.2)
|
204
228
|
mini_magick (>= 4.9.5, < 5)
|
205
229
|
ruby-vips (>= 2.0.17, < 3)
|
@@ -249,6 +273,8 @@ GEM
|
|
249
273
|
nokogiri (1.13.8)
|
250
274
|
mini_portile2 (~> 2.8.0)
|
251
275
|
racc (~> 1.4)
|
276
|
+
nokogiri (1.13.8-x86_64-linux)
|
277
|
+
racc (~> 1.4)
|
252
278
|
orm_adapter (0.5.0)
|
253
279
|
pagy (5.10.1)
|
254
280
|
activesupport
|
@@ -289,6 +315,9 @@ GEM
|
|
289
315
|
nokogiri (>= 1.6)
|
290
316
|
rails-html-sanitizer (1.4.3)
|
291
317
|
loofah (~> 2.3)
|
318
|
+
rails-i18n (7.0.5)
|
319
|
+
i18n (>= 0.7, < 2)
|
320
|
+
railties (>= 6.0.0, < 8)
|
292
321
|
railties (6.1.6.1)
|
293
322
|
actionpack (= 6.1.6.1)
|
294
323
|
activesupport (= 6.1.6.1)
|
@@ -350,7 +379,7 @@ GEM
|
|
350
379
|
ruby-vips (2.1.4)
|
351
380
|
ffi (~> 1.12)
|
352
381
|
rubyzip (2.3.2)
|
353
|
-
selenium-webdriver (4.
|
382
|
+
selenium-webdriver (4.5.0)
|
354
383
|
childprocess (>= 0.5, < 5.0)
|
355
384
|
rexml (~> 3.2, >= 3.2.5)
|
356
385
|
rubyzip (>= 1.2.2, < 3.0)
|
@@ -365,6 +394,7 @@ GEM
|
|
365
394
|
simplecov-html (0.12.3)
|
366
395
|
simplecov_json_formatter (0.1.4)
|
367
396
|
sixarm_ruby_unaccent (1.2.0)
|
397
|
+
smart_properties (1.17.0)
|
368
398
|
spring (4.0.0)
|
369
399
|
spring-commands-rspec (1.0.4)
|
370
400
|
spring (>= 0.9.1)
|
@@ -378,6 +408,8 @@ GEM
|
|
378
408
|
standard (1.16.0)
|
379
409
|
rubocop (= 1.35.0)
|
380
410
|
rubocop-performance (= 1.14.3)
|
411
|
+
terminal-table (3.0.2)
|
412
|
+
unicode-display_width (>= 1.1.1, < 3)
|
381
413
|
test-prof (1.0.10)
|
382
414
|
thor (1.2.1)
|
383
415
|
timeout (0.3.0)
|
@@ -388,8 +420,9 @@ GEM
|
|
388
420
|
tzinfo (2.0.5)
|
389
421
|
concurrent-ruby (~> 1.0)
|
390
422
|
unicode-display_width (2.2.0)
|
391
|
-
view_component (2.
|
423
|
+
view_component (2.74.1)
|
392
424
|
activesupport (>= 5.0.0, < 8.0)
|
425
|
+
concurrent-ruby (~> 1.0)
|
393
426
|
method_source (~> 1.0)
|
394
427
|
warden (1.2.9)
|
395
428
|
rack (>= 2.0.9)
|
@@ -398,7 +431,7 @@ GEM
|
|
398
431
|
activemodel (>= 6.0.0)
|
399
432
|
bindex (>= 0.4.0)
|
400
433
|
railties (>= 6.0.0)
|
401
|
-
webdrivers (5.
|
434
|
+
webdrivers (5.2.0)
|
402
435
|
nokogiri (~> 1.6)
|
403
436
|
rubyzip (>= 1.3.0)
|
404
437
|
selenium-webdriver (~> 4.0)
|
@@ -412,7 +445,6 @@ GEM
|
|
412
445
|
websocket-extensions (0.1.5)
|
413
446
|
xpath (3.2.0)
|
414
447
|
nokogiri (~> 1.8)
|
415
|
-
zeitwerk (2.6.0)
|
416
448
|
|
417
449
|
PLATFORMS
|
418
450
|
ruby
|
@@ -452,6 +484,7 @@ DEPENDENCIES
|
|
452
484
|
hotwire-livereload (~> 1.1)
|
453
485
|
htmlbeautifier
|
454
486
|
httparty
|
487
|
+
i18n-tasks (~> 1.0.12)
|
455
488
|
image_processing (~> 1.12)
|
456
489
|
iso
|
457
490
|
jsbundling-rails
|
@@ -482,7 +515,7 @@ DEPENDENCIES
|
|
482
515
|
web-console (>= 3.3.0)
|
483
516
|
webdrivers
|
484
517
|
webmock
|
485
|
-
zeitwerk
|
518
|
+
zeitwerk!
|
486
519
|
|
487
520
|
BUNDLED WITH
|
488
521
|
2.3.5
|
@@ -25,10 +25,8 @@
|
|
25
25
|
<% end %>
|
26
26
|
<% if body? %>
|
27
27
|
<div class="flex flex-col sm:flex-row space-y-4 sm:space-y-0 sm:gap-4 w-full">
|
28
|
-
<div class="flex-1 overflow-auto <% if sidebar? %> w-2/3 <% end %>">
|
29
|
-
|
30
|
-
<%= body %>
|
31
|
-
</div>
|
28
|
+
<div class="relative flex-1 overflow-auto <%= white_panel_classes %> <%= @body_classes %> <% if sidebar? %> w-2/3 <% end %>">
|
29
|
+
<%= body %>
|
32
30
|
</div>
|
33
31
|
<% if sidebar? %>
|
34
32
|
<div class="w-full sm:w-1/3 flex-shrink-0 h-full <%= white_panel_classes %>">
|
@@ -5,6 +5,8 @@ class Avo::PanelComponent < ViewComponent::Base
|
|
5
5
|
attr_reader :name
|
6
6
|
attr_reader :classes
|
7
7
|
|
8
|
+
delegate :white_panel_classes, to: :helpers
|
9
|
+
|
8
10
|
renders_one :tools
|
9
11
|
renders_one :body
|
10
12
|
renders_one :sidebar
|
@@ -26,10 +28,6 @@ class Avo::PanelComponent < ViewComponent::Base
|
|
26
28
|
|
27
29
|
private
|
28
30
|
|
29
|
-
def white_panel_classes
|
30
|
-
"bg-white rounded shadow"
|
31
|
-
end
|
32
|
-
|
33
31
|
def data_attributes
|
34
32
|
@data.merge({"panel-index": @index})
|
35
33
|
end
|
@@ -20,7 +20,7 @@
|
|
20
20
|
</div>
|
21
21
|
</div>
|
22
22
|
<% else %>
|
23
|
-
<div class="flex flex-wrap gap-2
|
23
|
+
<div class="flex flex-wrap gap-2 p-2 <%= white_panel_classes %>" data-target="tab-switcher" data-style="pills">
|
24
24
|
<% visible_items.each do |tab| %>
|
25
25
|
<%= a_link tab_path(tab),
|
26
26
|
color: selected?(tab) ? :primary : :gray,
|
@@ -11,6 +11,8 @@ class Avo::TabSwitcherComponent < Avo::BaseComponent
|
|
11
11
|
attr_reader :view
|
12
12
|
attr_reader :style
|
13
13
|
|
14
|
+
delegate :white_panel_classes, to: :helpers
|
15
|
+
|
14
16
|
def initialize(resource:, group:, current_tab:, active_tab_name:, view:, style:)
|
15
17
|
@active_tab_name = active_tab_name
|
16
18
|
@resource = resource
|
@@ -5,6 +5,7 @@ module Avo
|
|
5
5
|
before_action :set_model, only: [:show, :index, :new, :create, :destroy, :order]
|
6
6
|
before_action :set_related_resource_name
|
7
7
|
before_action :set_related_resource, only: [:show, :index, :new, :create, :destroy, :order]
|
8
|
+
before_action :set_related_authorization
|
8
9
|
before_action :set_reflection_field
|
9
10
|
before_action :hydrate_related_resource, only: [:show, :index, :create, :destroy, :order]
|
10
11
|
before_action :set_related_model, only: [:show, :order]
|
@@ -152,5 +153,18 @@ module Avo
|
|
152
153
|
def authorize_detach_action
|
153
154
|
authorize_if_defined "detach_#{@field.id}?"
|
154
155
|
end
|
156
|
+
|
157
|
+
private
|
158
|
+
|
159
|
+
def set_related_authorization
|
160
|
+
@authorization = if related_resource
|
161
|
+
t = related_resource.authorization(user: _current_user)
|
162
|
+
puts ["1->", t, related_resource].inspect
|
163
|
+
t
|
164
|
+
else
|
165
|
+
puts ["2->"].inspect
|
166
|
+
Services::AuthorizationService.new _current_user
|
167
|
+
end
|
168
|
+
end
|
155
169
|
end
|
156
170
|
end
|
data/avo.gemspec
CHANGED
@@ -34,13 +34,13 @@ Gem::Specification.new do |spec|
|
|
34
34
|
|
35
35
|
spec.add_dependency "rails", ">= 6.0"
|
36
36
|
spec.add_dependency "pagy"
|
37
|
-
spec.add_dependency "zeitwerk"
|
37
|
+
# spec.add_dependency "zeitwerk", git: "https://github.com/fxn/zeitwerk"
|
38
38
|
spec.add_dependency "countries"
|
39
39
|
spec.add_dependency "pundit"
|
40
40
|
spec.add_dependency "httparty"
|
41
41
|
spec.add_dependency "active_link_to"
|
42
42
|
spec.add_dependency "image_processing"
|
43
|
-
spec.add_dependency "view_component"
|
43
|
+
spec.add_dependency "view_component"
|
44
44
|
spec.add_dependency "turbo-rails"
|
45
45
|
spec.add_dependency "addressable"
|
46
46
|
spec.add_dependency "meta-tags"
|
@@ -0,0 +1,159 @@
|
|
1
|
+
# i18n-tasks finds and manages missing and unused translations: https://github.com/glebm/i18n-tasks
|
2
|
+
|
3
|
+
# The "main" locale.
|
4
|
+
base_locale: en
|
5
|
+
## All available locales are inferred from the data by default. Alternatively, specify them explicitly:
|
6
|
+
locales: [en, fr, nb, nn, pt-BR, ro, tr]
|
7
|
+
## Reporting locale, default: en. Available: en, ru.
|
8
|
+
# internal_locale: en
|
9
|
+
|
10
|
+
# Read and write translations.
|
11
|
+
data:
|
12
|
+
## Translations are read from the file system. Supported format: YAML, JSON.
|
13
|
+
## Provide a custom adapter:
|
14
|
+
# adapter: I18n::Tasks::Data::FileSystem
|
15
|
+
|
16
|
+
# Locale files or `File.find` patterns where translations are read from:
|
17
|
+
read:
|
18
|
+
## Default:
|
19
|
+
# - config/locales/%{locale}.yml
|
20
|
+
## More files:
|
21
|
+
- lib/generators/avo/templates/locales/**/*.%{locale}.yml
|
22
|
+
|
23
|
+
# Locale files to write new keys to, based on a list of key pattern => file rules. Matched from top to bottom:
|
24
|
+
# `i18n-tasks normalize -p` will force move the keys according to these rules
|
25
|
+
write:
|
26
|
+
## For example, write devise and simple form keys to their respective files:
|
27
|
+
# - ['{devise, simple_form}.*', 'config/locales/\1.%{locale}.yml']
|
28
|
+
## Catch-all default:
|
29
|
+
# - config/locales/%{locale}.yml
|
30
|
+
|
31
|
+
# External locale data (e.g. gems).
|
32
|
+
# This data is not considered unused and is never written to.
|
33
|
+
external:
|
34
|
+
## Example (replace %#= with %=):
|
35
|
+
# - "<%#= %x[bundle info vagrant --path].chomp %>/templates/locales/%{locale}.yml"
|
36
|
+
|
37
|
+
## Specify the router (see Readme for details). Valid values: conservative_router, pattern_router, or a custom class.
|
38
|
+
# router: conservative_router
|
39
|
+
|
40
|
+
yaml:
|
41
|
+
write:
|
42
|
+
# do not wrap lines at 80 characters
|
43
|
+
line_width: -1
|
44
|
+
|
45
|
+
## Pretty-print JSON:
|
46
|
+
# json:
|
47
|
+
# write:
|
48
|
+
# indent: ' '
|
49
|
+
# space: ' '
|
50
|
+
# object_nl: "\n"
|
51
|
+
# array_nl: "\n"
|
52
|
+
|
53
|
+
# Find translate calls
|
54
|
+
search:
|
55
|
+
## Paths or `File.find` patterns to search in:
|
56
|
+
# paths:
|
57
|
+
# - app/
|
58
|
+
|
59
|
+
## Root directories for relative keys resolution.
|
60
|
+
# relative_roots:
|
61
|
+
# - app/controllers
|
62
|
+
# - app/helpers
|
63
|
+
# - app/mailers
|
64
|
+
# - app/presenters
|
65
|
+
# - app/views
|
66
|
+
|
67
|
+
## Directories where method names which should not be part of a relative key resolution.
|
68
|
+
# By default, if a relative translation is used inside a method, the name of the method will be considered part of the resolved key.
|
69
|
+
# Directories listed here will not consider the name of the method part of the resolved key
|
70
|
+
#
|
71
|
+
# relative_exclude_method_name_paths:
|
72
|
+
# -
|
73
|
+
|
74
|
+
## Files or `File.fnmatch` patterns to exclude from search. Some files are always excluded regardless of this setting:
|
75
|
+
## *.jpg *.jpeg *.png *.gif *.svg *.ico *.eot *.otf *.ttf *.woff *.woff2 *.pdf *.css *.sass *.scss *.less
|
76
|
+
## *.yml *.json *.zip *.tar.gz *.swf *.flv *.mp3 *.wav *.flac *.webm *.mp4 *.ogg *.opus *.webp *.map *.xlsx
|
77
|
+
exclude:
|
78
|
+
- app/assets/images
|
79
|
+
- app/assets/fonts
|
80
|
+
- app/assets/videos
|
81
|
+
- app/assets/builds
|
82
|
+
|
83
|
+
## Alternatively, the only files or `File.fnmatch patterns` to search in `paths`:
|
84
|
+
## If specified, this settings takes priority over `exclude`, but `exclude` still applies.
|
85
|
+
# only: ["*.rb", "*.html.slim"]
|
86
|
+
|
87
|
+
## If `strict` is `false`, guess usages such as t("categories.#{category}.title"). The default is `true`.
|
88
|
+
# strict: true
|
89
|
+
|
90
|
+
## Allows adding ast_matchers for finding translations using the AST-scanners
|
91
|
+
## The available matchers are:
|
92
|
+
## - RailsModelMatcher
|
93
|
+
## Matches ActiveRecord translations like
|
94
|
+
## User.human_attribute_name(:email) and User.model_name.human
|
95
|
+
##
|
96
|
+
## To implement your own, please see `I18n::Tasks::Scanners::AstMatchers::BaseMatcher`.
|
97
|
+
<%# I18n::Tasks.add_ast_matcher('I18n::Tasks::Scanners::AstMatchers::RailsModelMatcher') %>
|
98
|
+
|
99
|
+
## Multiple scanners can be used. Their results are merged.
|
100
|
+
## The options specified above are passed down to each scanner. Per-scanner options can be specified as well.
|
101
|
+
## See this example of a custom scanner: https://github.com/glebm/i18n-tasks/wiki/A-custom-scanner-example
|
102
|
+
|
103
|
+
## Translation Services
|
104
|
+
# translation:
|
105
|
+
# # Google Translate
|
106
|
+
# # Get an API key and set billing info at https://code.google.com/apis/console to use Google Translate
|
107
|
+
# google_translate_api_key: "AbC-dEf5"
|
108
|
+
# # DeepL Pro Translate
|
109
|
+
# # Get an API key and subscription at https://www.deepl.com/pro to use DeepL Pro
|
110
|
+
# deepl_api_key: "48E92789-57A3-466A-9959-1A1A1A1A1A1A"
|
111
|
+
# # deepl_host: "https://api.deepl.com"
|
112
|
+
# # deepl_version: "v2"
|
113
|
+
|
114
|
+
## Do not consider these keys missing:
|
115
|
+
ignore_missing:
|
116
|
+
- 'avo.field_translations.file'
|
117
|
+
- 'avo.field_translations.people'
|
118
|
+
- 'avo.number_of_items'
|
119
|
+
- 'avo.resource_translations.user'
|
120
|
+
- 'avo.x_items_more'
|
121
|
+
|
122
|
+
# - 'errors.messages.{accepted,blank,invalid,too_short,too_long}'
|
123
|
+
# - '{devise,simple_form}.*'
|
124
|
+
|
125
|
+
## Consider these keys used:
|
126
|
+
# ignore_unused:
|
127
|
+
# - 'activerecord.attributes.*'
|
128
|
+
# - '{devise,kaminari,will_paginate}.*'
|
129
|
+
# - 'simple_form.{yes,no}'
|
130
|
+
# - 'simple_form.{placeholders,hints,labels}.*'
|
131
|
+
# - 'simple_form.{error_notification,required}.:'
|
132
|
+
|
133
|
+
## Exclude these keys from the `i18n-tasks eq-base' report:
|
134
|
+
# ignore_eq_base:
|
135
|
+
# all:
|
136
|
+
# - common.ok
|
137
|
+
# fr,es:
|
138
|
+
# - common.brand
|
139
|
+
|
140
|
+
## Exclude these keys from the `i18n-tasks check-consistent-interpolations` report:
|
141
|
+
# ignore_inconsistent_interpolations:
|
142
|
+
# - 'activerecord.attributes.*'
|
143
|
+
|
144
|
+
## Ignore these keys completely:
|
145
|
+
# ignore:
|
146
|
+
# - kaminari.*
|
147
|
+
|
148
|
+
## Sometimes, it isn't possible for i18n-tasks to match the key correctly,
|
149
|
+
## e.g. in case of a relative key defined in a helper method.
|
150
|
+
## In these cases you can use the built-in PatternMapper to map patterns to keys, e.g.:
|
151
|
+
#
|
152
|
+
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
|
153
|
+
# only: %w(*.html.haml *.html.slim),
|
154
|
+
# patterns: [['= title\b', '.page_title']] %>
|
155
|
+
#
|
156
|
+
# The PatternMapper can also match key literals via a special %{key} interpolation, e.g.:
|
157
|
+
#
|
158
|
+
# <%# I18n::Tasks.add_scanner 'I18n::Tasks::Scanners::PatternMapper',
|
159
|
+
# patterns: [['\bSpree\.t[( ]\s*%{key}', 'spree.%{key}']] %>
|
data/config/master.key
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2aeb23d82b909d9c6b5abb62f7058c2a
|
data/config/routes.rb
CHANGED
@@ -33,7 +33,7 @@ Avo::Engine.routes.draw do
|
|
33
33
|
|
34
34
|
# Generate resource routes as below:
|
35
35
|
# resources :posts
|
36
|
-
Avo::DynamicRouter.routes
|
36
|
+
Avo::DynamicRouter.routes
|
37
37
|
|
38
38
|
# Associations
|
39
39
|
get "/:resource_name/:id/:related_name/new", to: "associations#new", as: "associations_new"
|
data/lib/avo/app.rb
CHANGED
@@ -17,6 +17,12 @@ module Avo
|
|
17
17
|
class_attribute :error_messages
|
18
18
|
|
19
19
|
class << self
|
20
|
+
def eager_load_resources
|
21
|
+
Rails.autoloaders.each do |loader|
|
22
|
+
loader.eager_load_dir(Rails.root.join("app", "avo", "resources").to_s)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
20
26
|
def boot
|
21
27
|
init_fields
|
22
28
|
|
data/lib/avo/dynamic_router.rb
CHANGED
@@ -1,21 +1,25 @@
|
|
1
1
|
module Avo
|
2
|
-
|
3
|
-
def self.routes
|
4
|
-
|
2
|
+
class DynamicRouter
|
3
|
+
def self.routes
|
4
|
+
Avo::Engine.routes.draw do
|
5
|
+
scope "resources", as: "resources" do
|
6
|
+
Avo::App.eager_load_resources
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
8
|
+
BaseResource.descendants
|
9
|
+
.select do |resource|
|
10
|
+
resource != :BaseResource
|
11
|
+
end
|
12
|
+
.select do |resource|
|
13
|
+
resource.is_a? Class
|
14
|
+
end
|
15
|
+
# .select do |resource|
|
16
|
+
# resource.model_class.present?
|
17
|
+
# end
|
18
|
+
.map do |resource|
|
19
|
+
resources resource.new.route_key
|
20
|
+
end
|
18
21
|
end
|
22
|
+
end
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
data/lib/avo/engine.rb
CHANGED
@@ -17,6 +17,15 @@ module Avo
|
|
17
17
|
::Avo::App.boot
|
18
18
|
end
|
19
19
|
|
20
|
+
# initializer "eager load resources" do |app|
|
21
|
+
# # puts ["app.root->", app.root.join('app', 'avo', 'resources')].inspect
|
22
|
+
# app.config.to_prepare do
|
23
|
+
# puts ["app.config.to_prepare->", app.root.join('app', 'avo', 'resources')].inspect
|
24
|
+
# Rails.autoloaders.main.eager_load_dir(app.root.join('app', 'avo', 'resources'))
|
25
|
+
# puts [".to_prepare BaseResource.descendants->", BaseResource.descendants].inspect
|
26
|
+
# end
|
27
|
+
# end
|
28
|
+
|
20
29
|
initializer "avo.autoload" do |app|
|
21
30
|
[
|
22
31
|
["app", "avo", "fields"],
|
@@ -49,10 +49,15 @@ module Avo
|
|
49
49
|
return model if skip_authorization || user.nil?
|
50
50
|
|
51
51
|
begin
|
52
|
-
|
53
|
-
|
52
|
+
# Try and figure out the scope from a given policy or auto-detected one
|
53
|
+
scope_from_policy_class = scope_for_policy_class(policy_class)
|
54
|
+
|
55
|
+
# If we discover one use it.
|
56
|
+
# Else fallback to pundit.
|
57
|
+
if scope_from_policy_class.present?
|
58
|
+
scope_from_policy_class.new(user, model).resolve
|
54
59
|
else
|
55
|
-
Pundit.policy_scope!
|
60
|
+
Pundit.policy_scope!(user, model)
|
56
61
|
end
|
57
62
|
rescue Pundit::NotDefinedError => e
|
58
63
|
return model unless Avo.configuration.raise_error_on_missing_policy
|
@@ -88,6 +93,15 @@ module Avo
|
|
88
93
|
raise error
|
89
94
|
end
|
90
95
|
end
|
96
|
+
|
97
|
+
# Fetches the scope for a given policy
|
98
|
+
def scope_for_policy_class(policy_class = nil)
|
99
|
+
return if policy_class.blank?
|
100
|
+
|
101
|
+
if policy_class.present? && defined?(policy_class::Scope)
|
102
|
+
policy_class::Scope
|
103
|
+
end
|
104
|
+
end
|
91
105
|
end
|
92
106
|
|
93
107
|
def initialize(user = nil, record = nil, policy_class: nil)
|
data/lib/avo/version.rb
CHANGED