administrate 0.1.2 → 0.1.3

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/administrate/search.svg +2 -2
  3. data/app/assets/images/administrate/sort_arrow.svg +1 -1
  4. data/app/assets/javascripts/administrate/components/has_many_form.js +1 -1
  5. data/app/assets/stylesheets/administrate/application.scss +3 -8
  6. data/app/assets/stylesheets/administrate/base/_forms.scss +56 -44
  7. data/app/assets/stylesheets/administrate/base/_layout.scss +20 -0
  8. data/app/assets/stylesheets/administrate/base/_lists.scss +9 -21
  9. data/app/assets/stylesheets/administrate/base/_tables.scss +9 -6
  10. data/app/assets/stylesheets/administrate/base/_typography.scss +12 -57
  11. data/app/assets/stylesheets/administrate/components/_app-container.scss +7 -0
  12. data/app/assets/stylesheets/administrate/components/_attributes.scss +1 -1
  13. data/app/assets/stylesheets/administrate/components/_buttons.scss +36 -0
  14. data/app/assets/stylesheets/administrate/components/_cells.scss +31 -37
  15. data/app/assets/stylesheets/administrate/components/_field-unit.scss +17 -0
  16. data/app/assets/stylesheets/administrate/components/_flashes.scss +16 -0
  17. data/app/assets/stylesheets/administrate/components/_form-actions.scss +3 -0
  18. data/app/assets/stylesheets/administrate/components/_header.scss +9 -8
  19. data/app/assets/stylesheets/administrate/components/_main-content.scss +6 -0
  20. data/app/assets/stylesheets/administrate/components/_pagination.scss +3 -2
  21. data/app/assets/stylesheets/administrate/components/_search.scss +9 -10
  22. data/app/assets/stylesheets/administrate/components/_sidebar.scss +22 -0
  23. data/app/assets/stylesheets/administrate/components/_table.scss +7 -3
  24. data/app/assets/stylesheets/administrate/{mixins → library}/_data_label.scss +2 -2
  25. data/app/assets/stylesheets/administrate/library/_variables.scss +57 -0
  26. data/app/assets/stylesheets/docs.scss +92 -0
  27. data/app/controllers/administrate/application_controller.rb +4 -3
  28. data/app/controllers/docs_controller.rb +9 -0
  29. data/app/helpers/administrate/application_helper.rb +16 -0
  30. data/app/views/administrate/application/_collection.html.erb +17 -12
  31. data/app/views/administrate/application/_flashes.html.erb +1 -1
  32. data/app/views/administrate/application/_form.html.erb +6 -8
  33. data/app/views/administrate/application/_sidebar.html.erb +1 -1
  34. data/app/views/administrate/application/edit.html.erb +3 -3
  35. data/app/views/administrate/application/index.html.erb +7 -6
  36. data/app/views/administrate/application/new.html.erb +2 -2
  37. data/app/views/administrate/application/show.html.erb +3 -3
  38. data/app/views/fields/belongs_to/_form.html.erb +8 -4
  39. data/app/views/fields/belongs_to/_index.html.erb +1 -1
  40. data/app/views/fields/belongs_to/_show.html.erb +1 -1
  41. data/app/views/fields/boolean/_form.html.erb +6 -2
  42. data/app/views/fields/date_time/_form.html.erb +6 -2
  43. data/app/views/fields/email/_form.html.erb +6 -2
  44. data/app/views/fields/has_many/_form.html.erb +8 -5
  45. data/app/views/fields/has_one/_form.html.erb +3 -1
  46. data/app/views/fields/has_one/_index.html.erb +1 -1
  47. data/app/views/fields/has_one/_show.html.erb +1 -1
  48. data/app/views/fields/image/_form.html.erb +6 -2
  49. data/app/views/fields/number/_form.html.erb +6 -2
  50. data/app/views/fields/polymorphic/_form.html.erb +3 -1
  51. data/app/views/fields/polymorphic/_index.html.erb +1 -1
  52. data/app/views/fields/polymorphic/_show.html.erb +1 -1
  53. data/app/views/fields/string/_form.html.erb +6 -2
  54. data/app/views/fields/text/_form.html.erb +6 -2
  55. data/app/views/layouts/administrate/application.html.erb +11 -11
  56. data/app/views/layouts/docs.html.erb +39 -0
  57. data/config/locales/administrate.de.yml +2 -2
  58. data/config/locales/administrate.it.yml +23 -0
  59. data/config/locales/administrate.uk.yml +23 -0
  60. data/lib/administrate/engine.rb +2 -2
  61. data/lib/administrate/fields/deferred.rb +3 -1
  62. data/lib/administrate/generator_helpers.rb +13 -0
  63. data/lib/administrate/resource_resolver.rb +5 -3
  64. data/lib/administrate/search.rb +3 -0
  65. data/lib/administrate/version.rb +1 -1
  66. data/lib/administrate/view_generator.rb +3 -0
  67. data/lib/generators/administrate/assets/assets_generator.rb +13 -0
  68. data/lib/generators/administrate/assets/images_generator.rb +17 -0
  69. data/lib/generators/administrate/assets/javascripts_generator.rb +17 -0
  70. data/lib/generators/administrate/assets/stylesheets_generator.rb +17 -0
  71. data/lib/generators/administrate/dashboard/USAGE +1 -1
  72. data/lib/generators/administrate/dashboard/dashboard_generator.rb +23 -4
  73. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +7 -1
  74. data/lib/generators/administrate/install/install_generator.rb +17 -51
  75. data/lib/generators/administrate/manifest/manifest_generator.rb +65 -0
  76. data/lib/generators/administrate/{install → manifest}/templates/dashboard_manifest.rb.erb +0 -0
  77. data/lib/generators/administrate/views/layout_generator.rb +22 -0
  78. data/lib/generators/administrate/views/sidebar_generator.rb +15 -0
  79. data/lib/generators/administrate/views/views_generator.rb +4 -4
  80. metadata +28 -37
  81. data/app/assets/stylesheets/administrate/_sidebar.scss +0 -27
  82. data/app/assets/stylesheets/administrate/base/_base.scss +0 -24
  83. data/app/assets/stylesheets/administrate/base/_buttons.scss +0 -11
  84. data/app/assets/stylesheets/administrate/base/_grid-settings.scss +0 -15
  85. data/app/assets/stylesheets/administrate/base/_variables.scss +0 -106
  86. data/app/assets/stylesheets/administrate/base/extends/_button.scss +0 -23
  87. data/app/assets/stylesheets/administrate/base/extends/_clearfix.scss +0 -3
  88. data/app/assets/stylesheets/administrate/base/extends/_errors.scss +0 -11
  89. data/app/assets/stylesheets/administrate/base/extends/_flashes.scss +0 -34
  90. data/app/assets/stylesheets/administrate/base/extends/_hide-text.scss +0 -3
  91. data/app/assets/stylesheets/administrate/components/_components.scss +0 -8
  92. data/app/assets/stylesheets/administrate/components/_date_time_picker.scss +0 -3
  93. data/app/assets/stylesheets/administrate/components/_form.scss +0 -41
  94. data/app/assets/stylesheets/administrate/layout.scss +0 -29
  95. data/app/assets/stylesheets/administrate/mixins/_mixins.scss +0 -2
  96. data/app/assets/stylesheets/administrate/mixins/_shadow.scss +0 -35
  97. data/lib/administrate/namespace.rb +0 -3
