administrate 0.0.12 → 0.1.0

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 (84) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/administrate/dropdown.svg +3 -0
  3. data/app/assets/javascripts/administrate/components/_search.js +2 -1
  4. data/app/assets/javascripts/administrate/components/has_many_form.js +1 -1
  5. data/app/assets/stylesheets/administrate/application.scss +0 -1
  6. data/app/assets/stylesheets/administrate/base/_forms.scss +3 -3
  7. data/app/assets/stylesheets/administrate/base/_lists.scss +7 -7
  8. data/app/assets/stylesheets/administrate/base/_variables.scss +3 -0
  9. data/app/assets/stylesheets/administrate/components/_attributes.scss +13 -0
  10. data/app/assets/stylesheets/administrate/components/_cells.scss +2 -8
  11. data/app/assets/stylesheets/administrate/components/_form.scss +32 -25
  12. data/app/assets/stylesheets/administrate/components/_header.scss +1 -1
  13. data/app/assets/stylesheets/administrate/components/_search.scss +1 -1
  14. data/app/assets/stylesheets/administrate/components/_table.scss +4 -0
  15. data/app/assets/stylesheets/administrate/mixins/_data_label.scss +8 -0
  16. data/app/assets/stylesheets/administrate/mixins/_mixins.scss +1 -0
  17. data/app/controllers/administrate/application_controller.rb +35 -38
  18. data/app/views/administrate/application/{_table.html.erb → _collection.html.erb} +26 -6
  19. data/app/views/administrate/application/_flashes.html.erb +13 -0
  20. data/app/views/administrate/application/_form.html.erb +23 -7
  21. data/app/views/administrate/application/_javascript.html.erb +9 -0
  22. data/app/views/administrate/application/_sidebar.html.erb +9 -0
  23. data/app/views/administrate/application/edit.html.erb +22 -3
  24. data/app/views/administrate/application/index.html.erb +31 -6
  25. data/app/views/administrate/application/new.html.erb +22 -3
  26. data/app/views/administrate/application/show.html.erb +24 -4
  27. data/app/views/fields/belongs_to/_form.html.erb +18 -0
  28. data/app/views/fields/belongs_to/_index.html.erb +17 -0
  29. data/app/views/fields/belongs_to/_show.html.erb +17 -0
  30. data/app/views/fields/boolean/_form.html.erb +17 -0
  31. data/app/views/fields/boolean/_index.html.erb +19 -1
  32. data/app/views/fields/boolean/_show.html.erb +19 -1
  33. data/app/views/fields/date_time/_form.html.erb +18 -0
  34. data/app/views/fields/date_time/_index.html.erb +18 -0
  35. data/app/views/fields/date_time/_show.html.erb +18 -0
  36. data/app/views/fields/email/_form.html.erb +17 -0
  37. data/app/views/fields/email/_index.html.erb +17 -0
  38. data/app/views/fields/email/_show.html.erb +17 -0
  39. data/app/views/fields/has_many/_form.html.erb +21 -0
  40. data/app/views/fields/has_many/_index.html.erb +18 -0
  41. data/app/views/fields/has_many/_show.html.erb +33 -3
  42. data/app/views/fields/has_one/_form.html.erb +21 -1
  43. data/app/views/fields/has_one/_index.html.erb +17 -0
  44. data/app/views/fields/has_one/_show.html.erb +17 -0
  45. data/app/views/fields/image/_form.html.erb +17 -0
  46. data/app/views/fields/image/_index.html.erb +17 -0
  47. data/app/views/fields/image/_show.html.erb +17 -0
  48. data/app/views/fields/number/_form.html.erb +17 -0
  49. data/app/views/fields/number/_index.html.erb +19 -1
  50. data/app/views/fields/number/_show.html.erb +19 -1
  51. data/app/views/fields/polymorphic/_form.html.erb +20 -0
  52. data/app/views/fields/polymorphic/_index.html.erb +18 -0
  53. data/app/views/fields/polymorphic/_show.html.erb +18 -0
  54. data/app/views/fields/string/_form.html.erb +17 -0
  55. data/app/views/fields/string/_index.html.erb +17 -0
  56. data/app/views/fields/string/_show.html.erb +17 -0
  57. data/app/views/fields/text/_form.html.erb +2 -0
  58. data/app/views/fields/text/_index.html.erb +1 -0
  59. data/app/views/fields/text/_show.html.erb +1 -0
  60. data/app/views/layouts/administrate/application.html.erb +15 -1
  61. data/config/locales/administrate.en.yml +14 -10
  62. data/lib/administrate/base_dashboard.rb +3 -2
  63. data/lib/administrate/engine.rb +1 -1
  64. data/lib/administrate/fields/has_many.rb +7 -3
  65. data/lib/administrate/fields/text.rb +21 -0
  66. data/lib/administrate/page/{table.rb → collection.rb} +2 -6
  67. data/lib/administrate/version.rb +1 -1
  68. data/lib/administrate/view_generator.rb +27 -0
  69. data/lib/generators/administrate/dashboard/dashboard_generator.rb +7 -1
  70. data/lib/generators/administrate/dashboard/templates/dashboard.rb.erb +16 -10
  71. data/lib/generators/administrate/field/field_generator.rb +31 -0
  72. data/lib/generators/administrate/field/templates/_form.html.erb +2 -0
  73. data/lib/generators/administrate/field/templates/_index.html.erb +1 -0
  74. data/lib/generators/administrate/field/templates/_show.html.erb +1 -0
  75. data/lib/generators/administrate/field/templates/field_object.rb.erb +7 -0
  76. data/lib/generators/administrate/views/edit_generator.rb +16 -0
  77. data/lib/generators/administrate/views/field_generator.rb +36 -0
  78. data/lib/generators/administrate/views/form_generator.rb +15 -0
  79. data/lib/generators/administrate/views/index_generator.rb +16 -0
  80. data/lib/generators/administrate/views/new_generator.rb +16 -0
  81. data/lib/generators/administrate/views/show_generator.rb +15 -0
  82. data/lib/generators/administrate/views/views_generator.rb +14 -0
  83. metadata +33 -15
  84. data/app/assets/stylesheets/administrate/_show.sass +0 -16
