rails_omnibar 1.6.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile +1 -1
- data/README.md +33 -9
- data/app/controllers/rails_omnibar/html_controller.rb +1 -1
- data/bin/console +1 -0
- data/javascript/compiled.js +1 -1
- data/javascript/src/app.tsx +9 -2
- data/javascript/src/hooks/index.ts +1 -0
- data/javascript/src/hooks/use_delayed_loading_style.tsx +26 -0
- data/lib/rails_omnibar/command/base.rb +9 -2
- data/lib/rails_omnibar/command/search.rb +2 -1
- data/lib/rails_omnibar/commands.rb +16 -7
- data/lib/rails_omnibar/conditions.rb +27 -0
- data/lib/rails_omnibar/config.rb +29 -19
- data/lib/rails_omnibar/inheritance.rb +9 -0
- data/lib/rails_omnibar/item/base.rb +9 -3
- data/lib/rails_omnibar/items.rb +2 -3
- data/lib/rails_omnibar/rendering.rb +5 -11
- data/lib/rails_omnibar/version.rb +1 -1
- data/package.json +1 -1
- data/spec/benchmarks/benchmark.rb +16 -0
- data/spec/lib/rails_omnibar/config_spec.rb +1 -3
- data/spec/lib/rails_omnibar/inheritance_spec.rb +79 -0
- data/spec/system/rails_omnibar_spec.rb +27 -0
- data/spec/templates/app_template.rb +1 -1
- data/spec/templates/my_omnibar_template.rb +8 -0
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb8dc9106768dd42363729701b4590ff5a8f8276d675e5b408e9475d06f1e756
|
4
|
+
data.tar.gz: fb4070d55e1ee60265dd7fba81506556b03d974edb6c95a2a9a6d22e4fcca40e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b3ca6606749745f045e671efa9119aebcc695dec2c55072bb2042877b402f734d44e6ac89fc30e5a96321a8e6d15188f7ce327d7eb821bba94839e5e48467a9
|
7
|
+
data.tar.gz: 365ab2b1d105d7639828ba5bb1cc65c1a339f2ce5450a9740fd00559d7c793fc1d3ee5156924e211fa4e1a34748309e6f602423ea444a51f66ff2ac5c08af3a6
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [1.8.0] - 2024-07-06
|
8
|
+
|
9
|
+
### Added
|
10
|
+
|
11
|
+
- added support for turbo frames, thanks to @xijo
|
12
|
+
- added loading animation for long-running commands
|
13
|
+
|
14
|
+
## [1.7.0] - 2024-07-02
|
15
|
+
|
16
|
+
### Added
|
17
|
+
|
18
|
+
- conditional rendering of items (`add_item(if: ->{ ... })`)
|
19
|
+
- conditional execution of commands (`add_command(if: ->{ ... })`)
|
20
|
+
- inheritance of items, commands, and configuration (`Bar2 = Class.new(Bar1)`)
|
21
|
+
|
7
22
|
## [1.6.0] - 2024-01-25
|
8
23
|
|
9
24
|
### Added
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -89,14 +89,14 @@ end
|
|
89
89
|
Render it somewhere. E.g. `app/views/layouts/application.html.erb`:
|
90
90
|
|
91
91
|
```erb
|
92
|
-
<%= Omnibar.render %>
|
92
|
+
<%= Omnibar.render(self) %>
|
93
93
|
```
|
94
94
|
|
95
95
|
If you have a fully decoupled frontend, use `Omnibar.html_url` instead, fetch the omnibar HTML from there, and inject it.
|
96
96
|
|
97
97
|
### Authorization
|
98
98
|
|
99
|
-
You can limit access to commands (e.g. search commands)
|
99
|
+
You can limit access to commands (e.g. search commands) and items.
|
100
100
|
|
101
101
|
#### Option 1: globally limit engine access
|
102
102
|
|
@@ -119,19 +119,35 @@ MyOmnibar.auth = ->(controller, omnibar:) do
|
|
119
119
|
end
|
120
120
|
```
|
121
121
|
|
122
|
+
#### Option 3: Item-level conditionality
|
123
|
+
|
124
|
+
Items and commands can have an `if` proc that is executed in the controller context. If it returns false, the item is not shown and the command is not executed.
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
MyOmnibar.add_item(
|
128
|
+
title: 'Admin link',
|
129
|
+
url: admin_url,
|
130
|
+
if: ->{ current_user.admin? }
|
131
|
+
)
|
132
|
+
```
|
133
|
+
|
134
|
+
For this to work, the controller context must be given to the omnibar when rendering (e.g. by passing `self` in a view):
|
135
|
+
|
136
|
+
```erb
|
137
|
+
<%= Omnibar.render(self) %>
|
138
|
+
```
|
139
|
+
|
122
140
|
### Using multiple different omnibars
|
123
141
|
|
124
142
|
```ruby
|
125
|
-
BaseOmnibar = Class.new(RailsOmnibar)
|
126
|
-
BaseOmnibar.configure do |c|
|
143
|
+
BaseOmnibar = Class.new(RailsOmnibar).configure do |c|
|
127
144
|
c.add_item(
|
128
145
|
title: 'Log in',
|
129
146
|
url: Rails.application.routes.url_helpers.log_in_url
|
130
147
|
)
|
131
148
|
end
|
132
149
|
|
133
|
-
UserOmnibar = Class.new(RailsOmnibar)
|
134
|
-
UserOmnibar.configure do |c|
|
150
|
+
UserOmnibar = Class.new(RailsOmnibar).configure do |c|
|
135
151
|
c.auth = ->{ user_signed_in? }
|
136
152
|
c.add_item(
|
137
153
|
title: 'Log out',
|
@@ -143,7 +159,15 @@ end
|
|
143
159
|
Then, in some layout:
|
144
160
|
|
145
161
|
```erb
|
146
|
-
<%= (user_signed_in? ? UserOmnibar : BaseOmnibar).render %>
|
162
|
+
<%= (user_signed_in? ? UserOmnibar : BaseOmnibar).render(self) %>
|
163
|
+
```
|
164
|
+
|
165
|
+
Omnibars can also inherit commands, configuration, and items from existing omnibars:
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
SuperuserOmnibar = Class.new(UserOmnibar).configure do |c|
|
169
|
+
# add more items that only superusers should get
|
170
|
+
end
|
147
171
|
```
|
148
172
|
|
149
173
|
### Other options and usage patterns
|
@@ -172,7 +196,7 @@ end
|
|
172
196
|
```ruby
|
173
197
|
module AddOmnibar
|
174
198
|
def build_page(...)
|
175
|
-
within(super) { text_node(MyOmnibar.render) }
|
199
|
+
within(super) { text_node(MyOmnibar.render(self)) }
|
176
200
|
end
|
177
201
|
end
|
178
202
|
ActiveAdmin::Views::Pages::Base.prepend(AddOmnibar)
|
@@ -180,7 +204,7 @@ ActiveAdmin::Views::Pages::Base.prepend(AddOmnibar)
|
|
180
204
|
|
181
205
|
##### To render in RailsAdmin
|
182
206
|
|
183
|
-
Add `MyOmnibar.render` to `app/views/layouts/rails_admin/application.*`.
|
207
|
+
Add `MyOmnibar.render(self)` to `app/views/layouts/rails_admin/application.*`.
|
184
208
|
|
185
209
|
#### Adding all index routes as searchable items
|
186
210
|
|