@@ -0,0 +1,23 @@
1
+ ---
2
+ uk:
3
+ administrate:
4
+ actions:
5
+ confirm: Ви впевнені?
6
+ destroy: Видалити
7
+ edit: Редагувати
8
+ show: Показати
9
+ controller:
10
+ create:
11
+ success: "%{resource} було успішно створено."
12
+ destroy:
13
+ success: "%{resource} було успішно видалено."
14
+ update:
15
+ success: "%{resource} було успішно оновлено."
16
+ fields:
17
+ has_many:
18
+ more: "%{count} із %{total_count}"
19
+ none: Немає
20
+ polymorphic:
21
+ not_supported: Поліморфні відношення у формах не підтримуються.
22
+ has_one:
23
+ not_supported: HasOne відношення у формах не підтримуються.
@@ -1,5 +1,4 @@
1
1
  require "datetime_picker_rails"
2
- require "inline_svg"
3
2
  require "jquery-rails"
4
3
  require "kaminari"
5
4
  require "momentjs-rails"
@@ -9,7 +8,6 @@ require "sass-rails"
9
8
  require "selectize-rails"
10
9
  require "sprockets/railtie"
11
10
 
12
- require "administrate/namespace"
13
11
  require "administrate/page/form"
14
12
  require "administrate/page/show"
