five-two-nw-olivander 0.1.2.35 → 0.1.2.36
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e55a54429f0d10d6f23e477b5615cb32f1c2cbbccbd6a622b73f2cb07b70131
|
4
|
+
data.tar.gz: 04d1f0ee790725256e7a65b93c20baf0c2199fe7c3dbfbc5b7f576f6decf93bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a9555b4ebbfdbd0d55df3c3a0ec03b7e48ccd0be00fd1c25700511ae2bc2085451d3d0d023bb340cd6b1a5a0e8131b3c58311dcd33c6befa2c195ead6cbcc34
|
7
|
+
data.tar.gz: dfb311cdc4987aaf562859af28e0d81d2beb944fe75fdfad53fede0045f42ffd925e6ebff562e72b0a4e9c57dff8e93068af88349be2923a14c430346cef7448
|
@@ -23,10 +23,11 @@ module Olivander
|
|
23
23
|
end
|
24
24
|
|
25
25
|
class RoutedResource
|
26
|
-
attr_accessor :model, :actions
|
26
|
+
attr_accessor :model, :namespaces, :actions
|
27
27
|
|
28
|
-
def initialize(model, crud_actions)
|
28
|
+
def initialize(model, namespaces, crud_actions)
|
29
29
|
self.model = model
|
30
|
+
self.namespaces = namespaces
|
30
31
|
self.actions = []
|
31
32
|
%i[index new create edit show update destroy].each do |ca|
|
32
33
|
next unless crud_actions.include?(ca)
|
@@ -90,8 +91,8 @@ module Olivander
|
|
90
91
|
end
|
91
92
|
|
92
93
|
class_methods do
|
93
|
-
def resource(model, only: DEFAULT_CRUD_ACTIONS, except: [], &block)
|
94
|
-
self.current_resource = RoutedResource.new(model, DEFAULT_CRUD_ACTIONS & (only - except))
|
94
|
+
def resource(model, only: DEFAULT_CRUD_ACTIONS, except: [], namespaces: [], &block)
|
95
|
+
self.current_resource = RoutedResource.new(model, namespaces, DEFAULT_CRUD_ACTIONS & (only - except))
|
95
96
|
yield if block_given?
|
96
97
|
resources[model] = current_resource
|
97
98
|
self.current_resource = nil
|
@@ -109,9 +110,7 @@ module Olivander
|
|
109
110
|
end
|
110
111
|
|
111
112
|
def build_routes(mapper)
|
112
|
-
|
113
|
-
build_resource_routes(mapper)
|
114
|
-
Rails.logger.info "...routes built"
|
113
|
+
build_resources_routes(mapper)
|
115
114
|
end
|
116
115
|
|
117
116
|
def set_controller_and_helper(a)
|
@@ -121,10 +120,19 @@ module Olivander
|
|
121
120
|
self.last_path_helper = a.path_helper
|
122
121
|
end
|
123
122
|
|
124
|
-
def
|
123
|
+
def build_resources_routes(mapper)
|
125
124
|
resources.keys.each do |k|
|
126
|
-
before_routes = Rails.application.routes.named_routes.helper_names
|
127
125
|
r = resources[k]
|
126
|
+
build_resource_route(mapper, r, r.namespaces)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
def build_resource_route(mapper, r, namespaces)
|
131
|
+
if namespaces.size.positive?
|
132
|
+
mapper.namespace namespaces.first do
|
133
|
+
build_resource_route(mapper, r, r.namespaces.last(r.namespaces.size - 1))
|
134
|
+
end
|
135
|
+
else
|
128
136
|
mapper.resources r.model, only: [] do
|
129
137
|
mapper.collection do
|
130
138
|
r.collection_actions.each do |ba|
|
@@ -160,10 +168,6 @@ module Olivander
|
|
160
168
|
end
|
161
169
|
end
|
162
170
|
end
|
163
|
-
after_routes = Rails.application.routes.named_routes.helper_names
|
164
|
-
net_routes = after_routes - before_routes
|
165
|
-
# Rails.logger.info "added these route helpers:\n#{net_routes}"
|
166
|
-
# binding.pry if k == :projects
|
167
171
|
end
|
168
172
|
end
|
169
173
|
end
|
@@ -45,7 +45,8 @@ module Olivander
|
|
45
45
|
end
|
46
46
|
|
47
47
|
def resource_form_action_label(resource, action)
|
48
|
-
|
48
|
+
key = resource.class.name.underscore
|
49
|
+
return I18n.t("activerecord.actions.#{key}.#{action}") if I18n.exists?("activerecord.actions.#{key}.#{action}")
|
49
50
|
return I18n.t("activerecord.actions.#{action}") if I18n.exists?("activerecord.actions.#{action}")
|
50
51
|
|
51
52
|
action.to_s.titleize
|
@@ -2,4 +2,5 @@
|
|
2
2
|
= dropdown(variation: :dropleft, btn_class: btn_class) do
|
3
3
|
- authorized_resource_actions(route_builder, resource, for_action: action_name).select{ |x| x.show_in_datatable }.each do |a|
|
4
4
|
- path = a.path_helper.is_a?(Proc) ? a.path_helper.call(resource) : send(a.path_helper, resource.id)
|
5
|
-
=
|
5
|
+
- data = a.turbo_frame.present? ? { turbo: true, turbo_frame: a.turbo_frame } : {}
|
6
|
+
= dropdown_link_to resource_form_action_label(resource, a.sym), path, data: data
|
data/lib/olivander/version.rb
CHANGED