administrate 0.1.3 → 0.1.4

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.

Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/app/views/administrate/application/_sidebar.html.erb +2 -2
  3. data/lib/administrate/base_dashboard.rb +11 -11
  4. data/lib/administrate/engine.rb +1 -0
  5. data/lib/administrate/{fields → field}/associative.rb +0 -0
  6. data/lib/administrate/{fields → field}/base.rb +0 -0
  7. data/lib/administrate/{fields → field}/belongs_to.rb +0 -0
  8. data/lib/administrate/{fields → field}/boolean.rb +0 -0
  9. data/lib/administrate/{fields → field}/date_time.rb +0 -0
  10. data/lib/administrate/{fields → field}/deferred.rb +0 -0
  11. data/lib/administrate/{fields → field}/email.rb +0 -0
  12. data/lib/administrate/{fields → field}/has_many.rb +0 -0
  13. data/lib/administrate/{fields → field}/has_one.rb +0 -0
  14. data/lib/administrate/{fields → field}/image.rb +0 -0
  15. data/lib/administrate/{fields → field}/number.rb +0 -0
  16. data/lib/administrate/{fields → field}/polymorphic.rb +0 -0
  17. data/lib/administrate/{fields → field}/string.rb +0 -0
  18. data/lib/administrate/{fields → field}/text.rb +0 -0
  19. data/lib/administrate/namespace.rb +29 -0
  20. data/lib/administrate/version.rb +1 -1
  21. data/lib/generators/administrate/field/templates/field_object.rb.erb +1 -1
  22. data/lib/generators/administrate/install/install_generator.rb +9 -27
  23. data/lib/generators/administrate/{manifest/manifest_generator.rb → routes/routes_generator.rb} +19 -6
  24. data/lib/generators/administrate/routes/templates/routes.rb.erb +5 -0
  25. metadata +19 -19
  26. data/lib/generators/administrate/install/templates/routes.rb +0 -7
  27. data/lib/generators/administrate/manifest/templates/dashboard_manifest.rb.erb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be86082070f80aad91eef0098bfd4eeabdc19e72
4
- data.tar.gz: 974b398b126fa3a2a013037ca7fc8edebc2bb698
3
+ metadata.gz: cd6b7e88304b6a4b6255696bd3e09757f8dc9fa1
4
+ data.tar.gz: 46632cb11d7f960f33f89177d41e6be93407c200
5
5
  SHA512:
6
- metadata.gz: b3dad40ff964f01b2e7f1bdcbca7344729d80697b9b9626b8d312909292606cc2ec5464c0dc6bc29d3cf2891493b1f7032f26fac0674aa7ea02f02f4e970b1b4
7
- data.tar.gz: 5f631a841cc0212d8f0f693b257f69462768c5c53baeb4730d378b51d2fc4fdd2c76291624b191f8482f5f13b8c6b70fb3fa064938ffdf663081ad1148d494c0
6
+ metadata.gz: 0fd234605bdad1d95b25a2bd494df96ec9450d15c31500349edc4045daaea79da1acf394627a0930e3b487ffd5d9b9a43e30c27da6df07b674973e026adce839
7
+ data.tar.gz: aca5e1ea7517a2eca432c8edd9394cbf9be95e630c8de24f86eb2c9d63405bca2a8c7f28a4f29033a99dfaad0b385d70c7c16ad2a0416432f63a1b4d6afdb2c0
@@ -4,11 +4,11 @@
4
4
  This partial is used to display the sidebar in Administrate.
5
5
  By default, the sidebar contains navigation links
6
6
  for all resources in the admin dashboard,
7
- as defined by the DashboardManifest.
7
+ as defined by the routes in the `admin/` namespace
8
8
  %>
9
9
 
10
10
  <ul class="sidebar__list">
11
- <% DashboardManifest::DASHBOARDS.each do |resource| %>
11
+ <% Administrate::Namespace.new(namespace).resources.each do |resource| %>
12
12
  <li>
