bootstrap_admin 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +246 -0
- data/Rakefile +1 -0
- data/app/assets/images/cross.gif +0 -0
- data/app/assets/images/search_btn.png +0 -0
- data/app/assets/javascripts/bootstrap_admin/bootstrap_admin.js.coffee +13 -0
- data/app/assets/javascripts/bootstrap_admin.js +5 -0
- data/app/assets/stylesheets/_backgrounds.scss +12 -0
- data/app/assets/stylesheets/bootstrap_admin.css +12 -0
- data/app/assets/stylesheets/bootstrap_overrides.css.scss +173 -0
- data/app/helpers/bootstrap_admin/menu_helper.rb +117 -0
- data/app/helpers/bootstrap_admin/paginator_helper.rb +115 -0
- data/app/helpers/bootstrap_admin_helper.rb +235 -0
- data/app/views/admin/shared/_flash_area.html.haml +6 -0
- data/app/views/admin/shared/_login_area.html.haml +0 -0
- data/app/views/admin/shared/_navigation.html.haml +8 -0
- data/app/views/defaults/_form.html.haml +9 -0
- data/app/views/defaults/_form_fields.html.haml +5 -0
- data/app/views/defaults/_index.html.haml +17 -0
- data/app/views/defaults/_paginator.html.haml +6 -0
- data/app/views/defaults/_search_box.html.haml +7 -0
- data/app/views/defaults/_show.html.haml +4 -0
- data/app/views/defaults/edit.html.haml +3 -0
- data/app/views/defaults/index.html.haml +14 -0
- data/app/views/defaults/new.html.haml +3 -0
- data/app/views/defaults/show.html.haml +11 -0
- data/app/views/layouts/bootstrap_admin.html.haml +16 -0
- data/bootstrap_admin.gemspec +25 -0
- data/config/initializers/simple_form.rb +34 -0
- data/config/locales/en.yml +5 -0
- data/lib/bootstrap_admin/actions.rb +121 -0
- data/lib/bootstrap_admin/active_record_extensions.rb +17 -0
- data/lib/bootstrap_admin/attribute.rb +34 -0
- data/lib/bootstrap_admin/controller_config.rb +57 -0
- data/lib/bootstrap_admin/controller_helpers.rb +78 -0
- data/lib/bootstrap_admin/responder.rb +157 -0
- data/lib/bootstrap_admin/routes.rb +28 -0
- data/lib/bootstrap_admin/version.rb +3 -0
- data/lib/bootstrap_admin.rb +58 -0
- data/lib/generators/bootstrap_admin/USAGE +24 -0
- data/lib/generators/bootstrap_admin/install_generator.rb +67 -0
- data/lib/generators/bootstrap_admin/templates/bootstrap_admin.rb +18 -0
- data/lib/generators/bootstrap_admin/templates/bootstrap_admin_menu.yml +37 -0
- data/lib/generators/bootstrap_admin/templates/en_bootstrap_admin.yml +37 -0
- data/vendor/assets/images/glyphicons-halflings-white.png +0 -0
- data/vendor/assets/images/glyphicons-halflings.png +0 -0
- data/vendor/assets/images/jqueryui/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/vendor/assets/images/jqueryui/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/vendor/assets/images/jqueryui/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/vendor/assets/images/jqueryui/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/vendor/assets/images/jqueryui/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/vendor/assets/images/jqueryui/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/vendor/assets/images/jqueryui/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/vendor/assets/images/jqueryui/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/vendor/assets/images/jqueryui/ui-icons_222222_256x240.png +0 -0
- data/vendor/assets/images/jqueryui/ui-icons_2e83ff_256x240.png +0 -0
- data/vendor/assets/images/jqueryui/ui-icons_454545_256x240.png +0 -0
- data/vendor/assets/images/jqueryui/ui-icons_888888_256x240.png +0 -0
- data/vendor/assets/images/jqueryui/ui-icons_cd0a0a_256x240.png +0 -0
- data/vendor/assets/javascripts/bootstrap.js +2025 -0
- data/vendor/assets/javascripts/bootstrap.min.js +6 -0
- data/vendor/assets/javascripts/jquery-ui-1.9.2.custom.min.js +6 -0
- data/vendor/assets/stylesheets/bootstrap-responsive.css +1088 -0
- data/vendor/assets/stylesheets/bootstrap-responsive.min.css +9 -0
- data/vendor/assets/stylesheets/bootstrap.css +5893 -0
- data/vendor/assets/stylesheets/bootstrap.min.css +9 -0
- data/vendor/assets/stylesheets/jquery-ui-1.9.2.custom.css +462 -0
- metadata +197 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
# => TODO: This looks like a monkeypatch.. make this "the right way"..
|
3
|
+
ActiveRecord::Base.class_eval do
|
4
|
+
def self.type_of name
|
5
|
+
name = name.to_sym
|
6
|
+
associations = self.reflect_on_all_associations.map(&:name)
|
7
|
+
if name.match(/(.*)_id(s)?$/) and associations.include? "#{$1}#{$2}"
|
8
|
+
:association
|
9
|
+
elsif associations.include? name
|
10
|
+
:association
|
11
|
+
elsif self.attribute_names.include? name.to_s
|
12
|
+
:attribute
|
13
|
+
else
|
14
|
+
:none
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module BootstrapAdmin
|
2
|
+
|
3
|
+
# BootstrapAdmin::Attribute represents a model attribute and stores
|
4
|
+
# its name, human_name and a computed "type" which can be one of:
|
5
|
+
# :association
|
6
|
+
# :attribute
|
7
|
+
# :none
|
8
|
+
# (take a look at active_record_extensions).
|
9
|
+
#
|
10
|
+
# This is used to build UI elements, see:
|
11
|
+
# app/views/defaults/show
|
12
|
+
# app/views/defaults/form
|
13
|
+
# app/views/defaults/index
|
14
|
+
|
15
|
+
class Attribute
|
16
|
+
attr_reader :name, :human_name, :type
|
17
|
+
|
18
|
+
def initialize name, human_name, type
|
19
|
+
@name, @human_name, @type = name, human_name, type
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [String] the attribute's name
|
23
|
+
def to_s; name.to_s; end
|
24
|
+
|
25
|
+
# @return [Symbol] the attribute's name, but as a Symbol
|
26
|
+
def to_sym; to_s.to_sym; end
|
27
|
+
|
28
|
+
# @return [true, false] true if type is :association, false otherwise
|
29
|
+
def association?; :association == type; end
|
30
|
+
|
31
|
+
# @return [true, false] true if type is :attribute, false otherwise
|
32
|
+
def attribute?; :attribute == type; end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module BootstrapAdmin
|
2
|
+
# Defines each controllers specific configuration
|
3
|
+
class ControllerConfig
|
4
|
+
DEFAULTS = {
|
5
|
+
:responder_formats => [:html, :json]
|
6
|
+
}
|
7
|
+
|
8
|
+
# controller's namespace
|
9
|
+
attr_accessor :namespace
|
10
|
+
|
11
|
+
# Responded formats
|
12
|
+
attr_accessor :responder_formats
|
13
|
+
|
14
|
+
# Fields to be used on the index action
|
15
|
+
attr_accessor :index_fields
|
16
|
+
|
17
|
+
# Fields to be used on the show action
|
18
|
+
attr_accessor :show_fields
|
19
|
+
|
20
|
+
# Fields to be used on form (edit/new/create/update) actions
|
21
|
+
attr_accessor :form_fields
|
22
|
+
alias_method :edit_fields, :form_fields
|
23
|
+
alias_method :new_fields, :form_fields
|
24
|
+
alias_method :create_fields, :form_fields
|
25
|
+
alias_method :update_fields, :form_fields
|
26
|
+
|
27
|
+
# Fields to be used on ALL actions
|
28
|
+
# These are used when none of the {action}_fields are defined
|
29
|
+
attr_accessor :action_fields
|
30
|
+
|
31
|
+
# Searchable fields
|
32
|
+
attr_accessor :searchable_fields
|
33
|
+
|
34
|
+
# Available Actions
|
35
|
+
attr_accessor :available_actions
|
36
|
+
|
37
|
+
# =============================================================================
|
38
|
+
def initialize options = {}
|
39
|
+
options = DEFAULTS.merge options
|
40
|
+
|
41
|
+
# namespace
|
42
|
+
@namespace = options[:namespace] || BootstrapAdmin.admin_namespace
|
43
|
+
|
44
|
+
# responder responder_formats
|
45
|
+
@responder_formats = options[:responder_formats]
|
46
|
+
|
47
|
+
# fields to be shown @ index
|
48
|
+
# @index_fields = options[:index_fields]
|
49
|
+
|
50
|
+
# fields to be shown @ show
|
51
|
+
# @show_fields = options[:show_fields]
|
52
|
+
|
53
|
+
@available_actions = [:new, :show, :edit, :destroy]
|
54
|
+
end
|
55
|
+
# =============================================================================
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module BootstrapAdmin
|
2
|
+
module ControllerHelpers
|
3
|
+
# =============================================================================
|
4
|
+
module ClassMethods
|
5
|
+
# Controller Macro to define and configure bootstrap_admin
|
6
|
+
#
|
7
|
+
# When you run this macro on a controller, it:
|
8
|
+
# * sets BootstrapAdmin::Responder as the controller's responder
|
9
|
+
# * includes BootstrapAdmin::Actions, defining the controller's default actions
|
10
|
+
# * adds helpers (bootstrap_admin, bootstrap_admin/paginator and bootstrap_admin/menu)
|
11
|
+
# * adds the bootstrap_admin default views to the viewpath
|
12
|
+
#
|
13
|
+
# == Parameters
|
14
|
+
# +block+:: an optional code block that will receive an instance of BootstrapAdmin::ControllerConfig
|
15
|
+
# to configure controller specific stuff, such as index_fields, etc..
|
16
|
+
def bootstrap_admin &block
|
17
|
+
@bootstrap_admin_config = BootstrapAdmin::ControllerConfig.new # config
|
18
|
+
if block_given?
|
19
|
+
block.call @bootstrap_admin_config
|
20
|
+
end
|
21
|
+
|
22
|
+
self.respond_to *@bootstrap_admin_config.responder_formats
|
23
|
+
self.responder = BootstrapAdmin::Responder
|
24
|
+
# setup bootstrap_admin viewpath
|
25
|
+
add_bootstrap_admin_viewpath
|
26
|
+
|
27
|
+
# add bootstrap_admin helpers
|
28
|
+
helper "bootstrap_admin"
|
29
|
+
helper "bootstrap_admin/paginator"
|
30
|
+
helper "bootstrap_admin/menu"
|
31
|
+
|
32
|
+
layout "bootstrap_admin"
|
33
|
+
|
34
|
+
# add bootstrap_admin actions
|
35
|
+
self.send :include, BootstrapAdmin::Actions
|
36
|
+
helper_method :bootstrap_admin_config
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
# =============================================================================
|
41
|
+
def add_bootstrap_admin_viewpath
|
42
|
+
bootstrap_admin_viewpath = File.expand_path("../../../app/views/defaults", __FILE__)
|
43
|
+
self.view_paths << ActionView::FileSystemResolver.new(
|
44
|
+
bootstrap_admin_viewpath, ":action{.:locale,}{.:formats,}{.:handlers,}")
|
45
|
+
end
|
46
|
+
|
47
|
+
end # module ClassMethods
|
48
|
+
|
49
|
+
# =============================================================================
|
50
|
+
# Helper method - provides access to the controller config on the views
|
51
|
+
def bootstrap_admin_config
|
52
|
+
self.class.instance_variable_get "@bootstrap_admin_config"
|
53
|
+
end
|
54
|
+
|
55
|
+
# =============================================================================
|
56
|
+
# Eases the access to config properties via bootstrap_admin_config
|
57
|
+
def method_missing method, *args
|
58
|
+
if bootstrap_admin_config.respond_to? method
|
59
|
+
bootstrap_admin_config.send method, *args
|
60
|
+
else
|
61
|
+
super method, *args
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
# self responds_to bootstrap_admin_config methods via method_missing!
|
66
|
+
def respond_to? method, include_private = false
|
67
|
+
true if bootstrap_admin_config.respond_to? method
|
68
|
+
super method, include_private
|
69
|
+
end
|
70
|
+
|
71
|
+
# =============================================================================
|
72
|
+
def self.included base
|
73
|
+
base.extend ClassMethods
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
ActionController::Base.class_eval { include BootstrapAdmin::ControllerHelpers }
|
@@ -0,0 +1,157 @@
|
|
1
|
+
module BootstrapAdmin
|
2
|
+
class Responder < ActionController::Responder
|
3
|
+
# =============================================================================
|
4
|
+
# Responds to any format...
|
5
|
+
def to_format
|
6
|
+
render @format => format_resource(@resource, @format),
|
7
|
+
:status => status_for_resource(@resource),
|
8
|
+
:content_type => content_type_for(@format)
|
9
|
+
end
|
10
|
+
|
11
|
+
# =============================================================================
|
12
|
+
# Responds to HTML format
|
13
|
+
#
|
14
|
+
# It sets flash messages, handles search, sets pagination (@paginator)
|
15
|
+
def to_html
|
16
|
+
if get? && resource.is_a?(ActiveRecord::Relation)
|
17
|
+
items = process_search resource
|
18
|
+
items, paginator = paginate items
|
19
|
+
|
20
|
+
controller.instance_variable_set("@#{controller.controller_name}", items)
|
21
|
+
controller.instance_variable_set("@paginator", paginator)
|
22
|
+
if request.xhr?
|
23
|
+
render controller.params[:action], layout: false
|
24
|
+
end
|
25
|
+
elsif resource.is_a?(ActiveRecord::Base) && (post? || put?) && resource.valid?
|
26
|
+
message = if post?
|
27
|
+
'helpers.messages.create.success'
|
28
|
+
else #put?
|
29
|
+
'helpers.messages.update.success'
|
30
|
+
end
|
31
|
+
controller.flash[:success] = I18n.t(message, :model => resource.class.model_name.human)
|
32
|
+
redirect_to @resources
|
33
|
+
|
34
|
+
else
|
35
|
+
if delete?
|
36
|
+
controller.flash[:success] = I18n.t("helpers.messages.destroy.success", :model => resource.class.model_name.human)
|
37
|
+
end
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
# =============================================================================
|
44
|
+
def paginate resource
|
45
|
+
current_page = (controller.params[:page] || 1).to_i
|
46
|
+
per_page = (controller.params[:pp] || BootstrapAdmin.paginator_page_size).to_i
|
47
|
+
count = resource_count(resource)
|
48
|
+
pages = (count.to_f/per_page).ceil
|
49
|
+
paginator = {
|
50
|
+
:current_page => current_page,
|
51
|
+
:count => count,
|
52
|
+
:pages => pages > 0 ? pages : 1
|
53
|
+
}
|
54
|
+
items = resource.offset( (current_page-1)*per_page ).limit(per_page)
|
55
|
+
|
56
|
+
return items, paginator
|
57
|
+
end
|
58
|
+
|
59
|
+
# =============================================================================
|
60
|
+
def resource_count resource
|
61
|
+
values = resource.includes_values
|
62
|
+
to_remove = resource.reflect_on_all_associations.select{|a| a.options[:polymorphic]}.map &:name
|
63
|
+
resource.includes_values -= to_remove
|
64
|
+
count = resource.count
|
65
|
+
resource.includes_values = values
|
66
|
+
|
67
|
+
return count
|
68
|
+
end
|
69
|
+
|
70
|
+
# =============================================================================
|
71
|
+
def process_search resource
|
72
|
+
result = resource
|
73
|
+
fields = search_fields resource
|
74
|
+
|
75
|
+
if controller.params[:q] and !fields.blank?
|
76
|
+
conditions = fields.map do |field|
|
77
|
+
if field.is_a? Symbol or field.is_a? String
|
78
|
+
"#{resource.table_name}.#{field} like ?"
|
79
|
+
|
80
|
+
elsif field.is_a? Hash
|
81
|
+
resource, sconds = process_search_hash(resource, field)
|
82
|
+
sconds
|
83
|
+
end
|
84
|
+
end.flatten.compact
|
85
|
+
|
86
|
+
params = ["%#{controller.params[:q]}%"] * conditions.count
|
87
|
+
result = resource.where(conditions.join(" OR "), *params)
|
88
|
+
end
|
89
|
+
|
90
|
+
result
|
91
|
+
end
|
92
|
+
|
93
|
+
# =============================================================================
|
94
|
+
def search_fields resource
|
95
|
+
if controller.searchable_fields.blank?
|
96
|
+
accessible = resource.accessible_attributes.reject &:blank?
|
97
|
+
text_fields = resource.columns.
|
98
|
+
select{|c| [:string, :text].include? c.type}.
|
99
|
+
map(&:name)
|
100
|
+
text_fields & accessible
|
101
|
+
else
|
102
|
+
controller.searchable_fields
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# =============================================================================
|
107
|
+
def process_search_hash resource, hash
|
108
|
+
conditions = hash.keys.map do |key|
|
109
|
+
assoc = resource.reflect_on_association(key)
|
110
|
+
if assoc.options[:polymorphic]
|
111
|
+
next
|
112
|
+
else
|
113
|
+
resource = resource.joins <<-SQL
|
114
|
+
LEFT JOIN #{assoc.table_name}
|
115
|
+
on (#{resource.table_name}.#{assoc.foreign_key} = #{assoc.klass.table_name}.#{assoc.klass.primary_key})
|
116
|
+
SQL
|
117
|
+
if hash[key].is_a? Symbol or hash[key].is_a? String
|
118
|
+
"#{assoc.table_name}.#{hash[key]} like ?"
|
119
|
+
|
120
|
+
elsif hash[key].is_a? Array
|
121
|
+
hash[key].map{|col| "#{assoc.table_name}.#{col} like ?" }
|
122
|
+
|
123
|
+
elsif hash[key].is_a? Hash
|
124
|
+
process_search_hash(resource, hash[key])
|
125
|
+
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
return resource, conditions
|
130
|
+
end
|
131
|
+
|
132
|
+
# =============================================================================
|
133
|
+
def content_type_for format
|
134
|
+
"application/#{format}"
|
135
|
+
end
|
136
|
+
|
137
|
+
# =============================================================================
|
138
|
+
def format_resource resource, format
|
139
|
+
if resource.is_a?(ActiveRecord::Base) and not resource.valid?
|
140
|
+
resource.errors.send "to_#{format}"
|
141
|
+
else
|
142
|
+
resource.send "to_#{format}"
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
# =============================================================================
|
147
|
+
def status_for_resource(resource)
|
148
|
+
if resource.is_a?(ActiveRecord::Base) and not resource.valid?
|
149
|
+
403
|
150
|
+
else
|
151
|
+
200
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
end # class Responder
|
156
|
+
end # module BootstrapAdmin
|
157
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ActionDispatch::Routing
|
2
|
+
class Mapper
|
3
|
+
# =============================================================================
|
4
|
+
# Defines the routes to the bootstrap_admin controllers of your app and also
|
5
|
+
# defines a "admin root" route based on the bootstrap_admin namespace
|
6
|
+
#
|
7
|
+
# == Parameters
|
8
|
+
# +options+:: regular route options for the "admin root"
|
9
|
+
# +block+:: A block configuring namespaced routes, just like a regular
|
10
|
+
# namespace route block
|
11
|
+
def bootstrap_admin options = {}, &block
|
12
|
+
admin_namespace = options.delete(:namespace) || BootstrapAdmin.admin_namespace
|
13
|
+
BootstrapAdmin.admin_namespace = admin_namespace
|
14
|
+
|
15
|
+
root_options = BootstrapAdmin.admin_root_options.
|
16
|
+
merge({:to => admin_namespace.to_s}).
|
17
|
+
merge(options)
|
18
|
+
resource admin_namespace, root_options
|
19
|
+
|
20
|
+
if block_given?
|
21
|
+
namespace admin_namespace do
|
22
|
+
block.call
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end # bootstrap_admin
|
26
|
+
|
27
|
+
end # class Mapper
|
28
|
+
end # module ActionDispatch::Routing
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# -----------------------------------------------------------------------------
|
2
|
+
require 'rails'
|
3
|
+
require 'haml'
|
4
|
+
require 'simple_form'
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
require 'active_support/dependencies'
|
7
|
+
# -----------------------------------------------------------------------------
|
8
|
+
require 'bootstrap_admin/actions'
|
9
|
+
require 'bootstrap_admin/active_record_extensions'
|
10
|
+
require 'bootstrap_admin/attribute'
|
11
|
+
require 'bootstrap_admin/version'
|
12
|
+
require 'bootstrap_admin/responder'
|
13
|
+
require 'bootstrap_admin/controller_config'
|
14
|
+
require 'bootstrap_admin/controller_helpers'
|
15
|
+
require 'bootstrap_admin/routes'
|
16
|
+
# -----------------------------------------------------------------------------
|
17
|
+
require File.expand_path("../../config/initializers/simple_form.rb", __FILE__)
|
18
|
+
# -----------------------------------------------------------------------------
|
19
|
+
|
20
|
+
# Bootstrap admin eases the tedious task of building admin interfaces
|
21
|
+
module BootstrapAdmin
|
22
|
+
class BootstrapAdminEngine < Rails::Engine
|
23
|
+
config.autoload_paths << File.expand_path("../../app/helpers", __FILE__)
|
24
|
+
end
|
25
|
+
# =============================================================================
|
26
|
+
# Defines the namespace where all the "bootstrap_admin" magic happens
|
27
|
+
mattr_accessor :admin_namespace
|
28
|
+
@@admin_namespace = :admin
|
29
|
+
|
30
|
+
# =============================================================================
|
31
|
+
# mattr_accessor :admin_root_url
|
32
|
+
# @@admin_root_url = nil
|
33
|
+
|
34
|
+
# =============================================================================
|
35
|
+
# Defines the route options for the "admin root"
|
36
|
+
mattr_accessor :admin_root_options
|
37
|
+
@@admin_root_options = {:only => :show}
|
38
|
+
|
39
|
+
# =============================================================================
|
40
|
+
# Defines de number of items per page
|
41
|
+
mattr_accessor :paginator_page_size
|
42
|
+
@@paginator_page_size = 10
|
43
|
+
|
44
|
+
# =============================================================================
|
45
|
+
#
|
46
|
+
mattr_accessor :ui_styles
|
47
|
+
@@ui_styles = {
|
48
|
+
index: %w(table-bordered table-striped)
|
49
|
+
}
|
50
|
+
# =============================================================================
|
51
|
+
# Setup BootstrapAdmin
|
52
|
+
# Run rails generate bootstrap_admin:install
|
53
|
+
# to create a fresh initializer with all configuration values.
|
54
|
+
def self.setup
|
55
|
+
yield self
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Description:
|
2
|
+
Copies bootstrap_admin's initializer, menu config file to your application.
|
3
|
+
Generates javascript and css structure needed to use and enhance bootstrap_admin's assets.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
1) rails g bootstrap_admin:install
|
7
|
+
|
8
|
+
This will:
|
9
|
+
1) Create config/initializers/bootstrap_admin.rb with bootstrap_admin's configurations
|
10
|
+
2) Create config/bootstrap_admin_menu.yml with bootstrap_admin's menu configurations
|
11
|
+
3) Creates manifest files with directives to use bootstrap_admin's assets
|
12
|
+
and complement them with host app's assets
|
13
|
+
- admin.js
|
14
|
+
- admin.css
|
15
|
+
|
16
|
+
2) rails g bootstrap_admin:install --namespace=MyAdmin
|
17
|
+
|
18
|
+
This will:
|
19
|
+
1) Create config/initializers/bootstrap_admin.rb with bootstrap_admin's configurations
|
20
|
+
2) Create config/bootstrap_admin_menu.yml with bootstrap_admin's menu configurations
|
21
|
+
3) Creates manifest files with directives to use bootstrap_admin's assets
|
22
|
+
and complement them with host app's assets
|
23
|
+
- my_admin.js
|
24
|
+
- my_admin.css
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module BootstrapAdmin
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
|
6
|
+
class_option :namespace, :type => :string, :default => "admin", :desc => "Namespace used by the bootstrap_admin"
|
7
|
+
|
8
|
+
def copy_initializer
|
9
|
+
template "bootstrap_admin.rb", "config/initializers/bootstrap_admin.rb"
|
10
|
+
end
|
11
|
+
|
12
|
+
def copy_bootstrap_admin_menu
|
13
|
+
copy_file "bootstrap_admin_menu.yml", "config/bootstrap_admin_menu.yml"
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_locale_file
|
17
|
+
copy_file "en_bootstrap_admin.yml", "config/locales/en_bootstrap_admin.yml"
|
18
|
+
end
|
19
|
+
|
20
|
+
def asset_configuration
|
21
|
+
empty_directory "app/assets/javascripts/#{namespace_parsed}"
|
22
|
+
create_file "app/assets/javascripts/#{namespace_parsed}.js" do
|
23
|
+
<<-JS_INFO.strip_heredoc
|
24
|
+
// Loads all bootstrap_admin javascripts
|
25
|
+
//= require bootstrap_admin
|
26
|
+
//= require_tree ./#{namespace_parsed}
|
27
|
+
JS_INFO
|
28
|
+
end
|
29
|
+
|
30
|
+
empty_directory "app/assets/stylesheets/#{namespace_parsed}"
|
31
|
+
create_file "app/assets/stylesheets/#{namespace_parsed}.css" do
|
32
|
+
<<-CSS_INFO.strip_heredoc
|
33
|
+
/*
|
34
|
+
*= require bootstrap_admin.css
|
35
|
+
*= require_self
|
36
|
+
*= require_tree ./#{namespace_parsed}
|
37
|
+
*/
|
38
|
+
CSS_INFO
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def create_admin_controller
|
43
|
+
create_file "app/controllers/#{namespace_parsed}_controller.rb" do
|
44
|
+
<<-RUBY.strip_heredoc
|
45
|
+
class #{options.namespace.classify}Controller < ApplicationController
|
46
|
+
layout "bootstrap_admin"
|
47
|
+
helper "bootstrap_admin/menu"
|
48
|
+
end
|
49
|
+
RUBY
|
50
|
+
end
|
51
|
+
|
52
|
+
create_file "app/views/#{namespace_parsed}/show.html.haml" do
|
53
|
+
<<-HAML.strip_heredoc
|
54
|
+
%p Hello!
|
55
|
+
%p Find me @ app/views/#{namespace_parsed}/show.html.haml
|
56
|
+
HAML
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def namespace_parsed
|
63
|
+
options.namespace.underscore
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
BootstrapAdmin.setup do |config|
|
2
|
+
|
3
|
+
# ==> Admin namespace configuration
|
4
|
+
# Configure namespace used for the scope of this admin
|
5
|
+
# Default value: :admin
|
6
|
+
config.admin_namespace = "<%= namespace_parsed %>"
|
7
|
+
|
8
|
+
# ==> Paginator configuration
|
9
|
+
# Configure the number of results shown per page by the paginator.
|
10
|
+
# Default value: 10
|
11
|
+
# config.paginator_page_size = 10
|
12
|
+
|
13
|
+
# ==> UI Styles
|
14
|
+
# Configure the css class names that each action wrapper will have
|
15
|
+
# Default value: {index: %w(table-bordered table-striped)}
|
16
|
+
# config.ui_styles[:index] << "my_awesome_style_class"
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# This is where you can define the bootstrap admin menu.
|
2
|
+
# Menus can only have 2 levels (root level and secondary level [for dropdown menu entries]).
|
3
|
+
# You must supply a list of menu entries.
|
4
|
+
# To do that, you can use this set of options
|
5
|
+
# :label - the label that will be presented in the menu
|
6
|
+
# :class - the css class to apply to the item
|
7
|
+
# :url - the url to be used on the item link.
|
8
|
+
# :item - one of 3 things: a String, an Array or a Symbol
|
9
|
+
# * String: must be a name of a model. The supplied model will be used to build
|
10
|
+
# the link url, as well as the label if not supplied
|
11
|
+
# * Array: This will indicate that the item is in fact a dropdown menu. In this case
|
12
|
+
# :label MUST be supplied.
|
13
|
+
# * Symbol: currently only ":divider" is supported and produces a division between
|
14
|
+
# dropdown elements. In this case, both :label and :url will be ignored
|
15
|
+
#
|
16
|
+
#
|
17
|
+
# Examples:
|
18
|
+
# * Simple menu item based on a known model
|
19
|
+
# - :item: Document
|
20
|
+
#
|
21
|
+
# * Simple menu item based on a model with a custom label and a custom css class
|
22
|
+
# - :item: Author
|
23
|
+
# :label: The guys who done things
|
24
|
+
# :class: really_bold
|
25
|
+
#
|
26
|
+
# * Simple menu item based on a model with a custom url
|
27
|
+
# - :item: Search
|
28
|
+
# :url: "https://google.com"
|
29
|
+
#
|
30
|
+
# * Dropdown menu item with several options and a divider
|
31
|
+
# - :label: "User Administration"
|
32
|
+
# :url: "#"
|
33
|
+
# :item:
|
34
|
+
# - :item: Role
|
35
|
+
# - :item: :divider
|
36
|
+
# - :item: User
|
37
|
+
# :label: Dudes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
en:
|
2
|
+
listing: "Listing %{elem}"
|
3
|
+
showing: "Showing %{elem}"
|
4
|
+
back: Back
|
5
|
+
new: New
|
6
|
+
update: Update
|
7
|
+
show: View
|
8
|
+
edit: Edit
|
9
|
+
destroy: Remove
|
10
|
+
previous: Previous
|
11
|
+
next: Next
|
12
|
+
actions: Actions
|
13
|
+
app_name: "!APP NAME!"
|
14
|
+
confirm: Are you sure?
|
15
|
+
|
16
|
+
placeholder:
|
17
|
+
search: Search...
|
18
|
+
date: Date...
|
19
|
+
|
20
|
+
helpers:
|
21
|
+
messages:
|
22
|
+
create:
|
23
|
+
success: "%{model} created successfully!"
|
24
|
+
update:
|
25
|
+
success: "%{model} updated successfully!"
|
26
|
+
destroy:
|
27
|
+
success: "%{model} removed successfully!"
|
28
|
+
|
29
|
+
select:
|
30
|
+
prompt: "Select an option"
|
31
|
+
|
32
|
+
submit:
|
33
|
+
new: 'New %{model}'
|
34
|
+
edit: 'Edit %{model}'
|
35
|
+
create: 'Create %{model}'
|
36
|
+
update: 'Update %{model}'
|
37
|
+
submit: 'Save %{model}'
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|