bootstrap_admin 0.0.15 → 0.0.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +129 -31
- data/app/assets/stylesheets/bootstrap_overrides.css.scss +1 -0
- data/app/helpers/bootstrap_admin/menu_helper.rb +1 -1
- data/app/helpers/bootstrap_admin_helper.rb +22 -4
- data/app/views/defaults/_form.html.haml +1 -1
- data/app/views/defaults/_paginator.html.haml +3 -2
- data/app/views/defaults/edit.html.haml +1 -1
- data/app/views/defaults/new.html.haml +1 -1
- data/bootstrap_admin.gemspec +3 -2
- data/config/initializers/simple_form.rb +1 -1
- data/lib/bootstrap_admin/controller_helpers.rb +5 -2
- data/lib/bootstrap_admin/version.rb +1 -1
- data/lib/bootstrap_admin.rb +7 -0
- data/lib/generators/bootstrap_admin/{USAGE → install/USAGE} +0 -0
- data/lib/generators/bootstrap_admin/{install_generator.rb → install/install_generator.rb} +5 -0
- data/lib/generators/bootstrap_admin/{templates → install/templates}/bootstrap_admin.rb +0 -0
- data/lib/generators/bootstrap_admin/{templates → install/templates}/bootstrap_admin_menu.yml +0 -0
- data/lib/generators/bootstrap_admin/{templates → install/templates}/en_bootstrap_admin.yml +0 -0
- data/lib/generators/bootstrap_admin/override_views/USAGE +24 -0
- data/lib/generators/bootstrap_admin/override_views/override_views_generator.rb +61 -0
- data/vendor/assets/javascripts/bootstrap.js +379 -124
- data/vendor/assets/javascripts/bootstrap.min.js +2 -2
- data/vendor/assets/stylesheets/bootstrap-responsive.css +26 -5
- data/vendor/assets/stylesheets/bootstrap-responsive.min.css +4 -4
- data/vendor/assets/stylesheets/bootstrap.css +510 -236
- data/vendor/assets/stylesheets/bootstrap.min.css +4 -4
- metadata +39 -36
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c48b519fd799851de6a334d3ddd7f642546d29a5
|
4
|
+
data.tar.gz: cb2011b030732ad0de90b95853a0060dd7bc29ad
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c942b58bae975618c33212ed9b77f5df2cfde6c4249276be317159f3af18c5a9147eee4cf964b2c05465a4273cf5bb6de735276506d2ef319f06fe3e1e4e1874
|
7
|
+
data.tar.gz: fe1f3cad48919d74f0d865dc2262a457a1869a4632c3304d1920f4e252c31a17bc4e8a4222c9e53b2d11fd06ed13622b46bfe384c3fa4c1aaa1fdfbac329017b
|
data/README.md
CHANGED
@@ -94,7 +94,45 @@ And BAM, ready to roll!!
|
|
94
94
|
|
95
95
|
## Configuring Bootstrap Admin - Initializer
|
96
96
|
|
97
|
-
|
97
|
+
This is were you can configure the global options for bootstrap admin.
|
98
|
+
|
99
|
+
For now there are only a few options:
|
100
|
+
|
101
|
+
* `admin_namespace` - a String defining the name of the namespace to be used
|
102
|
+
* `paginator_page_size`- an Integer defining the page size for all bootstrap_admin index actions
|
103
|
+
* `ui_styles` - an Hash that defines CSS classes to be used on certain elements
|
104
|
+
|
105
|
+
For now `ui_styles` should contain an hash with more or less the following structure:
|
106
|
+
```ruby
|
107
|
+
config.ui_styles = {
|
108
|
+
index: %w(table-bordered table-striped)
|
109
|
+
}
|
110
|
+
```
|
111
|
+
The index ui_styles will be used on the index table.
|
112
|
+
On future releases, this hash will be extended and taken into account for other situations.
|
113
|
+
|
114
|
+
### Example of a Bootstrap Admin Initializer
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
BootstrapAdmin.setup do |config|
|
118
|
+
|
119
|
+
# ==> Admin namespace configuration
|
120
|
+
# Configure namespace used for the scope of this admin
|
121
|
+
# Default value: :admin
|
122
|
+
config.admin_namespace = "backoffice"
|
123
|
+
|
124
|
+
# ==> Paginator configuration
|
125
|
+
# Configure the number of results shown per page by the paginator.
|
126
|
+
# Default value: 10
|
127
|
+
config.paginator_page_size = 6
|
128
|
+
|
129
|
+
# ==> UI Styles
|
130
|
+
# Configure the css class names that each action wrapper will have
|
131
|
+
# Default value: {index: %w(table-bordered table-striped)}
|
132
|
+
config.ui_styles[:index] << "my_awesome_style_class"
|
133
|
+
|
134
|
+
end
|
135
|
+
```
|
98
136
|
|
99
137
|
## Admin Menu
|
100
138
|
|
@@ -103,51 +141,65 @@ If you want to customize the bootstrap_admin menu, you can edit the `config/boot
|
|
103
141
|
So, to customize the menu, you must supply a list of menu entries.<br/>
|
104
142
|
On each entry you can use this set of options:
|
105
143
|
|
106
|
-
* `:label` - the label that will be presented in the menu. This can be either:
|
107
|
-
* **Symbol** - Will be passed to I18n for translation
|
108
|
-
* **String** - Will be used directly
|
109
|
-
* `:class` - the css class to apply to the item
|
110
|
-
* `:url` - the url to be used on the item link.
|
111
144
|
* `:item` - one of 3 things:
|
112
145
|
* **String**: must be a name of a model (it will be used to build the link url and the label if not supplied)
|
113
146
|
* **List**: This will tell bootstrap_admin that the item is in fact a dropdown menu. **In this case `:label` must be supplied.**
|
114
147
|
* **Symbol**: currently only `:divider` is supported and produces a division between dropdown elements.
|
148
|
+
* `:label` - the label that will be presented in the menu. This can be either:
|
149
|
+
* **Symbol** - Will be passed to I18n for translation
|
150
|
+
* **String** - Will be used directly
|
151
|
+
* By default (when not supplied), the label will be the `:item` human name.
|
152
|
+
* `:namespace` - if your model (`:item`) is under a namespace, then you should declare it on this option
|
153
|
+
* `:class` - the css class to apply to the item
|
154
|
+
* `:url` - the url to be used on the item link.
|
155
|
+
* `:controller` - the controller to be used on the item link.
|
115
156
|
|
116
157
|
### Example
|
117
158
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
159
|
+
```yaml
|
160
|
+
# Item based on a model
|
161
|
+
- :item: Document
|
162
|
+
|
163
|
+
# Item based on a model, with non-default controller
|
164
|
+
- :item: NewsArticle
|
165
|
+
:controller: admin/news
|
166
|
+
|
167
|
+
# Item based on a namespaced model (Blog::Entry)
|
168
|
+
- :item: Entry
|
169
|
+
:namespace: Blog
|
170
|
+
|
171
|
+
# Item based on a model with a custom label and css class
|
172
|
+
- :item: Author
|
173
|
+
:label: The guys who write things
|
174
|
+
:class: really_bold
|
175
|
+
|
176
|
+
# Item based on a model with a custom url
|
177
|
+
- :item: Search
|
178
|
+
:url: "https://google.com"
|
179
|
+
|
180
|
+
# Dropdown menu item with several options and a divider
|
181
|
+
- :label: :user_admin # this will be called as I18n.t(:user_admin)
|
182
|
+
:url: "#"
|
183
|
+
:item:
|
184
|
+
- :item: Role
|
185
|
+
- :item: :divider
|
186
|
+
- :item: User
|
187
|
+
:label: Dudes
|
188
|
+
```
|
138
189
|
|
139
190
|
## Configuring the Controller
|
140
191
|
|
141
192
|
By default, bootstrap\_admin will use the fields defined as accessible on the model matching the name of the controller it is working on to build all markup. Also, by default, bootstrap\_admin will respond to `html` and `json` formats.
|
142
|
-
If you want to override this
|
193
|
+
If you want to override this behavior, the controller macro allows you to pass a block that will be used to configure how bootstrap\_admin will behave.
|
143
194
|
|
144
195
|
### Configuring which fields to use
|
145
196
|
|
146
|
-
To override the default
|
197
|
+
To override the default behavior, you can use the following configurators:
|
147
198
|
|
148
199
|
* `index_fields` - the fields to be used on the index action
|
149
200
|
* `show_fields` - the fields to be used on the show action
|
150
201
|
* `form_fields` - the fields to be used on all form actions (new, edit, etc..)
|
202
|
+
* `action_fields` - the fields to be used on all actions. This will only be used when the specific action fields aren't defined.
|
151
203
|
* `searchable_fields` - the fields to be used while searching
|
152
204
|
|
153
205
|
To use these configurators, you pass a block to the bootstrap\_admin macro like so:
|
@@ -161,6 +213,28 @@ bootstrap_admin do |config|
|
|
161
213
|
end
|
162
214
|
```
|
163
215
|
|
216
|
+
### Configuring the action links available
|
217
|
+
|
218
|
+
Imagine that for some reason you don't have the need to create new records on a given scaffold. Then, there really shouldn't be a button/link to the new record form...
|
219
|
+
In order to configure which action links should be shown on a given scaffold, you can use the `available_actions` configurator:
|
220
|
+
|
221
|
+
```ruby
|
222
|
+
bootstrap_admin do |config|
|
223
|
+
config.available_actions = [:show, :new]
|
224
|
+
end
|
225
|
+
```
|
226
|
+
|
227
|
+
With this setting, then your scaffold would only show the link to show on each record and the link to the new record form.
|
228
|
+
|
229
|
+
By default the available_actions are:
|
230
|
+
|
231
|
+
* `:new` - collection-wise link to the new record form
|
232
|
+
* `:show` - member-wise link to show the record
|
233
|
+
* `:edit` - member-wise link to the edit record form
|
234
|
+
* `:destroy` - member-wise link to destroy the record
|
235
|
+
|
236
|
+
No other actions will be taken into account.
|
237
|
+
|
164
238
|
### Configuring response formats
|
165
239
|
|
166
240
|
bootstrap\_admin also allows you to define to which formats will your controller respond to using the `responder_formats` configurator like so:
|
@@ -171,6 +245,18 @@ bootstrap_admin do |config|
|
|
171
245
|
end
|
172
246
|
```
|
173
247
|
|
248
|
+
### Configuring which model to use
|
249
|
+
|
250
|
+
Sometimes you need a controller to handle a model that has a completely different name from the controller. On those cases, bootstrap\_admin allows you to configure the name of the model to use:
|
251
|
+
|
252
|
+
```ruby
|
253
|
+
class NewsController < AdminController
|
254
|
+
bootstrap_admin do |config|
|
255
|
+
config.model_name = "NewsArticle"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
```
|
259
|
+
|
174
260
|
## Configuring the Routes
|
175
261
|
|
176
262
|
TODO
|
@@ -203,7 +289,7 @@ def title record
|
|
203
289
|
end
|
204
290
|
```
|
205
291
|
|
206
|
-
If, on the other hand you need to use
|
292
|
+
If, on the other hand you need to use different code to display different actions, then your helper must:
|
207
293
|
|
208
294
|
* Be named `<action>_<field>`
|
209
295
|
* Accept one argument - the model instance we are displaying
|
@@ -220,10 +306,12 @@ end
|
|
220
306
|
|
221
307
|
#### Overriding field on `form` actions (`new`, `edit`, etc..)
|
222
308
|
|
223
|
-
|
309
|
+
This is similar to the overriding done for the `show` and/or `index` actions.
|
310
|
+
|
311
|
+
If all your form actions (`new`, `edit`, etc..) can use the same code, then your helper must:
|
224
312
|
|
225
313
|
* Be named `form_<field>`
|
226
|
-
* Accept one argument - the form for the model
|
314
|
+
* Accept one argument - the form builder for the model
|
227
315
|
|
228
316
|
```ruby
|
229
317
|
def form_title form
|
@@ -232,6 +320,16 @@ end
|
|
232
320
|
```
|
233
321
|
You can use `form.object` to get the object to which the form is for.
|
234
322
|
|
323
|
+
But if you need to use different code on each action, then you can build helpers that must:
|
324
|
+
|
325
|
+
* Be named `<action>_form_<field>`
|
326
|
+
* Accept one argument - the form builder for the model
|
327
|
+
|
328
|
+
```ruby
|
329
|
+
def new_form_title form
|
330
|
+
form.input(:title)
|
331
|
+
end
|
332
|
+
```
|
235
333
|
|
236
334
|
### Overriding the views
|
237
335
|
|
@@ -32,7 +32,7 @@ module BootstrapAdmin::MenuHelper
|
|
32
32
|
"- :item: #{ename}"
|
33
33
|
end.join("\n")
|
34
34
|
|
35
|
-
@bootstrap_admin_menu_items = YAML.load(yml_menu)
|
35
|
+
@bootstrap_admin_menu_items = YAML.load(yml_menu) || []
|
36
36
|
end
|
37
37
|
|
38
38
|
# =============================================================================
|
@@ -134,8 +134,8 @@ module BootstrapAdminHelper
|
|
134
134
|
defaults = {:controller => params[:controller]}.merge options
|
135
135
|
|
136
136
|
ctrl_namespace = defaults[:controller].split("/").first
|
137
|
-
# Fix for engines with shared namespace for some reason main_app.url_for doesn't find the route without this "/"
|
138
|
-
# It consider the route inside of engine instead of main app.
|
137
|
+
# Fix for engines with shared namespace for some reason main_app.url_for doesn't find the route without this "/"
|
138
|
+
# It consider the route inside of engine instead of main app.
|
139
139
|
defaults[:controller] = "/#{defaults[:controller]}"
|
140
140
|
|
141
141
|
if instance_eval "defined? #{ctrl_namespace}"
|
@@ -171,7 +171,7 @@ module BootstrapAdminHelper
|
|
171
171
|
end
|
172
172
|
|
173
173
|
# =====
|
174
|
-
def index_default_actions
|
174
|
+
def index_default_actions
|
175
175
|
if available_actions.include? :new
|
176
176
|
model_klass = model_for controller
|
177
177
|
link_to([:new, model_klass], bootstrap_url_for(:action => :new), :class => 'btn btn-primary').html_safe
|
@@ -243,7 +243,11 @@ module BootstrapAdminHelper
|
|
243
243
|
bootstrap_admin_config.send("action_fields") ||
|
244
244
|
model_klass.accessible_attributes.
|
245
245
|
reject(&:blank?).
|
246
|
-
map{|att| real_attribute_name att }
|
246
|
+
map{|att| real_attribute_name att }.
|
247
|
+
reject do |att|
|
248
|
+
att.to_s =~ /(.+)_attributes/ &&
|
249
|
+
model_klass.reflect_on_all_associations.map(&:name).include?($1.to_sym)
|
250
|
+
end
|
247
251
|
|
248
252
|
@attributes = fields.map do |att|
|
249
253
|
BootstrapAdmin::Attribute.new att,
|
@@ -252,6 +256,20 @@ module BootstrapAdminHelper
|
|
252
256
|
end
|
253
257
|
end
|
254
258
|
|
259
|
+
# =============================================================================
|
260
|
+
# Tries to render the action/partial "namespaced" with the current action name
|
261
|
+
# if it fails, then simply calls render with whatever args that got passed in.
|
262
|
+
#
|
263
|
+
# Ex:
|
264
|
+
# # on get to '/admin/some_resource/new'
|
265
|
+
# render_with_fallback 'form' # this will to render 'new_form', if it fails,
|
266
|
+
# # then it will just call "render 'form'"
|
267
|
+
def render_with_fallback *args
|
268
|
+
render "#{params[:action]}_#{args.first}", *args[1..-1]
|
269
|
+
rescue ActionView::MissingTemplate
|
270
|
+
render *args
|
271
|
+
end
|
272
|
+
|
255
273
|
# =============================================================================
|
256
274
|
# def render_attribute name, type = :index
|
257
275
|
# # content_tag :td do
|
data/bootstrap_admin.gemspec
CHANGED
@@ -17,9 +17,10 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_runtime_dependency %q<rails>,
|
21
|
-
gem.add_runtime_dependency %q<simple_form>,
|
20
|
+
gem.add_runtime_dependency %q<rails>, ">= 3.1.0"
|
21
|
+
gem.add_runtime_dependency %q<simple_form>, ">= 2.0.0"
|
22
22
|
gem.add_runtime_dependency %q<haml>
|
23
23
|
gem.add_runtime_dependency %q<coffee-rails>
|
24
24
|
gem.add_runtime_dependency %q<jquery-rails>
|
25
|
+
gem.add_runtime_dependency %q<responders>
|
25
26
|
end
|
@@ -39,9 +39,12 @@ module BootstrapAdmin
|
|
39
39
|
private
|
40
40
|
# =============================================================================
|
41
41
|
def add_bootstrap_admin_viewpath
|
42
|
+
view_matcher_format = ":action{.:locale,}{.:formats,}{.:handlers,}"
|
43
|
+
bootstrap_admin_app_viewpath = "#{Rails.root}/app/views/#{BootstrapAdmin.admin_namespace}/defaults"
|
42
44
|
bootstrap_admin_viewpath = File.expand_path("../../../app/views/defaults", __FILE__)
|
43
|
-
|
44
|
-
|
45
|
+
|
46
|
+
self.view_paths << ActionView::FileSystemResolver.new(bootstrap_admin_app_viewpath, view_matcher_format)
|
47
|
+
self.view_paths << ActionView::FileSystemResolver.new(bootstrap_admin_viewpath, view_matcher_format)
|
45
48
|
end
|
46
49
|
|
47
50
|
end # module ClassMethods
|
data/lib/bootstrap_admin.rb
CHANGED
@@ -22,6 +22,13 @@ module BootstrapAdmin
|
|
22
22
|
class BootstrapAdminEngine < Rails::Engine
|
23
23
|
config.autoload_paths << File.expand_path("../../app/helpers", __FILE__)
|
24
24
|
end
|
25
|
+
|
26
|
+
# =============================================================================
|
27
|
+
# Returns the gem root dir
|
28
|
+
def self.root_dir
|
29
|
+
File.expand_path("../..", __FILE__)
|
30
|
+
end
|
31
|
+
|
25
32
|
# =============================================================================
|
26
33
|
# Defines the namespace where all the "bootstrap_admin" magic happens
|
27
34
|
mattr_accessor :admin_namespace
|
File without changes
|
@@ -17,6 +17,11 @@ module BootstrapAdmin
|
|
17
17
|
copy_file "en_bootstrap_admin.yml", "config/locales/en_bootstrap_admin.yml"
|
18
18
|
end
|
19
19
|
|
20
|
+
def append_to_assets
|
21
|
+
append_file "config/initializers/assets.rb",
|
22
|
+
"Rails.application.config.assets.precompile += %w( admin.css admin.js )"
|
23
|
+
end
|
24
|
+
|
20
25
|
def asset_configuration
|
21
26
|
empty_directory "app/assets/javascripts/#{namespace_parsed}"
|
22
27
|
create_file "app/assets/javascripts/#{namespace_parsed}.js" do
|
File without changes
|
data/lib/generators/bootstrap_admin/{templates → install/templates}/bootstrap_admin_menu.yml
RENAMED
File without changes
|
File without changes
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Description:
|
2
|
+
Allows you to override the default views for all bootstrap_admin actions, either globally or resource specific.
|
3
|
+
If you choose to override globally, then all views for all resources will be overridden.
|
4
|
+
If you choose to override for a specific resource, then your overrides will only affect that resources' views.
|
5
|
+
|
6
|
+
Example:
|
7
|
+
$ rails g bootstrap_admin:override_views defaults
|
8
|
+
This will:
|
9
|
+
1) Create app/views/admin/defaults folder
|
10
|
+
2) Copy all of bootstrap_admin default views to that folder for you to tweak
|
11
|
+
From there on, all resources will use these views.
|
12
|
+
|
13
|
+
$ rails g bootstrap_admin:override_views defaults index new
|
14
|
+
This will:
|
15
|
+
1) Create app/views/admin/defaults folder
|
16
|
+
2) Copy all index and new related views to that folder for you to tweak
|
17
|
+
From there on, all resources will use these views to render index or new actions.
|
18
|
+
|
19
|
+
$ rails g bootstrap_admin:override_views books
|
20
|
+
This will:
|
21
|
+
1) Create app/views/admin/books folder (if it doesn't exist already)
|
22
|
+
2) Copy all of bootstrap_admin default views to that folder for you to tweak
|
23
|
+
From there on, only book resources will use these views.
|
24
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module BootstrapAdmin
|
2
|
+
module Generators
|
3
|
+
class OverrideViewsGenerator < Rails::Generators::Base
|
4
|
+
# =============================================================================
|
5
|
+
argument :resource, :type => :string,
|
6
|
+
:default => "defaults",
|
7
|
+
:banner => "defaults or <resource>"
|
8
|
+
|
9
|
+
# =============================================================================
|
10
|
+
argument :actions, :type => :array,
|
11
|
+
:optional => true,
|
12
|
+
:banner => "index show edit ...",
|
13
|
+
:default => %w(index show new edit)
|
14
|
+
|
15
|
+
# =============================================================================
|
16
|
+
class_option :namespace, :type => :string,
|
17
|
+
:default => "admin",
|
18
|
+
:desc => "Namespace used by the bootstrap_admin"
|
19
|
+
|
20
|
+
source_root File.expand_path("../templates", __FILE__)
|
21
|
+
|
22
|
+
# =============================================================================
|
23
|
+
def copy_views
|
24
|
+
folder_base = "#{Rails.root}/app/views/#{BootstrapAdmin.admin_namespace}"
|
25
|
+
target_dir = if "defaults" == resource
|
26
|
+
"#{folder_base}/defaults" # global view folder
|
27
|
+
else
|
28
|
+
"#{folder_base}/#{resource.tableize}" # resource view folder
|
29
|
+
end
|
30
|
+
|
31
|
+
empty_directory target_dir
|
32
|
+
_copy_views_ target_dir, actions
|
33
|
+
end
|
34
|
+
|
35
|
+
# =============================================================================
|
36
|
+
protected
|
37
|
+
VIEW_DEPENDENCIES = {
|
38
|
+
"index" => ['index', '_index', '_paginator', '_search_box'],
|
39
|
+
"show" => ['show' , '_show'],
|
40
|
+
"new" => ['new' , ['_form', '_new_form'] , ['_form_fields', '_new_form_fields' ]],
|
41
|
+
"edit" => ['edit' , ['_form', '_edit_form'], ['_form_fields', '_edit_form_fields']],
|
42
|
+
"new_and_edit" => ['new' , 'edit', '_form', '_form_fields']
|
43
|
+
}
|
44
|
+
|
45
|
+
def _copy_views_ target_dir, actions
|
46
|
+
if actions & %w[new edit] == %w[new edit]
|
47
|
+
actions = actions - %w[new edit] + %w[new_and_edit]
|
48
|
+
end
|
49
|
+
|
50
|
+
actions.each do |action|
|
51
|
+
VIEW_DEPENDENCIES[action].each do |view_name, rename_to|
|
52
|
+
view = "#{BootstrapAdmin.root_dir}/app/views/defaults/#{view_name}.html.haml"
|
53
|
+
target = "#{target_dir}/#{rename_to || view_name}.html.haml"
|
54
|
+
copy_file view, target
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end # class OverrideViewsGenerator
|
60
|
+
end # module Generators
|
61
|
+
end # module BootstrapAdmin
|