administrate 0.0.4 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of administrate might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/administrate/base/_typography.scss +0 -5
- data/app/controllers/administrate/application_controller.rb +18 -31
- data/app/views/fields/show/_has_many.html.erb +9 -5
- data/config/locales/administrate.en.yml +10 -0
- data/lib/administrate/fields/has_many.rb +1 -1
- data/lib/administrate/page.rb +4 -0
- data/lib/administrate/{pages → page}/base.rb +0 -0
- data/lib/administrate/{pages → page}/form.rb +0 -0
- data/lib/administrate/{pages → page}/show.rb +0 -0
- data/lib/administrate/{pages → page}/table.rb +0 -0
- data/lib/administrate/resource_resolver.rb +41 -0
- data/lib/administrate/version.rb +1 -1
- data/lib/generators/administrate/dashboard/dashboard_generator.rb +2 -0
- data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +4 -1
- data/lib/generators/administrate/install/templates/application_controller.rb +10 -0
- metadata +22 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 110c076246ab6939cc37da4ede75207b571adf4b
|
4
|
+
data.tar.gz: 78aa661a2b45c16533009ad19fe820b3bb2cd767
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 388dc4bfd5a7a92bb8f027790625ca6286afedf90ef37309dac57f735abc7176ff9c394a23f191a79d08442c31a134eaf00bb8226813dc74b438c7ceb4ff373f
|
7
|
+
data.tar.gz: 92b2e3901c5e94ce0597a60ca518fc45f0814bc95ee6d0222839b39e34aad28aad14e96d17ee39270ba7f20304267b10d23b96d9f65a03721543b214920ed1a5
|
@@ -1,7 +1,8 @@
|
|
1
1
|
require "administrate/namespace"
|
2
|
-
require "administrate/
|
3
|
-
require "administrate/
|
4
|
-
require "administrate/
|
2
|
+
require "administrate/page/form"
|
3
|
+
require "administrate/page/table"
|
4
|
+
require "administrate/page/show"
|
5
|
+
require "administrate/resource_resolver"
|
5
6
|
|
6
7
|
module Administrate
|
7
8
|
class ApplicationController < ActionController::Base
|
@@ -32,7 +33,7 @@ module Administrate
|
|
32
33
|
if resource.save
|
33
34
|
redirect_to(
|
34
35
|
[Administrate::NAMESPACE, resource],
|
35
|
-
notice:
|
36
|
+
notice: translate("create.success"),
|
36
37
|
)
|
37
38
|
else
|
38
39
|
@page = Administrate::Page::Form.new(dashboard, resource)
|
@@ -46,7 +47,7 @@ module Administrate
|
|
46
47
|
if resource.update(resource_params)
|
47
48
|
redirect_to(
|
48
49
|
[Administrate::NAMESPACE, resource],
|
49
|
-
notice:
|
50
|
+
notice: translate("update.success"),
|
50
51
|
)
|
51
52
|
else
|
52
53
|
@page = Administrate::Page::Form.new(dashboard, resource)
|
@@ -58,7 +59,7 @@ module Administrate
|
|
58
59
|
set_resource
|
59
60
|
|
60
61
|
resource.destroy
|
61
|
-
flash[:notice] =
|
62
|
+
flash[:notice] = translate("destroy.success")
|
62
63
|
redirect_to action: :index
|
63
64
|
end
|
64
65
|
|
@@ -71,12 +72,8 @@ module Administrate
|
|
71
72
|
end
|
72
73
|
end
|
73
74
|
|
74
|
-
def resource_class
|
75
|
-
Object.const_get(resource_class_name)
|
76
|
-
end
|
77
|
-
|
78
75
|
def dashboard
|
79
|
-
@dashboard ||= dashboard_class.new
|
76
|
+
@dashboard ||= resource_resolver.dashboard_class.new
|
80
77
|
end
|
81
78
|
|
82
79
|
def set_resource(resource = nil)
|
@@ -89,39 +86,29 @@ module Administrate
|
|
89
86
|
end
|
90
87
|
|
91
88
|
def resource_params
|
92
|
-
params.require(
|
89
|
+
params.require(resource_name).permit(*permitted_attributes)
|
93
90
|
end
|
94
91
|
|
95
92
|
def permitted_attributes
|
96
93
|
dashboard.permitted_attributes
|
97
94
|
end
|
98
95
|
|
99
|
-
def dashboard_class
|
100
|
-
Object.const_get("#{resource_class_name}Dashboard")
|
101
|
-
end
|
102
|
-
|
103
|
-
def resource_class_name
|
104
|
-
resource_name.to_s.camelcase
|
105
|
-
end
|
106
|
-
|
107
96
|
def instance_variable
|
108
97
|
"@#{resource_name}"
|
109
98
|
end
|
110
99
|
|
111
|
-
|
112
|
-
resource_class_name.titleize
|
113
|
-
end
|
100
|
+
delegate :resource_class, :resource_name, to: :resource_resolver
|
114
101
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
updated: "#{resource_title} was successfully updated.",
|
119
|
-
destroyed: "#{resource_title} was successfully destroyed.",
|
120
|
-
}
|
102
|
+
def resource_resolver
|
103
|
+
@resource_resolver ||=
|
104
|
+
Administrate::ResourceResolver.new(controller_path)
|
121
105
|
end
|
122
106
|
|
123
|
-
def
|
124
|
-
|
107
|
+
def translate(key)
|
108
|
+
t(
|
109
|
+
"administrate.controller.#{key}",
|
110
|
+
resource: resource_resolver.resource_title,
|
111
|
+
)
|
125
112
|
end
|
126
113
|
end
|
127
114
|
end
|
@@ -1,5 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
<% if has_many.data.any? %>
|
2
|
+
<%= render(
|
3
|
+
"table",
|
4
|
+
table_presenter: has_many.associated_table,
|
5
|
+
resources: has_many.data
|
6
|
+
) %>
|
7
|
+
<% else %>
|
8
|
+
<%= t("administrate.fields.has_many.none") %>
|
9
|
+
<% end %>
|
@@ -5,3 +5,13 @@ en:
|
|
5
5
|
edit: Edit
|
6
6
|
destroy: Destroy
|
7
7
|
confirm: Are you sure?
|
8
|
+
fields:
|
9
|
+
has_many:
|
10
|
+
none: None
|
11
|
+
controller:
|
12
|
+
create:
|
13
|
+
success: "%{resource} was successfully created."
|
14
|
+
update:
|
15
|
+
success: "%{resource} was successfully updated."
|
16
|
+
destroy:
|
17
|
+
success: "%{resource} was successfully destroyed."
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require "administrate/namespace"
|
2
|
+
|
3
|
+
module Administrate
|
4
|
+
class ResourceResolver
|
5
|
+
def initialize(controller_path)
|
6
|
+
@controller_path = controller_path
|
7
|
+
end
|
8
|
+
|
9
|
+
def dashboard_class
|
10
|
+
Object.const_get(resource_class_name + "Dashboard")
|
11
|
+
end
|
12
|
+
|
13
|
+
def resource_class
|
14
|
+
Object.const_get(resource_class_name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def resource_name
|
18
|
+
model_path_parts.map(&:underscore).join("__").to_sym
|
19
|
+
end
|
20
|
+
|
21
|
+
def resource_title
|
22
|
+
model_path_parts.join(" ")
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def resource_class_name
|
28
|
+
model_path_parts.join("::")
|
29
|
+
end
|
30
|
+
|
31
|
+
def model_path_parts
|
32
|
+
controller_path_parts.map(&:camelize)
|
33
|
+
end
|
34
|
+
|
35
|
+
def controller_path_parts
|
36
|
+
controller_path.singularize.split("/") - [Administrate::NAMESPACE.to_s]
|
37
|
+
end
|
38
|
+
|
39
|
+
attr_reader :controller_path
|
40
|
+
end
|
41
|
+
end
|
data/lib/administrate/version.rb
CHANGED
@@ -16,8 +16,11 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
|
|
16
16
|
|
17
17
|
# This method returns an array of attributes
|
18
18
|
# that will be displayed on the model's index page.
|
19
|
+
#
|
20
|
+
# By default, it's limited to four items to reduce clutter on index pages.
|
21
|
+
# Feel free to remove the limit or customize the returned array.
|
19
22
|
def table_attributes
|
20
|
-
attributes
|
23
|
+
attributes.first(<%= TABLE_ATTRIBUTE_LIMIT %>)
|
21
24
|
end
|
22
25
|
|
23
26
|
# This method returns an array of attributes
|
@@ -10,4 +10,14 @@ class Admin::ApplicationController < Administrate::ApplicationController
|
|
10
10
|
def authenticate_admin
|
11
11
|
# TODO Add authentication logic here.
|
12
12
|
end
|
13
|
+
|
14
|
+
def index
|
15
|
+
super
|
16
|
+
|
17
|
+
flash[:alert] =
|
18
|
+
"For performance, Administrate limits the index page to show 20 items.
|
19
|
+
Customize this action to update/remove the limit,
|
20
|
+
or implement the pagination library of your choice."
|
21
|
+
@resources = @resources.limit(20)
|
22
|
+
end
|
13
23
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: administrate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grayson Wright
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: neat
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sass
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.4'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.4'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: normalize-rails
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,10 +166,12 @@ files:
|
|
152
166
|
- lib/administrate/fields/image.rb
|
153
167
|
- lib/administrate/fields/string.rb
|
154
168
|
- lib/administrate/namespace.rb
|
155
|
-
- lib/administrate/
|
156
|
-
- lib/administrate/
|
157
|
-
- lib/administrate/
|
158
|
-
- lib/administrate/
|
169
|
+
- lib/administrate/page.rb
|
170
|
+
- lib/administrate/page/base.rb
|
171
|
+
- lib/administrate/page/form.rb
|
172
|
+
- lib/administrate/page/show.rb
|
173
|
+
- lib/administrate/page/table.rb
|
174
|
+
- lib/administrate/resource_resolver.rb
|
159
175
|
- lib/administrate/version.rb
|
160
176
|
- lib/generators/administrate/dashboard/USAGE
|
161
177
|
- lib/generators/administrate/dashboard/dashboard_generator.rb
|