@@ -0,0 +1,2 @@
1
+ <%= f.label field.attribute %>
2
+ <%= f.text_area field.attribute %>
@@ -0,0 +1 @@
1
+ <%= field.truncate %>
@@ -0,0 +1 @@
1
+ <%= field.data %>
@@ -1,10 +1,24 @@
1
+ <%#
2
+ # Application Layout
3
+
4
+ This view template is used as the layout
5
+ for every page that Administrate generates.
6
+
7
+ By default, it renders:
8
+ - Sidebar for navigation
9
+ - Content for a search bar
10
+ (if provided by a `content_for` block in a nested page)
11
+ - Flashes
12
+ - Links to stylesheets and Javascripts
13
+ %>
14
+
1
15
  <!DOCTYPE html>
2
16
  <html>
3
17
  <head>
4
18
  <meta charset="utf-8" />
5
19
  <meta name="ROBOTS" content="NOODP" />
6
20
  <meta name="viewport" content="initial-scale=1" />
7
- <title>Administrate</title>
21
+ <title><%= content_for(:title) %> | <%= Rails.application.class.parent_name.titlecase %></title>
8
22
  <%= stylesheet_link_tag "//fonts.googleapis.com/css?family=Lato:300,400,900", media: "all" %>
9
23
  <%= stylesheet_link_tag "administrate/application", media: "all" %>
10
24
  <%= csrf_meta_tags %>
@@ -1,19 +1,23 @@
1
+ ---
1
2
  en:
2
3
  administrate:
3
4
  actions:
4
- show: Show
5
- edit: Edit
6
- destroy: Destroy
7
5
  confirm: Are you sure?
8
- fields:
9
- has_many:
10
- none: None
11
- polymorphic:
12
- not_supported: "Polymorphic relationship forms are not supported yet. Sorry!"
6
+ destroy: Destroy
7
+ edit: Edit
8
+ show: Show
13
9
  controller:
14
10
  create:
15
11
  success: "%{resource} was successfully created."
16
- update:
17
- success: "%{resource} was successfully updated."
18
12
  destroy:
19
13
  success: "%{resource} was successfully destroyed."
14
+ update:
15
+ success: "%{resource} was successfully updated."
16
+ fields:
17
+ has_many:
18
+ more: Showing %{count} of %{total_count}
19
+ none: None
20
+ polymorphic:
21
+ not_supported: Polymorphic relationship forms are not supported yet. Sorry!
22
+ has_one:
23
+ not_supported: HasOne relationship forms are not supported yet. Sorry!
@@ -8,6 +8,7 @@ require "administrate/fields/image"
8
8
  require "administrate/fields/number"
9
9
  require "administrate/fields/polymorphic"
10
10
  require "administrate/fields/string"
11
+ require "administrate/fields/text"
11
12
 
12
13
  module Administrate
13
14
  class BaseDashboard
@@ -31,8 +32,8 @@ module Administrate
31
32
  self.class::SHOW_PAGE_ATTRIBUTES
32
33
  end
33
34
 
34
- def table_attributes
35
- self.class::TABLE_ATTRIBUTES
35
+ def collection_attributes
36
+ self.class::COLLECTION_ATTRIBUTES
36
37
  end
37
38
  end
38
39
  end
@@ -10,7 +10,7 @@ require "selectize-rails"
10
10
  require "administrate/namespace"
