rails_omnibar 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/tests.yml +24 -0
  3. data/.gitignore +41 -0
  4. data/CHANGELOG.md +9 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +178 -0
  8. data/Rakefile +45 -0
  9. data/app/controllers/rails_omnibar/base_controller.rb +2 -0
  10. data/app/controllers/rails_omnibar/js_controller.rb +11 -0
  11. data/app/controllers/rails_omnibar/queries_controller.rb +7 -0
  12. data/bin/console +7 -0
  13. data/bin/setup +8 -0
  14. data/config/routes.rb +4 -0
  15. data/javascript/compiled.js +2 -0
  16. data/javascript/src/app.tsx +44 -0
  17. data/javascript/src/hooks/index.ts +5 -0
  18. data/javascript/src/hooks/use_hotkey.ts +18 -0
  19. data/javascript/src/hooks/use_item_action.tsx +20 -0
  20. data/javascript/src/hooks/use_modal.tsx +33 -0
  21. data/javascript/src/hooks/use_omnibar_extensions.ts +33 -0
  22. data/javascript/src/hooks/use_toggle_focus.ts +15 -0
  23. data/javascript/src/index.ts +1 -0
  24. data/javascript/src/types.ts +34 -0
  25. data/lib/rails_omnibar/command/base.rb +44 -0
  26. data/lib/rails_omnibar/command/search.rb +68 -0
  27. data/lib/rails_omnibar/commands.rb +28 -0
  28. data/lib/rails_omnibar/config.rb +35 -0
  29. data/lib/rails_omnibar/engine.rb +5 -0
  30. data/lib/rails_omnibar/item/base.rb +21 -0
  31. data/lib/rails_omnibar/item/help.rb +22 -0
  32. data/lib/rails_omnibar/items.rb +25 -0
  33. data/lib/rails_omnibar/rendering.rb +34 -0
  34. data/lib/rails_omnibar/version.rb +3 -0
  35. data/lib/rails_omnibar.rb +8 -0
  36. data/package.json +27 -0
  37. data/rails_omnibar.gemspec +31 -0
  38. data/spec/app_template.rb +17 -0
  39. data/spec/lib/rails_omnibar/config_spec.rb +53 -0
  40. data/spec/lib/rails_omnibar/version_spec.rb +7 -0
  41. data/spec/my_omnibar_template.rb +45 -0
  42. data/spec/rails_helper.rb +22 -0
  43. data/spec/support/factories.rb +8 -0
  44. data/spec/system/rails_omnibar_spec.rb +87 -0
  45. data/tsconfig.json +18 -0
  46. data/webpack.config.js +32 -0
  47. metadata +226 -0
