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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07132bcc31a15ed0d5ba925a00bf25ac2656babd01c15e8df03ac41b46897512
4
- data.tar.gz: f18ef9526a35db7790b4c79ae597df3bbcf4ab93273e245ba753650b427453ca
3
+ metadata.gz: eb8dc9106768dd42363729701b4590ff5a8f8276d675e5b408e9475d06f1e756
4
+ data.tar.gz: fb4070d55e1ee60265dd7fba81506556b03d974edb6c95a2a9a6d22e4fcca40e
5
5
  SHA512:
6
- metadata.gz: 25e3eb51a271cb5c229a6850c138f783a828b6b08434625ebca9aa75ea16c7368073eaf52260270ea1599c74734a7662cc0f0c8be700295c4aa062b26018efc8
7
- data.tar.gz: a4e5a52e52eadaedc34018b95f79aaf084c6310d0bb1a33fd68188736e7a7028bbaa6c3ed090788d7e256b8df5f15989c562791f6fe389192a8220f0596fe6ca
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
@@ -12,7 +12,7 @@ group :development, :test do
12
12
  gem 'puma', '~> 6.0'
13
13
  gem 'rake', '~> 13.0'
14
14
  gem 'rspec-rails', '~> 5.0'
15
- gem 'sqlite3', '>= 1.3.6'
15
+ gem 'sqlite3', '~> 1.4'
16
16
  gem 'sprockets-rails', '~> 3.4' # for activeadmin
17
17
  gem 'webdrivers', '~> 5.0'
18
18
  end
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). This will not limit access to plain items.
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
 
@@ -1,5 +1,5 @@
1
1
  class RailsOmnibar::HtmlController < RailsOmnibar::BaseController
2
2
  def show
3
- render html: omnibar.render
3
+ render html: omnibar.render(self)
4
4
  end
5
5
  end
data/bin/console CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'rails_omnibar'
5
+ require_relative '../spec/dummy/config/environment'
5
6
 
6
7
  require 'irb'
7
8
  IRB.start(__FILE__)