11
11
  require "administrate/page/form"
12
12
  require "administrate/page/show"
13
- require "administrate/page/table"
13
+ require "administrate/page/collection"
14
14
  require "administrate/order"
15
15
  require "administrate/resource_resolver"
16
16
  require "administrate/search"
@@ -1,5 +1,5 @@
1
1
  require_relative "base"
2
- require "administrate/page/table"
2
+ require "administrate/page/collection"
3
3
 
4
4
  module Administrate
5
5
  module Field
@@ -10,8 +10,8 @@ module Administrate
10
10
  { "#{attribute.to_s.singularize}_ids".to_sym => [] }
11
11
  end
12
12
 
13
- def associated_table
14
- Administrate::Page::Table.new(associated_dashboard)
13
+ def associated_collection
14
+ Administrate::Page::Collection.new(associated_dashboard)
15
15
  end
16
16
 
17
17
  def attribute_key
@@ -34,6 +34,10 @@ module Administrate
34
34
  data.limit(limit)
35
35
  end
36
36
 
37
+ def more_than_limit?
38
+ data.count > limit
39
+ end
40
+
37
41
  private
38
42
 
39
43
  def associated_dashboard
@@ -0,0 +1,21 @@
1
+ require_relative "base"
2
+
3
+ module Administrate
4
+ module Field
5
+ class Text < Administrate::Field::Base
6
+ def self.searchable?
7
+ false
8
+ end
9
+
10
+ def truncate
11
+ data.to_s[0...truncation_length]
12
+ end
13
+
14
+ private
15
+
16
+ def truncation_length
17
+ options.fetch(:truncate, 50)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,9 +2,9 @@ require_relative "base"
2
2
 
3
3
  module Administrate
4
4
  module Page
5
- class Table < Page::Base
5
+ class Collection < Page::Base
6
6
  def attribute_names
7
- dashboard.table_attributes
7
+ dashboard.collection_attributes
8
8
  end
9
9
 
10
10
  def attributes_for(resource)
@@ -17,10 +17,6 @@ module Administrate
17
17
  dashboard.attribute_types.slice(*attribute_names)
18
18
  end
19
19
 
20
- def to_partial_path
21
- "/dashboard/table"
22
- end
23
-
24
20
  def ordered_html_class(attr)
25
21
  ordered_by?(attr) && order.direction
26
22
  end
@@ -1,3 +1,3 @@
1
1
  module Administrate
2
- VERSION = "0.0.12"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,27 @@
1
+ require "rails/generators/base"
2
+
3
+ module Administrate
4
+ class ViewGenerator < Rails::Generators::Base
5
+ private
6
+
7
+ def self.template_source_path
8
+ File.expand_path(
9
+ "../../../app/views/administrate/application",
10
+ __FILE__,
11
+ )
12
+ end
13
+
14
+ def copy_resource_template(template_name)
15
+ template_file = "#{template_name}.html.erb"
16
+
17
+ copy_file(
18
+ template_file,
19
+ "app/views/admin/#{resource_path}/#{template_file}",
20
+ )
21
+ end
22
+
23
+ def resource_path
24
+ args.first.try(:underscore).try(:pluralize) || "application"
25
+ end
26
+ end
27
+ end
@@ -10,6 +10,7 @@ module Administrate
10
10
  float: "Field::Number",
11
11
  integer: "Field::Number",
12
12
  time: "Field::DateTime",
13
+ text: "Field::Text",
13
14
  }
14
15
 
15
16
  ATTRIBUTE_OPTIONS_MAPPING = {
@@ -17,7 +18,8 @@ module Administrate
17
18
  }
18
19
 
19
20
  DEFAULT_FIELD_TYPE = "Field::String"
20
- TABLE_ATTRIBUTE_LIMIT = 4
21
+ COLLECTION_ATTRIBUTE_LIMIT = 4
22
+ READ_ONLY_ATTRIBUTES = %w[id created_at updated_at]
21
23
 
22
24
  source_root File.expand_path("../templates", __FILE__)
23
25
 
@@ -38,6 +40,10 @@ module Administrate
38
40
  klass.reflections.keys + klass.attribute_names - redundant_attributes
39
41
  end
40
42
 
43
+ def form_attributes
44
+ attributes - READ_ONLY_ATTRIBUTES
45
+ end
46
+
41
47
  def redundant_attributes
42
48
  klass.reflections.keys.flat_map do |relationship|
43
49
  redundant_attributes_for(relationship)
@@ -1,12 +1,6 @@
1
1
  require "administrate/base_dashboard"
2
2
 
3
3
  class <%= class_name %>Dashboard < Administrate::BaseDashboard
4
- READ_ONLY_ATTRIBUTES = [
5
- :id,
6
- :created_at,
7
- :updated_at,
8
- ]
9
-
10
4
  # ATTRIBUTE_TYPES