15
13
  require "administrate/page/collection"
@@ -20,5 +18,7 @@ require "administrate/search"
20
18
  module Administrate
21
19
  class Engine < ::Rails::Engine
22
20
  isolate_namespace Administrate
21
+
22
+ Engine.config.assets.precompile << /\.(?:svg)\z/
23
23
  end
24
24
  end
@@ -15,7 +15,9 @@ module Administrate
15
15
  end
16
16
 
17
17
  def ==(other)
18
- deferred_class == other.deferred_class && options == other.options
18
+ other.respond_to?(:deferred_class) &&
19
+ deferred_class == other.deferred_class &&
20
+ options == other.options
19
21
  end
20
22
 
21
23
  def searchable?
@@ -0,0 +1,13 @@
1
+ module Administrate
2
+ module GeneratorHelpers
3
+ def call_generator(generator, *args)
4
+ Rails::Generators.invoke(generator, args, generator_options)
5
+ end
6
+
7
+ private
8
+
9
+ def generator_options
10
+ { behavior: behavior }
11
+ end
12
+ end
13
+ end
@@ -1,5 +1,3 @@
1
- require "administrate/namespace"
2
-
3
1
  module Administrate
4
2
  class ResourceResolver
5
3
  def initialize(controller_path)
@@ -10,6 +8,10 @@ module Administrate
10
8
  Object.const_get(resource_class_name + "Dashboard")
11
9
  end
12
10
 
11
+ def namespace
12
+ controller_path.split("/").first
13
+ end
14
+
13
15
  def resource_class
14
16
  Object.const_get(resource_class_name)
15
17
  end
@@ -33,7 +35,7 @@ module Administrate
33
35
  end
34
36
 
35
37
  def controller_path_parts
36
- controller_path.singularize.split("/") - [Administrate::NAMESPACE.to_s]
38
+ controller_path.singularize.split("/")[1..-1]
37
39
  end
38
40
 
39
41
  attr_reader :controller_path
@@ -1,3 +1,6 @@
1
+ require "active_support/core_ext/module/delegation"
2
+ require "active_support/core_ext/object/blank"
3
+
1
4
  module Administrate
2
5
  class Search
3
6
  def initialize(resolver, term)
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -1,7 +1,10 @@
1
1
  require "rails/generators/base"
2
+ require "administrate/generator_helpers"
2
3
 
3
4
  module Administrate
4
5
  class ViewGenerator < Rails::Generators::Base
6
+ include Administrate::GeneratorHelpers
7
+
5
8
  private
6
9
 
7
10
  def self.template_source_path
@@ -0,0 +1,13 @@
1
+ require "administrate/view_generator"
2
+
3
+ module Administrate
4
+ module Generators
5
+ class AssetsGenerator < Administrate::ViewGenerator
6
+ def copy_assets
7
+ call_generator("administrate:assets:images")
8
+ call_generator("administrate:assets:javascripts")
9
+ call_generator("administrate:assets:stylesheets")
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ require "rails/generators/base"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Assets
6
+ class ImagesGenerator < Rails::Generators::Base
7
+ IMAGES_PATH = "app/assets/images/administrate"
8
+
9
+ source_root File.expand_path("../../../../../", __FILE__)
10
+
11
+ def copy_images
12
+ directory IMAGES_PATH, IMAGES_PATH
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require "rails/generators/base"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Assets
6
+ class JavascriptsGenerator < Rails::Generators::Base
7
+ JAVASCRIPTS_PATH = "app/assets/javascripts/administrate"
8
+
9
+ source_root File.expand_path("../../../../../", __FILE__)
10
+
11
+ def copy_javascripts
12
+ directory JAVASCRIPTS_PATH, JAVASCRIPTS_PATH
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ require "rails/generators/base"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Assets
6
+ class StylesheetsGenerator < Rails::Generators::Base
7
+ STYLESHEETS_PATH = "app/assets/stylesheets/administrate"
8
+
9
+ source_root File.expand_path("../../../../../", __FILE__)
10
+
11
+ def copy_stylesheets
12
+ directory STYLESHEETS_PATH, STYLESHEETS_PATH
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,7 +3,7 @@ Description:
3
3
  pulling the attributes from database columns.
4
4
 
5
5
  Example:
6
- rails generate dashboard FooBar
6
+ rails generate administrate:dashboard FooBar
7
7
 
8
8
  This will create:
9
9
  app/dashboards/foo_bar_dashboard.rb
@@ -7,6 +7,7 @@ module Administrate
7
7
  boolean: "Field::Boolean",
8
8
  date: "Field::DateTime",
9
9
  datetime: "Field::DateTime",
10
+ enum: "Field::String",
10
11
  float: "Field::Number",
11
12
  integer: "Field::Number",
12
13
  time: "Field::DateTime",
@@ -15,6 +16,7 @@ module Administrate
15
16
  }
16
17
 
17
18
  ATTRIBUTE_OPTIONS_MAPPING = {
19
+ enum: { searchable: false },
18
20
  float: { decimals: 2 },
19
21
  }
20
22
 
@@ -25,14 +27,18 @@ module Administrate
25
27
  source_root File.expand_path("../templates", __FILE__)
26
28
 
27
29
  def create_dashboard_definition
28
- template "dashboard.rb.erb", "app/dashboards/#{file_name}_dashboard.rb"
30
+ template(
31
+ "dashboard.rb.erb",
32
+ Rails.root.join("app/dashboards/#{file_name}_dashboard.rb"),
33
+ )
29
34
  end
30
35
 
31
36
  def create_resource_controller
32
- template(
33
- "controller.rb.erb",
37
+ destination = Rails.root.join(
34
38
  "app/controllers/admin/#{file_name.pluralize}_controller.rb",
35
39
  )
40
+
41
+ template("controller.rb.erb", destination)
36
42
  end
37
43
 
38
44
  private
@@ -61,7 +67,7 @@ module Administrate
61
67
  end
62
68
 
63
69
  def field_type(attribute)
64
- type = klass.column_types[attribute.to_s].type
70
+ type = column_type_for_attribute(attribute.to_s)
65
71
 
66
72
  if type
67
73
  ATTRIBUTE_TYPE_MAPPING.fetch(type, DEFAULT_FIELD_TYPE) +
@@ -71,6 +77,19 @@ module Administrate
71
77
  end
72
78
  end
73
79
 
80
+ def column_type_for_attribute(attr)
81
+ if enum_column?(attr)
82
+ :enum
83
+ else
84
+ klass.column_types[attr].type
85
+ end
86
+ end
87
+
88
+ def enum_column?(attr)
89
+ klass.respond_to?(:defined_enums) &&
90
+ klass.defined_enums.keys.include?(attr)
91
+ end
92
+
74
93
  def association_type(attribute)
75
94
  relationship = klass.reflections[attribute.to_s]
76
95
  if relationship.has_one?
@@ -28,7 +28,13 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
28
28
 
29
29
  # SHOW_PAGE_ATTRIBUTES
30
30
  # an array of attributes that will be displayed on the model's show page.
31
- SHOW_PAGE_ATTRIBUTES = ATTRIBUTE_TYPES.keys
31
+ SHOW_PAGE_ATTRIBUTES = [
32
+ <%=
33
+ attributes.map do |attr|
34
+ " :#{attr},"
35
+ end.join("\n")
36
+ %>
37
+ ]
32
38
 
33
39
  # FORM_ATTRIBUTES
34
40
  # an array of attributes that will be displayed
@@ -1,9 +1,10 @@
1
- Rails.application.eager_load!
2
1
  require "rails/generators/base"
2
+ require "administrate/generator_helpers"
3
3
 
4
4
  module Administrate
5
5
  module Generators
6
6
  class InstallGenerator < Rails::Generators::Base
7
+ include Administrate::GeneratorHelpers
7
8
  source_root File.expand_path("../templates", __FILE__)
8
9
 
9
10
  def create_dashboard_controller
@@ -13,79 +14,44 @@ module Administrate
13
14
  )
14
15
  end
15
16
 
16
- def create_dashboard_manifest
17
- template(
18
- "dashboard_manifest.rb.erb",
19
- "app/dashboards/dashboard_manifest.rb"
20
- )
21
- end
22
-
23
17
  def insert_dashboard_routes
24
- route(dashboard_routes)
18
+ unless File.read(rails_routes_file_path).include?(dashboard_routes)
19
+ route(dashboard_routes)
20
+ end
25
21
  end
26
22
 
27
23
  def run_dashboard_generators