13
13
  <%= link_to(
14
14
  display_resource_name(resource),
@@ -1,14 +1,14 @@
1
- require "administrate/fields/belongs_to"
2
- require "administrate/fields/boolean"
3
- require "administrate/fields/date_time"
4
- require "administrate/fields/email"
5
- require "administrate/fields/has_many"
6
- require "administrate/fields/has_one"
7
- require "administrate/fields/image"
8
- require "administrate/fields/number"
9
- require "administrate/fields/polymorphic"
10
- require "administrate/fields/string"
11
- require "administrate/fields/text"
1
+ require "administrate/field/belongs_to"
2
+ require "administrate/field/boolean"
3
+ require "administrate/field/date_time"
4
+ require "administrate/field/email"
5
+ require "administrate/field/has_many"
6
+ require "administrate/field/has_one"
7
+ require "administrate/field/image"
8
+ require "administrate/field/number"
9
+ require "administrate/field/polymorphic"
10
+ require "administrate/field/string"
11
+ require "administrate/field/text"
12
12
 
13
13
  module Administrate
14
14
  class BaseDashboard
@@ -14,6 +14,7 @@ require "administrate/page/collection"
14
14
  require "administrate/order"
15
15
  require "administrate/resource_resolver"
16
16
  require "administrate/search"
17
+ require "administrate/namespace"
17
18
 
18
19
  module Administrate
19
20
  class Engine < ::Rails::Engine
@@ -0,0 +1,29 @@
1
+ module Administrate
2
+ class Namespace
3
+ def initialize(namespace)
4
+ @namespace = namespace
5
+ end
6
+
7
+ def resources
8
+ namespace_controller_paths.uniq.map do |controller|
9
+ controller.gsub(/^#{namespace}\//, "").to_sym
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :namespace
16
+
17
+ def namespace_controller_paths
18
+ all_controller_paths.select do |controller|
19
+ controller.starts_with?(namespace.to_s)
20
+ end
21
+ end
22
+
23
+ def all_controller_paths
24
+ Rails.application.routes.routes.map do |route|
25
+ route.defaults[:controller].to_s
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4".freeze
3
3
  end
@@ -1,4 +1,4 @@
1
- require "administrate/fields/base"
1
+ require "administrate/field/base"
2
2
 
3
3
  class <%= class_name %>Field < Administrate::Field::Base
4
4
  def to_s
@@ -1,5 +1,6 @@
1
1
  require "rails/generators/base"
2
2
  require "administrate/generator_helpers"
3
+ require "administrate/namespace"
3
4
 
4
5
  module Administrate
5
6
  module Generators
@@ -7,6 +8,13 @@ module Administrate
7
8
  include Administrate::GeneratorHelpers
8
9
  source_root File.expand_path("../templates", __FILE__)
9
10
 
11
+ def run_routes_generator
12
+ if dashboard_resources.none?
13
+ call_generator("administrate:routes")
14
+ load Rails.root.join("config/routes.rb")
15
+ end
16
+ end
17
+
10
18
  def create_dashboard_controller
11
19
  copy_file(
12
20
  "application_controller.rb",
@@ -14,12 +22,6 @@ module Administrate
14
22
  )
15
23
  end
16
24
 
17
- def insert_dashboard_routes
18
- unless File.read(rails_routes_file_path).include?(dashboard_routes)
19
- route(dashboard_routes)
20
- end
21
- end
22
-
23
25
  def run_dashboard_generators
24
26
  singular_dashboard_resources.each do |resource|
25
27
  call_generator("administrate:dashboard", resource)
@@ -33,27 +35,7 @@ module Administrate
33
35
  end
34
36
 
35
37
  def dashboard_resources
36
- manifest::DASHBOARDS
37
- end
38
-
39
- def manifest
40
- unless defined?(DashboardManifest)
41
- call_generator("administrate:manifest")
42
- end
43
-
44
- DashboardManifest
45
- end
46
-
47
- def dashboard_routes
48
- File.read(routes_file_path)
49
- end
50
-
51
- def rails_routes_file_path
52
- Rails.root.join("config/routes.rb")
53
- end
54
-
55
- def routes_file_path
56
- File.expand_path(find_in_source_paths("routes.rb"))
38
+ Administrate::Namespace.new(:admin).resources
57
39
  end
58
40
  end
59
41
  end
@@ -1,16 +1,16 @@
1
1
  Rails.application.eager_load!
2
2
  require "rails/generators/base"
3
+ require "administrate/namespace"
3
4
 
4
5
  module Administrate
5
6
  module Generators
6
- class ManifestGenerator < Rails::Generators::Base
7
+ class RoutesGenerator < Rails::Generators::Base
7
8
  source_root File.expand_path("../templates", __FILE__)
8
9
 
9
- def create_dashboard_manifest
10
- template(
11
- "dashboard_manifest.rb.erb",
12
- Rails.root.join("app/dashboards/dashboard_manifest.rb"),
13
- )
10
+ def insert_dashboard_routes
11
+ unless File.read(rails_routes_file_path).include?(dashboard_routes)
12
+ route(dashboard_routes)
13
+ end
14
14
  end
15
15
 
16
16
  def warn_about_invalid_models
@@ -22,6 +22,7 @@ module Administrate
22
22
  models_without_tables.each do |invalid_model|
23
23
  puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
24
24
  puts " It is not connected to a database table."
25
+ puts " Make sure your database migrations are up to date."
25
26
  end
26
27
 
27
28
  unnamed_constants.each do |invalid_model|
@@ -60,6 +61,18 @@ module Administrate
60
61
  def unnamed_constants
61
62
  ActiveRecord::Base.descendants.reject { |d| d.name == d.to_s }
62
63
  end
64
+
65
+ def dashboard_routes
66
+ ERB.new(File.read(routes_file_path)).result(binding)
67
+ end
68
+
69
+ def rails_routes_file_path
70
+ Rails.root.join("config/routes.rb")
71
+ end
72
+
73
+ def routes_file_path
74
+ File.expand_path(find_in_source_paths("routes.rb.erb"))
75
+ end
63
76
  end
64
77
  end
65
78
  end
@@ -0,0 +1,5 @@
1
+ namespace :admin do
2
+ <% dashboard_resources.each do |resource| %>resources :<%= resource %>
3
+ <% end %>
4
+ root to: "<%= dashboard_resources.first %>#index"
5
+ 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.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grayson Wright
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-22 00:00:00.000000000 Z
11
+ date: 2016-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: autoprefixer-rails
@@ -268,21 +268,22 @@ files:
268
268
  - lib/administrate.rb
269
269
  - lib/administrate/base_dashboard.rb
270
270
  - lib/administrate/engine.rb
271
- - lib/administrate/fields/associative.rb
272
- - lib/administrate/fields/base.rb
273
- - lib/administrate/fields/belongs_to.rb
274
- - lib/administrate/fields/boolean.rb
275
- - lib/administrate/fields/date_time.rb
276
- - lib/administrate/fields/deferred.rb
277
- - lib/administrate/fields/email.rb
278
- - lib/administrate/fields/has_many.rb
279
- - lib/administrate/fields/has_one.rb
280
- - lib/administrate/fields/image.rb
281
- - lib/administrate/fields/number.rb
282
- - lib/administrate/fields/polymorphic.rb
283
- - lib/administrate/fields/string.rb
284
- - lib/administrate/fields/text.rb
271
+ - lib/administrate/field/associative.rb
272
+ - lib/administrate/field/base.rb
273
+ - lib/administrate/field/belongs_to.rb
274
+ - lib/administrate/field/boolean.rb
275
+ - lib/administrate/field/date_time.rb
276
+ - lib/administrate/field/deferred.rb
277
+ - lib/administrate/field/email.rb
278
+ - lib/administrate/field/has_many.rb
279
+ - lib/administrate/field/has_one.rb
280
+ - lib/administrate/field/image.rb
281
+ - lib/administrate/field/number.rb
282
+ - lib/administrate/field/polymorphic.rb
283
+ - lib/administrate/field/string.rb
284
+ - lib/administrate/field/text.rb
285
285
  - lib/administrate/generator_helpers.rb
286
+ - lib/administrate/namespace.rb
286
287
  - lib/administrate/order.rb
287
288
  - lib/administrate/page.rb
288
289
  - lib/administrate/page/base.rb
@@ -308,9 +309,8 @@ files:
308
309
  - lib/generators/administrate/field/templates/field_object.rb.erb
309
310
  - lib/generators/administrate/install/install_generator.rb
310
311
  - lib/generators/administrate/install/templates/application_controller.rb
311
- - lib/generators/administrate/install/templates/routes.rb
312
- - lib/generators/administrate/manifest/manifest_generator.rb
313
- - lib/generators/administrate/manifest/templates/dashboard_manifest.rb.erb
312
+ - lib/generators/administrate/routes/routes_generator.rb
313
+ - lib/generators/administrate/routes/templates/routes.rb.erb
314
314
  - lib/generators/administrate/views/edit_generator.rb
315
315
  - lib/generators/administrate/views/field_generator.rb
316
316
  - lib/generators/administrate/views/form_generator.rb
@@ -1,7 +0,0 @@
1
- namespace :admin do
2
- DashboardManifest::DASHBOARDS.each do |dashboard_resource|
3
- resources dashboard_resource
4
- end
5
-
6
- root controller: DashboardManifest::ROOT_DASHBOARD, action: :index
7
- end
@@ -1,25 +0,0 @@
1
- # DashboardManifest tells Administrate which dashboards to display
2
- class DashboardManifest
3
- # `DASHBOARDS`
4
- # a list of dashboards to display in the side navigation menu
5
- #
6
- # These are all of the rails models that we found in your database
7
- # at the time you installed Administrate.
8
- #
9
- # To show or hide dashboards, add or remove the model name from this list.
10
- # Dashboards returned from this method must be Rails models for Administrate
11
- # to work correctly.
12
- DASHBOARDS = [
13
- <% dashboard_resources.each do |model| -%>
14
- :<%= model %>,
15
- <% end -%>
16
- ]
17
-
18
- # `ROOT_DASHBOARD`
19
- # the name of the dashboard that will be displayed
20
- # at "http://your_site.com/admin"
21
- #
22
- # This dashboard will likely be the first page that admins see
23
- # when they log into the dashboard.
24
- ROOT_DASHBOARD = DASHBOARDS.first
25
- end