11
5
  # a hash that describes the type of each of the model's fields.
12
6
  #
@@ -19,12 +13,18 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
19
13
  <% end -%>
20
14
  }
21
15
 
22
- # TABLE_ATTRIBUTES
16
+ # COLLECTION_ATTRIBUTES
23
17
  # an array of attributes that will be displayed on the model's index page.
24
18
  #
25
19
  # By default, it's limited to four items to reduce clutter on index pages.
26
- # Feel free to remove the limit or customize the returned array.
27
- TABLE_ATTRIBUTES = ATTRIBUTE_TYPES.keys.first(<%= TABLE_ATTRIBUTE_LIMIT %>)
20
+ # Feel free to add, remove, or rearrange items.
21
+ COLLECTION_ATTRIBUTES = [
22
+ <%=
23
+ attributes.first(COLLECTION_ATTRIBUTE_LIMIT).map do |attr|
24
+ " :#{attr},"
25
+ end.join("\n")
26
+ %>
27
+ ]
28
28
 
29
29
  # SHOW_PAGE_ATTRIBUTES
30
30
  # an array of attributes that will be displayed on the model's show page.
@@ -33,5 +33,11 @@ class <%= class_name %>Dashboard < Administrate::BaseDashboard
33
33
  # FORM_ATTRIBUTES
34
34
  # an array of attributes that will be displayed
35
35
  # on the model's form (`new` and `edit`) pages.
36
- FORM_ATTRIBUTES = ATTRIBUTE_TYPES.keys - READ_ONLY_ATTRIBUTES
36
+ FORM_ATTRIBUTES = [
37
+ <%=
38
+ form_attributes.map do |attr|
39
+ " :#{attr},"
40
+ end.join("\n")
41
+ %>
42
+ ]
37
43
  end
@@ -0,0 +1,31 @@
1
+ module Administrate
2
+ module Generators
3
+ class FieldGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path("../templates", __FILE__)
5
+
6
+ def template_field_object
7
+ template(
8
+ "field_object.rb.erb",
9
+ "app/fields/#{file_name}_field.rb",
10
+ )
11
+ end
12
+
13
+ def copy_partials
14
+ copy_partial(:show)
15
+ copy_partial(:index)
16
+ copy_partial(:form)
17
+ end
18
+
19
+ private
20
+
21
+ def copy_partial(partial_name)
22
+ partial = "_#{partial_name}.html.erb"
23
+
24
+ copy_file(
25
+ partial,
26
+ "app/views/fields/#{file_name}_field/#{partial}",
27
+ )
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,2 @@
1
+ <%= f.label field.attribute %>
2
+ <%= f.text_field field.attribute %>
@@ -0,0 +1,7 @@
1
+ require "administrate/fields/base"
2
+
3
+ class <%= class_name %>Field < Administrate::Field::Base
4
+ def to_s
5
+ data
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ require "administrate/view_generator"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Views
6
+ class EditGenerator < Administrate::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_edit
10
+ copy_resource_template("edit")
11
+ copy_resource_template("_form")
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,36 @@
1
+ require "administrate/view_generator"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Views
6
+ class FieldGenerator < Administrate::ViewGenerator
7
+ def self.template_source_path
8
+ File.expand_path(
9
+ "../../../../../app/views/fields/",
10
+ __FILE__,
11
+ )
12
+ end
13
+
14
+ source_root template_source_path
15
+
16
+ def copy_partials
17
+ copy_field_partial(:index)
18
+ copy_field_partial(:show)
19
+ copy_field_partial(:form)
20
+ end
21
+
22
+ private
23
+
24
+ def copy_field_partial(partial_name)
25
+ resource_path = args.first.try(:underscore)
26
+ template_file = "#{resource_path}/_#{partial_name}.html.erb"
27
+
28
+ copy_file(
29
+ template_file,
30
+ "app/views/fields/#{template_file}",
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,15 @@
1
+ require "administrate/view_generator"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Views
6
+ class FormGenerator < Administrate::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_form
10
+ copy_resource_template("_form")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require "administrate/view_generator"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Views
6
+ class IndexGenerator < Administrate::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_template
10
+ copy_resource_template("index")
11
+ copy_resource_template("_collection")
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ require "administrate/view_generator"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Views
6
+ class NewGenerator < Administrate::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_new
10
+ copy_resource_template("new")
11
+ copy_resource_template("_form")
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,15 @@
1
+ require "administrate/view_generator"
2
+
3
+ module Administrate
4
+ module Generators
5
+ module Views
6
+ class ShowGenerator < Administrate::ViewGenerator
7
+ source_root template_source_path
8
+
9
+ def copy_template
10
+ copy_resource_template("show")
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end