@@ -0,0 +1,8 @@
1
+ require 'factory_bot_rails'
2
+
3
+ FactoryBot.define do
4
+ factory :user do
5
+ first_name { 'John' }
6
+ last_name { 'Doe' }
7
+ end
8
+ end
@@ -0,0 +1,87 @@
1
+ require 'rails_helper'
2
+
3
+ describe RailsOmnibar do
4
+ it 'works' do
5
+ FactoryBot.create(:user, id: 1, first_name: 'John', last_name: 'Doe')
6
+ FactoryBot.create(:user, id: 2, first_name: 'Jane', last_name: 'Doe', admin: true)
7
+ expect(User.pluck(:id).sort).to eq [1, 2] # sanity check
8
+
9
+ visit main_app.root_path
10
+ expect(page).to have_selector '#mount-rails-omnibar' # sanity check
11
+
12
+ # test visibility toggling with hotkey
13
+ expect(page).not_to have_selector 'input'
14
+
15
+ send_keys([:control, 'm']) # custom hotkey, c.f. app_template.rb
16
+ expect(page).to have_selector 'input'
17
+
18
+ send_keys([:control, 'm'])
19
+ expect(page).not_to have_selector 'input'
20
+
21
+ send_keys([:meta, 'm']) # meta modifier (⌘) should also be supported
22
+ expect(page).to have_selector 'input'
23
+
24
+ # test fuzzy search for static items
25
+ type('ou')
26
+ expect(page).to have_content 'boring URL'
27
+ expect(page).to have_content 'important URL'
28
+
29
+ type('ori')
30
+ expect(page).to have_content 'boring URL'
31
+ expect(page).not_to have_content 'important URL'
32
+
33
+ # test help modal
34
+ expect(page).not_to have_content 'Available actions'
35
+ submit('Help')
36
+ expect(page).to have_content 'Available actions'
37
+ send_keys :escape
38
+ expect(page).not_to have_content 'Available actions'
39
+
40
+ # test record search by id
41
+ type('u1')
42
+ expect(page).to have_content 'User#1'
43
+ expect(page).not_to have_content 'User#2'
44
+
45
+ type('u2')
46
+ expect(page).to have_content 'User#2'
47
+ expect(page).not_to have_content 'User#1'
48
+
49
+ # test record search by custom column
50
+ type('u J') # both usernames start with J
51
+ expect(page).to have_content 'User#1'
52
+ expect(page).to have_content 'User#2'
53
+
54
+ type('u Jo')
55
+ expect(page).to have_content 'User#1'
56
+ expect(page).not_to have_content 'User#2'
57
+
58
+ type('u Ja')
59
+ expect(page).to have_content 'User#2'
60
+ expect(page).not_to have_content 'User#1'
61
+
62
+ # test navigation for item with #url
63
+ submit
64
+ expect(page.current_url).to end_with '/users/2'
65
+ send_keys([:control, 'm']) # make omnibar visible again
66
+
67
+ # test generic search
68
+ type('g foobar')
69
+ expect(page).to have_content 'fake_result_1'
70
+ expect(page).to have_content 'fake_result_2'
71
+ expect(page).to have_content 'fake_result_3'
72
+
73
+ # test custom command
74
+ type('count users')
75
+ expect(page).to have_content '2'
76
+ end
77
+
78
+ def type(str)
79
+ find('input').set(str)
80
+ end
81
+
82
+ def submit(str = nil)
83
+ str.present? && type(str)
84
+ sleep(0.1) # wait a tiny bit for the omnibar results to appear
85
+ send_keys(:return)
86
+ end
87
+ end
data/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "allowSyntheticDefaultImports": true,
4
+ "downlevelIteration": true,
5
+ "outDir": "./javascript/",
6
+ "noImplicitAny": true,
7
+ "module": "es6",
8
+ "target": "es5",
9
+ "jsx": "react-jsx",
10
+ "jsxImportSource": "preact",
11
+ "allowJs": true,
12
+ "moduleResolution": "node",
13
+ "paths": {
14
+ "react": ["./node_modules/preact/compat/"],
15
+ "react-dom": ["./node_modules/preact/compat/"]
16
+ }
17
+ },
18
+ }
data/webpack.config.js ADDED
@@ -0,0 +1,32 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ entry: './javascript/src/index.ts',
5
+ mode: 'production',
6
+ module: {
7
+ rules: [
8
+ {
9
+ rules: [
10
+ {
11
+ test: /\.tsx?$/,
12
+ use: 'ts-loader',
13
+ exclude: /node_modules/,
14
+ },
15
+ ],
16
+ }
17
+ ]
18
+ },
19
+ resolve: {
20
+ extensions: ['.tsx', '.ts', '.js'],
21
+ alias: {
22
+ "react": "preact/compat",
23
+ "react-dom/test-utils": "preact/test-utils",
24
+ "react-dom": "preact/compat", // Must be below test-utils
25
+ "react/jsx-runtime": "preact/jsx-runtime"
26
+ },
27
+ },
28
+ output: {
29
+ filename: 'compiled.js',
30
+ path: path.resolve(__dirname, 'javascript'),
31
+ },
32
+ }
metadata ADDED
@@ -0,0 +1,226 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_omnibar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Janosch Müller
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: js_regex
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '6.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '8.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '6.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '8.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: capybara
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '3.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: factory_bot_rails
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '6.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '6.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: puma
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '5.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '5.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: rake
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '13.0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '13.0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: rspec-rails
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '5.0'
110
+ type: :development
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '5.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: sqlite3
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 1.3.6
124
+ type: :development
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 1.3.6
131
+ - !ruby/object:Gem::Dependency
132
+ name: webdrivers
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '5.0'
138
+ type: :development
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '5.0'
145
+ description: Omnibar for Rails
146
+ email:
147
+ executables: []
148
+ extensions: []
149
+ extra_rdoc_files: []
150
+ files:
151
+ - ".github/workflows/tests.yml"
152
+ - ".gitignore"
153
+ - CHANGELOG.md
154
+ - Gemfile
155
+ - LICENSE.txt
156
+ - README.md
157
+ - Rakefile
158
+ - app/controllers/rails_omnibar/base_controller.rb
159
+ - app/controllers/rails_omnibar/js_controller.rb
160
+ - app/controllers/rails_omnibar/queries_controller.rb
161
+ - bin/console
162
+ - bin/setup
163
+ - config/routes.rb
164
+ - javascript/compiled.js
165
+ - javascript/src/app.tsx
166
+ - javascript/src/hooks/index.ts
167
+ - javascript/src/hooks/use_hotkey.ts
168
+ - javascript/src/hooks/use_item_action.tsx
169
+ - javascript/src/hooks/use_modal.tsx
170
+ - javascript/src/hooks/use_omnibar_extensions.ts
171
+ - javascript/src/hooks/use_toggle_focus.ts
172
+ - javascript/src/index.ts
173
+ - javascript/src/types.ts
174
+ - lib/rails_omnibar.rb
175
+ - lib/rails_omnibar/command/base.rb
176
+ - lib/rails_omnibar/command/search.rb
177
+ - lib/rails_omnibar/commands.rb
178
+ - lib/rails_omnibar/config.rb
179
+ - lib/rails_omnibar/engine.rb
180
+ - lib/rails_omnibar/item/base.rb
181
+ - lib/rails_omnibar/item/help.rb
182
+ - lib/rails_omnibar/items.rb
183
+ - lib/rails_omnibar/rendering.rb
184
+ - lib/rails_omnibar/version.rb
185
+ - package.json
186
+ - rails_omnibar.gemspec
187
+ - spec/app_template.rb
188
+ - spec/lib/rails_omnibar/config_spec.rb
189
+ - spec/lib/rails_omnibar/version_spec.rb
190
+ - spec/my_omnibar_template.rb
191
+ - spec/rails_helper.rb
192
+ - spec/support/factories.rb
193
+ - spec/system/rails_omnibar_spec.rb
194
+ - tsconfig.json
195
+ - webpack.config.js
196
+ homepage: https://github.com/jaynetics/rails_omnibar
197
+ licenses:
198
+ - MIT
199
+ metadata: {}
200
+ post_install_message:
201
+ rdoc_options: []
202
+ require_paths:
203
+ - lib
204
+ required_ruby_version: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '2.7'
209
+ required_rubygems_version: !ruby/object:Gem::Requirement
210
+ requirements:
211
+ - - ">="
212
+ - !ruby/object:Gem::Version
213
+ version: '0'
214
+ requirements: []
215
+ rubygems_version: 3.4.1
216
+ signing_key:
217
+ specification_version: 4
218
+ summary: Omnibar for Rails
219
+ test_files:
220
+ - spec/app_template.rb
221
+ - spec/lib/rails_omnibar/config_spec.rb
222
+ - spec/lib/rails_omnibar/version_spec.rb
223
+ - spec/my_omnibar_template.rb
224
+ - spec/rails_helper.rb
225
+ - spec/support/factories.rb
226
+ - spec/system/rails_omnibar_spec.rb