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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7cdb61f2f894654954ec8030160c5d818c507705
4
- data.tar.gz: 8bd69bc151425100e99aca7c7c6ba078d6ef111a
3
+ metadata.gz: 110c076246ab6939cc37da4ede75207b571adf4b
4
+ data.tar.gz: 78aa661a2b45c16533009ad19fe820b3bb2cd767
5
5
  SHA512:
6
- metadata.gz: 94c1e82a6b692e385becac51fb290345d0b6289c002a5b4cb614591e2321f22917b9deae54be351f49ac1ddc280b0701fc8b7285afda0199da004518291d7586
7
- data.tar.gz: 8ea136a55f97172c648d9e69d03fa924dd449f238be33cc45a4d76174f65b3770bb2fd8bbbd952fa2b41cf6481de45cd52c8b1d3b6d8785bb5078f6b94f74def
6
+ metadata.gz: 388dc4bfd5a7a92bb8f027790625ca6286afedf90ef37309dac57f735abc7176ff9c394a23f191a79d08442c31a134eaf00bb8226813dc74b438c7ceb4ff373f
7
+ data.tar.gz: 92b2e3901c5e94ce0597a60ca518fc45f0814bc95ee6d0222839b39e34aad28aad14e96d17ee39270ba7f20304267b10d23b96d9f65a03721543b214920ed1a5
@@ -55,11 +55,6 @@ a {
55
55
  &:hover {
56
56
  color: $hover-link-color;
57
57
  }
58
-
59
- &:active, &:focus {
60
- color: $hover-link-color;
61
- outline: none;
62
- }
63
58
  }
64
59
 
65
60
  hr {
@@ -1,7 +1,8 @@
1
1
  require "administrate/namespace"
2
- require "administrate/pages/form"
3
- require "administrate/pages/table"
4
- require "administrate/pages/show"
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: notices[:created],
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: notices[:updated],
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] = notices[:destroyed]
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(:"#{resource_name}").permit(*permitted_attributes)
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
- def resource_title
112
- resource_class_name.titleize
113
- end
100
+ delegate :resource_class, :resource_name, to: :resource_resolver
114
101
 
115
- def notices
116
- {
117
- created: "#{resource_title} was successfully created.",
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 resource_name
124
- controller_name.singularize.to_sym
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
- <%= render(
2
- "table",
3
- table_presenter: has_many.associated_table,
4
- resources: has_many.data
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."
@@ -1,5 +1,5 @@
1
1
  require_relative "base"
2
- require "administrate/pages/table"
2
+ require "administrate/page/table"
3
3
 
4
4
  module Administrate
5
5
  module Field
@@ -0,0 +1,4 @@
1
+ module Administrate
2
+ module Page
3
+ end
4
+ end
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
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,6 +3,8 @@ require "rails/generators/named_base"
3
3
  module Administrate
4
4
  module Generators
5
5
  class DashboardGenerator < Rails::Generators::NamedBase
6
+ TABLE_ATTRIBUTE_LIMIT = 4
7
+
6
8
  source_root File.expand_path("../templates", __FILE__)
7
9
 
8
10
  def create_dashboard_definition
@@ -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
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-06-26 00:00:00.000000000 Z
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/pages/base.rb
156
- - lib/administrate/pages/form.rb
157
- - lib/administrate/pages/show.rb
158
- - lib/administrate/pages/table.rb
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