28
24
  singular_dashboard_resources.each do |resource|
29
- Rails::Generators.invoke("administrate:dashboard", [resource])
30
- end
31
- end
32
-
33
- def warn_about_invalid_models
34
- namespaced_models.each do |invalid_model|
35
- puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
36
- puts " Administrate does not yet support namespaced models."
37
- end
38
-
39
- models_without_tables.each do |invalid_model|
40
- puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
41
- puts " It is not connected to a database table."
42
- end
43
-
44
- unnamed_constants.each do |invalid_model|
45
- puts "NOTICE: Skipping dynamically generated model #{invalid_model}."
25
+ call_generator("administrate:dashboard", resource)
46
26
  end
47
27
  end
48
28
 
49
29
  private
50
30
 
51
31
  def singular_dashboard_resources
52
- dashboard_resources.map(&:singularize)
32
+ dashboard_resources.map(&:to_s).map(&:singularize)
53
33
  end
54
34
 
55
35
  def dashboard_resources
56
- valid_dashboard_models.map do |model|
57
- model.to_s.pluralize.underscore
58
- end
36
+ manifest::DASHBOARDS
59
37
  end
60
38
 
61
- def valid_dashboard_models
62
- database_models - invalid_database_models
63
- end
64
-
65
- def database_models
66
- ActiveRecord::Base.descendants
67
- end
68
-
69
- def invalid_database_models
70
- models_without_tables + namespaced_models + unnamed_constants
71
- end
72
-
73
- def models_without_tables
74
- database_models.reject(&:table_exists?)
75
- end
76
-
77
- def namespaced_models
78
- database_models.select { |model| model.to_s.include?("::") }
79
- end
39
+ def manifest
40
+ unless defined?(DashboardManifest)
41
+ call_generator("administrate:manifest")
42
+ end
80
43
 
81
- def unnamed_constants
82
- ActiveRecord::Base.descendants.reject { |d| d.name == d.to_s }
44
+ DashboardManifest
83
45
  end
84
46
 
85
47
  def dashboard_routes
86
48
  File.read(routes_file_path)
87
49
  end
88
50
 
51
+ def rails_routes_file_path
52
+ Rails.root.join("config/routes.rb")
53
+ end
54
+
89
55
  def routes_file_path
90
56
  File.expand_path(find_in_source_paths("routes.rb"))
91
57
  end
@@ -0,0 +1,65 @@
1
+ Rails.application.eager_load!
2
+ require "rails/generators/base"
3
+
4
+ module Administrate
5
+ module Generators
6
+ class ManifestGenerator < Rails::Generators::Base
7
+ source_root File.expand_path("../templates", __FILE__)
8
+
9
+ def create_dashboard_manifest
10
+ template(
11
+ "dashboard_manifest.rb.erb",
12
+ Rails.root.join("app/dashboards/dashboard_manifest.rb"),
13
+ )
14
+ end
15
+
16
+ def warn_about_invalid_models
17
+ namespaced_models.each do |invalid_model|
18
+ puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
19
+ puts " Administrate does not yet support namespaced models."
20
+ end
21
+
22
+ models_without_tables.each do |invalid_model|
23
+ puts "WARNING: Unable to generate a dashboard for #{invalid_model}."
24
+ puts " It is not connected to a database table."
25
+ end
26
+
27
+ unnamed_constants.each do |invalid_model|
28
+ puts "NOTICE: Skipping dynamically generated model #{invalid_model}."
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def dashboard_resources
35
+ valid_dashboard_models.map do |model|
36
+ model.to_s.pluralize.underscore
37
+ end
38
+ end
39
+
40
+ def valid_dashboard_models
41
+ database_models - invalid_database_models
42
+ end
43
+
44
+ def database_models
45
+ ActiveRecord::Base.descendants
46
+ end
47
+
48
+ def invalid_database_models
49
+ models_without_tables + namespaced_models + unnamed_constants
50
+ end
51
+
52
+ def models_without_tables
53
+ database_models.reject(&:table_exists?)
54
+ end
55
+
56
+ def namespaced_models
57
+ database_models.select { |model| model.to_s.include?("::") }
58
+ end
59
+
60
+ def unnamed_constants
61
+ ActiveRecord::Base.descendants.reject { |d| d.name == d.to_s }
62
+ end
63
+ end
64
+ end
65
+ end