|
5 | 5 |
|
6 | 6 | # ActiveAdmin Sidebar |
7 | 7 |
|
8 | | -Provides ability to manipulate sidebar position for ActiveAdmin (tested with ActiveAdmin ~> 1.0.0) |
| 8 | +Manipulate sidebar position and add collapsible sidebar support for ActiveAdmin 3.x. |
9 | 9 |
|
10 | 10 | ## Install |
11 | 11 |
|
12 | | -Add following line to the `Gemfile` |
| 12 | +Add to your `Gemfile`: |
13 | 13 |
|
14 | 14 | ```ruby |
15 | 15 | gem 'active_admin_sidebar' |
16 | 16 | ``` |
17 | 17 |
|
18 | | -##### Using assets via Sprockets |
19 | | -Add following line to the `app/assets/stylesheets/active_admin.css.scss` |
| 18 | +### Using assets via Sprockets |
| 19 | + |
| 20 | +Add to `app/assets/stylesheets/active_admin.scss`: |
20 | 21 |
|
21 | 22 | ```scss |
22 | | - @import "active_admin_sidebar"; |
| 23 | +@import "active_admin_sidebar"; |
23 | 24 | ``` |
24 | 25 |
|
25 | | -If you want to use collapsing feature, add following line |
| 26 | +Add to `app/assets/javascripts/active_admin.js`: |
26 | 27 |
|
27 | | -```javascripts |
28 | | - //= require active_admin_sidebar |
| 28 | +```javascript |
| 29 | +//= require active_admin_sidebar |
29 | 30 | ``` |
30 | 31 |
|
31 | | -to the `app/assets/javascripts/active_admin.js` |
32 | | - |
33 | | -##### Using assets via Webpacker (or any other assets bundler) as a NPM module (Yarn package) |
34 | | - |
35 | | -Execute: |
| 32 | +### Using assets via NPM |
36 | 33 |
|
37 | 34 | $ npm i @activeadmin-plugins/active_admin_sidebar |
38 | 35 |
|
39 | 36 | Or |
40 | 37 |
|
41 | 38 | $ yarn add @activeadmin-plugins/active_admin_sidebar |
42 | 39 |
|
43 | | -Or add manually to `package.json`: |
44 | | - |
45 | | -```json |
46 | | -"dependencies": { |
47 | | - "@activeadmin-plugins/active_admin_sidebar": "2.0.0" |
48 | | -} |
49 | | -``` |
50 | | -and execute: |
51 | | - |
52 | | - $ yarn |
53 | | - |
54 | | -Add the following line into `app/assets/javascripts/active_admin.js`: |
| 40 | +Add to `app/assets/javascripts/active_admin.js`: |
55 | 41 |
|
56 | 42 | ```javascript |
57 | 43 | import '@activeadmin-plugins/active_admin_sidebar'; |
58 | 44 | ``` |
59 | 45 |
|
60 | | -Add the following line into `app/assets/stylesheets/active_admin.scss`: |
| 46 | +Add to `app/assets/stylesheets/active_admin.scss`: |
61 | 47 |
|
62 | | -```css |
| 48 | +```scss |
63 | 49 | @import '@activeadmin-plugins/active_admin_sidebar'; |
64 | 50 | ``` |
65 | 51 |
|
66 | | -# Configuration per resource |
| 52 | +## Configuration per resource |
67 | 53 |
|
68 | | -Changing sidebar position dynamically with before_action |
| 54 | +Change sidebar position with `before_action`: |
69 | 55 |
|
70 | 56 | ```ruby |
71 | | - # app/admin/posts.rb |
72 | | - ActiveAdmin.register Post do |
73 | | - before_action :left_sidebar!, only: [:show] |
| 57 | +# app/admin/posts.rb |
| 58 | +ActiveAdmin.register Post do |
| 59 | + before_action only: [:index] do |
| 60 | + left_sidebar! |
74 | 61 | end |
| 62 | +end |
75 | 63 |
|
76 | | - # app/admin/comments.rb |
77 | | - ActiveAdmin.register Comment do |
78 | | - before_action :right_sidebar! |
| 64 | +# app/admin/comments.rb |
| 65 | +ActiveAdmin.register Comment do |
| 66 | + before_action do |
| 67 | + right_sidebar! |
79 | 68 | end |
| 69 | +end |
80 | 70 | ``` |
81 | 71 |
|
82 | 72 | ## Global configuration |
83 | 73 |
|
84 | | -Moving sidebar to the left within all resource. Set configuration in `config/initializers/active_admin.rb` |
| 74 | +Move sidebar to the left for all resources in `config/initializers/active_admin.rb`: |
85 | 75 |
|
86 | 76 | ```ruby |
87 | | - # == Controller before-actions |
88 | | - # |
89 | | - # You can add before, after and around actions to all of your resources |
90 | | - ActiveAdmin.setup do |config| |
91 | | - config.before_action do |
92 | | - left_sidebar! if respond_to?(:left_sidebar!) |
93 | | - end |
| 77 | +ActiveAdmin.setup do |config| |
| 78 | + config.before_action do |
| 79 | + left_sidebar! if respond_to?(:left_sidebar!) |
94 | 80 | end |
| 81 | +end |
95 | 82 | ``` |
96 | 83 |
|
97 | 84 | ## Collapsible sidebar |
98 | 85 |
|
99 | 86 | Add a toggle button to collapse/expand the sidebar. State is persisted per-resource across page navigations. |
100 | 87 |
|
101 | 88 | ```ruby |
102 | | - # Collapsible sidebar (starts expanded) |
103 | | - left_sidebar!(collapsible: true) |
104 | | - right_sidebar!(collapsible: true) |
| 89 | +# Collapsible sidebar (starts expanded) |
| 90 | +left_sidebar!(collapsible: true) |
| 91 | +right_sidebar!(collapsible: true) |
105 | 92 |
|
106 | | - # Collapsible sidebar (starts collapsed) |
107 | | - left_sidebar!(collapsible: true, start_collapsed: true) |
108 | | - right_sidebar!(collapsible: true, start_collapsed: true) |
| 93 | +# Collapsible sidebar (starts collapsed) |
| 94 | +left_sidebar!(collapsible: true, start_collapsed: true) |
| 95 | +right_sidebar!(collapsible: true, start_collapsed: true) |
109 | 96 | ``` |
110 | 97 |
|
111 | 98 |  |
0 commit comments