super 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +0 -8
  3. data/README.md +4 -8
  4. data/app/controllers/super/application_controller.rb +5 -5
  5. data/app/views/layouts/super/application.html.erb +1 -3
  6. data/app/views/super/application/{_super_schema_display_actions.html.erb → _display_actions.html.erb} +0 -0
  7. data/app/views/super/application/{_super_schema_display_index.html.erb → _display_index.html.erb} +3 -3
  8. data/app/views/super/application/_display_show.html.erb +8 -0
  9. data/app/views/super/application/{_super_schema_form.html.erb → _form.html.erb} +2 -2
  10. data/app/views/super/application/{_super_layout.html.erb → _layout.html.erb} +7 -7
  11. data/app/views/super/application/{_super_pagination.html.erb → _pagination.html.erb} +1 -1
  12. data/app/views/super/application/{_super_panel.html.erb → _panel.html.erb} +2 -2
  13. data/lib/generators/super/install/install_generator.rb +16 -7
  14. data/lib/generators/super/install/templates/base_controller.rb.tt +9 -1
  15. data/lib/generators/super/install/templates/initializer.rb.tt +9 -2
  16. data/lib/generators/super/resource/resource_generator.rb +105 -30
  17. data/lib/generators/super/resource/templates/resources_controller.rb.tt +3 -9
  18. data/lib/super.rb +2 -0
  19. data/lib/super/configuration.rb +14 -23
  20. data/lib/super/controls.rb +7 -2
  21. data/lib/super/controls/optional.rb +1 -0
  22. data/lib/super/display.rb +16 -8
  23. data/lib/super/display/schema_types.rb +70 -33
  24. data/lib/super/error.rb +7 -0
  25. data/lib/super/form.rb +1 -1
  26. data/lib/super/layout.rb +1 -1
  27. data/lib/super/link.rb +5 -0
  28. data/lib/super/navigation/automatic.rb +2 -2
  29. data/lib/super/pagination.rb +1 -1
  30. data/lib/super/panel.rb +1 -1
  31. data/lib/super/useful/builder.rb +25 -0
  32. data/lib/super/useful/enum.rb +63 -0
  33. data/lib/super/version.rb +1 -1
  34. metadata +17 -19
  35. data/STABILITY.md +0 -50
  36. data/app/views/super/application/_super_schema_display_show.html.erb +0 -8
  37. data/docs/README.md +0 -8
  38. data/docs/action_text.md +0 -48
  39. data/docs/faq.md +0 -44
  40. data/docs/installation.md +0 -21
  41. data/docs/quick_start.md +0 -30
  42. data/docs/webpacker.md +0 -25
  43. data/docs/yard_customizations.rb +0 -43
  44. data/lib/super/controls/required.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 05520525a7f38fff438eee43a134b9b2e52ac3551098c177323cdb87fd193670
4
- data.tar.gz: 0db34e8d60114592b824ec79a2318a11743fe676291859ccec0d81615ce77bfb
3
+ metadata.gz: 645a472c963d0e09e2d4b8646fc54c82b780b4cd60b47daac01b7434d9f37111
4
+ data.tar.gz: 7fa33b28be8edffa88ca94c919ae79f96287e071e84ab2f84dbb51a66a72d0e4
5
5
  SHA512:
6
- metadata.gz: 489419d94f150b08399cfab907773f7cbafc08d7bbf6d2db3af0b8966b81b5cfc1d547fe1a8bb066f72fdac41b04d4b6295715468356de9442d66ae546ff890a
7
- data.tar.gz: 806ca79ae33691eca540cd1350210ef4cf75fc427be26731068f307687e50643fe02999c473a39d90fe58f267e2f3aa5bd5e35d580c273b625f787c7176941b3
6
+ metadata.gz: a91b5535467f835d8cd87c5a02f2e09f086455bedaa02d529dc896c025eefc67ef9162954ab9159c79915bbcfdfb70729443d524137efe6173a7a07cbb20b598
7
+ data.tar.gz: f6f3d9ff8e7ce16cd1470b9b8ad1f7f982cbf2e13428e0fb6e47380fa17c1438e4e63832a7a9db8db1e9d32a8639c5847c2621572a9f0845fa18725116336777
data/.yardopts CHANGED
@@ -1,13 +1,5 @@
1
1
  --exclude lib/generators
2
2
  --markup markdown
3
- --load ./docs/yard_customizations.rb
4
3
  -
5
4
  CONTRIBUTING.md
6
- STABILITY.md
7
5
  LICENSE
8
- docs/quick_start.md
9
- docs/installation.md
10
- docs/webpacker.md
11
- docs/action_text.md
12
- docs/cheat.md
13
- docs/faq.md
data/README.md CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  ![Unit tests status](https://github.com/zachahn/super/workflows/Unit%20tests/badge.svg?branch=master)
4
4
  [![Gem](https://img.shields.io/gem/v/super)][gem]
5
- [![Try the demo](https://img.shields.io/badge/try-demo-blue)][demo]
5
+ [![Try the demo](https://img.shields.io/badge/demo-try-blue)][demo]
6
+ [![Read the docs](https://img.shields.io/badge/docs-available-brightgreen)][docs]
6
7
 
7
8
 
8
9
  Super is an admin framework for Ruby on Rails applications. Super helps you make
@@ -48,13 +49,7 @@ See the [stability doc](./STABILITY.md) for an idea of what might be changed.
48
49
 
49
50
 
50
51
  See the [demo][demo] and its [source][demo_source] for an example of some of its
51
- features.
52
-
53
-
54
- ## Installation and Usage
55
-
56
- See [Installation](./docs/quick_start.md) and
57
- [Quick start](./docs/quick_start.md)
52
+ features. See the [docs][docs] for a walkthrough.
58
53
 
59
54
 
60
55
  ## Editions
@@ -101,6 +96,7 @@ The gem is available under the terms of the [GNU LGPLv3](./LICENSE).
101
96
 
102
97
  [gem]: https://rubygems.org/gems/super
103
98
  [discussions]: https://github.com/zachahn/super/discussions
99
+ [docs]: https://superadministration.github.io/
104
100
  [newsletter]: https://tinyletter.com/zachahn
105
101
  [demo]: https://demo-super.herokuapp.com/admin/members
106
102
  [demo_source]: https://github.com/zachahn/super_demo
@@ -38,7 +38,7 @@ module Super
38
38
  @record = controls.build_record_with_params(action: action_inquirer, params: params)
39
39
 
40
40
  if controls.save_record(action: action_inquirer, record: @record, params: params)
41
- redirect_to polymorphic_path(Super.configuration.path_parts(@record))
41
+ redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
42
42
  else
43
43
  @form = controls.form_schema(action: action_inquirer_for("new"))
44
44
  @view = controls.new_view
@@ -58,7 +58,7 @@ module Super
58
58
  @record = controls.load_record(action: action_inquirer, params: params)
59
59
 
60
60
  if controls.update_record(action: action_inquirer, record: @record, params: params)
61
- redirect_to polymorphic_path(Super.configuration.path_parts(@record))
61
+ redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
62
62
  else
63
63
  @form = controls.form_schema(action: action_inquirer_for("edit"))
64
64
  @view = controls.edit_view
@@ -71,14 +71,14 @@ module Super
71
71
  @record = controls.load_record(action: action_inquirer, params: params)
72
72
 
73
73
  if controls.destroy_record(action: action_inquirer, record: @record, params: params)
74
- redirect_to polymorphic_path(Super.configuration.path_parts(controls.model))
74
+ redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
75
75
  else
76
76
  flash.alert = "Couldn't delete record"
77
- redirect_to polymorphic_path(Super.configuration.path_parts(@record))
77
+ redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
78
78
  end
79
79
  rescue ActiveRecord::InvalidForeignKey => e
80
80
  flash.alert = "Couldn't delete record: #{e.class}"
81
- redirect_to polymorphic_path(Super.configuration.path_parts(@record))
81
+ redirect_to polymorphic_path(Super::Link.polymorphic_parts(@record))
82
82
  end
83
83
 
84
84
  private
@@ -38,9 +38,7 @@
38
38
  <div class="px-4">
39
39
  <header class="pt-4">
40
40
  <h1 class="text-lg font-bold mr-6 mb-1"><%= Super.configuration.title %></h1>
41
- <%
42
- route_namespace = Super.configuration.route_namespace.map(&:to_s).join("/")
43
- Super::Navigation::Automatic.new(route_namespace: route_namespace).each do |text, href| %>
41
+ <% Super::Navigation::Automatic.new.each do |text, href| %>
44
42
  <%= link_to(text, href, class: "inline-block mr-6") %>
45
43
  <% end %>
46
44
  </header>
@@ -2,7 +2,7 @@
2
2
  <table class="w-full border-separate relative" cellspacing="0" cellpadding="0">
3
3
  <thead class="">
4
4
  <tr class="">
5
- <% super_schema_display_index.each_attribute_name do |attribute_name| %>
5
+ <% display_index.each_attribute_name do |attribute_name| %>
6
6
  <th class="p-2 first:pl-6 border-b border-b-2 border-gray-400 text-gray-600 text-left text-sm font-normal bg-white top-0 z-10">
7
7
  <%= controls.model.human_attribute_name(attribute_name) %>
8
8
  </th>
@@ -12,9 +12,9 @@
12
12
  <tbody class="">
13
13
  <% @records.each.with_index do |record, row_index| %>
14
14
  <tr id="record-pk-<%= record.id %>" class="group">
15
- <% super_schema_display_index.each_attribute_name do |attribute_name| %>
15
+ <% display_index.each_attribute_name do |attribute_name| %>
16
16
  <td class="py-1 px-2 first:pl-5 border-transparent border-t border-b group-hover:bg-blue-200 first:border-l first:rounded-l-lg last:border-r last:rounded-r-lg bg-white <%= Super::ViewHelper.classes(["bg-gray-100", row_index.odd?]) %>">
17
- <%= super_schema_display_index.render_field(template: self, record: record, column: attribute_name) %>
17
+ <%= display_index.render_attribute(template: self, record: record, column: attribute_name) %>
18
18
  </td>
19
19
  <% end %>
20
20
  </tr>
@@ -0,0 +1,8 @@
1
+ <table class="max-w-full mt-4">
2
+ <% display_show.each_attribute_name do |attribute_name| %>
3
+ <tr>
4
+ <th class="py-1 align-baseline text-right px-4"><%= controls.model.human_attribute_name(attribute_name) %></th>
5
+ <td class="py-1 align-baseline"><%= display_show.render_attribute(template: self, record: @record, column: attribute_name) %></td>
6
+ </tr>
7
+ <% end %>
8
+ </table>
@@ -1,6 +1,6 @@
1
- <%= super_form_for(Super.configuration.path_parts(@record), builder: Super::Form::Builder) do |f| %>
1
+ <%= super_form_for(Super::Link.polymorphic_parts(@record), builder: Super::Form::Builder) do |f| %>
2
2
  <div class="max-w-3xl">
3
- <% super_schema_form.each_attribute do |field, type| %>
3
+ <% form.each_attribute do |field, type| %>
4
4
  <%= render(
5
5
  type,
6
6
  form: f,
@@ -1,29 +1,29 @@
1
- <% super_layout.resolve(self) %>
1
+ <% layout.resolve(self) %>
2
2
 
3
- <% super_layout.resolved_headers.each do |partial| %>
3
+ <% layout.resolved_headers.each do |partial| %>
4
4
  <%= Super::Partial.render(partial, template: self) %>
5
5
  <% end %>
6
6
 
7
- <% if super_layout.resolved_asides.empty? %>
8
- <% super_layout.resolved_mains.each do |partial| %>
7
+ <% if layout.resolved_asides.empty? %>
8
+ <% layout.resolved_mains.each do |partial| %>
9
9
  <%= Super::Partial.render(partial, template: self) %>
10
10
  <% end %>
11
11
  <% else %>
12
12
  <div class="clearfix -mx-2">
13
13
  <div class="md:float-left md:w-9/12 px-2">
14
- <% super_layout.resolved_mains.each do |partial| %>
14
+ <% layout.resolved_mains.each do |partial| %>
15
15
  <%= Super::Partial.render(partial, template: self) %>
16
16
  <% end %>
17
17
  </div>
18
18
 
19
19
  <div class="md:float-right md:w-3/12 px-2">
20
- <% super_layout.resolved_asides.each do |partial| %>
20
+ <% layout.resolved_asides.each do |partial| %>
21
21
  <%= Super::Partial.render(partial, template: self) %>
22
22
  <% end %>
23
23
  </div>
24
24
  </div>
25
25
  <% end %>
26
26
 
27
- <% super_layout.resolved_footers.each do |partial| %>
27
+ <% layout.resolved_footers.each do |partial| %>
28
28
  <%= Super::Partial.render(partial, template: self) %>
29
29
  <% end %>
@@ -5,7 +5,7 @@
5
5
  <%= link_to(
6
6
  display,
7
7
  polymorphic_path(
8
- Super.configuration.path_parts(controls.model),
8
+ Super::Link.polymorphic_parts(controls.model),
9
9
  page_query_params
10
10
  ),
11
11
  class: "inline-block ml-2 text-lg #{is_current_page ? " text-gray-900" : ""}"
@@ -1,6 +1,6 @@
1
- <% if super_panel.resolve(self, block_given? ? Proc.new { yield } : nil).resolved_parts.any? %>
1
+ <% if panel.resolve(self, block_given? ? Proc.new { yield } : nil).resolved_parts.any? %>
2
2
  <div class="border rounded shadow border-gray-400 bg-white px-5 pt-4 pb-8 mt-6">
3
- <% super_panel.resolved_parts.each do |partial| %>
3
+ <% panel.resolved_parts.each do |partial| %>
4
4
  <%= Super::Partial.render(partial, template: self) %>
5
5
  <% end %>
6
6
  </div>
@@ -9,6 +9,12 @@ module Super
9
9
  class_option :route_namespace, type: :string, default: "admin",
10
10
  banner: "Specifies the route namespace for admin controllers"
11
11
 
12
+ def assert_not_controller_namespace_not_super
13
+ if controller_namespace == "super"
14
+ raise Super::Error::ArgumentError, "controller_namespace can not be `super`"
15
+ end
16
+ end
17
+
12
18
  def create_initializer
13
19
  template("initializer.rb", "config/initializers/super.rb")
14
20
  end
@@ -16,8 +22,7 @@ module Super
16
22
  def create_base_admin_controller
17
23
  template(
18
24
  "base_controller.rb",
19
- "app/controllers/#{controller_namespace}_controller.rb",
20
- controller_namespace: controller_namespace
25
+ "app/controllers/#{parent_controller_name}_controller.rb"
21
26
  )
22
27
  end
23
28
 
@@ -53,12 +58,16 @@ module Super
53
58
 
54
59
  private
55
60
 
61
+ def route_namespace
62
+ options[:route_namespace].strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip.underscore
63
+ end
64
+
56
65
  def controller_namespace
57
- if options["controller_namespace"].blank?
58
- "admin"
59
- else
60
- options["controller_namespace"]
61
- end
66
+ options["controller_namespace"].strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip.underscore
67
+ end
68
+
69
+ def parent_controller_name
70
+ controller_namespace.presence || "admin"
62
71
  end
63
72
  end
64
73
  end
@@ -1,2 +1,10 @@
1
- class <%= config[:controller_namespace].classify %>Controller < Super::ApplicationController
1
+ class <%= parent_controller_name.classify %>Controller < Super::ApplicationController
2
+ class <%= parent_controller_name.classify.demodulize %>Controls < Super::Controls
3
+ end
4
+
5
+ private
6
+
7
+ def new_controls
8
+ self.class::Controls.new
9
+ end
2
10
  end
@@ -1,5 +1,12 @@
1
1
  Super.configuration do |c|
2
2
  c.title = "My Admin Site"
3
- c.controller_namespace = "<%= options["controller_namespace"] %>"
4
- c.route_namespace = "<%= options["route_namespace"] %>"
3
+ <% if route_namespace != "admin" -%>
4
+ c.path = "/<%= route_namespace %>"
5
+ <% end -%>
6
+ <% if route_namespace != "admin" -%>
7
+ c.generator_as = "<%= route_namespace.gsub(%r{/}, "_") %>"
8
+ <% end -%>
9
+ <% if controller_namespace != "admin" -%>
10
+ c.generator_module = "<%= controller_namespace %>"
11
+ <% end -%>
5
12
  end
@@ -1,54 +1,129 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "rails/generators/resource_helpers"
4
+
3
5
  module Super
4
6
  class ResourceGenerator < Rails::Generators::NamedBase
7
+ include Rails::Generators::ResourceHelpers
5
8
  source_root File.expand_path("templates", __dir__)
6
9
 
7
- def create_controller
8
- controller_subdir =
9
- if Super.configuration.controller_namespace.present?
10
- "#{Super.configuration.controller_namespace}/"
11
- else
12
- ""
13
- end
10
+ check_class_collision suffix: "Controller"
11
+
12
+ class_option :skip_routes, type: :boolean, desc: "Don't add routes to config/routes.rb."
13
+
14
+ def initialize(*)
15
+ super
16
+
17
+ controller_namespace = Super.configuration.generator_module
18
+ if controller_namespace.present?
19
+ controller_name =
20
+ if controller_namespace.include?("/")
21
+ "#{controller_namespace}/#{name}"
22
+ else
23
+ "#{controller_namespace}::#{name}"
24
+ end
25
+ self.options = options.dup
26
+ options[:model_name] = name
27
+ options.freeze
28
+ assign_names!(name)
29
+ assign_controller_names!(controller_name.pluralize)
30
+ else
31
+ assign_names!(name)
32
+ assign_controller_names!(name.pluralize)
33
+ end
34
+ end
14
35
 
36
+ def create_controller
15
37
  template(
16
38
  "resources_controller.rb",
17
- "app/controllers/#{controller_subdir}#{file_path.pluralize}_controller.rb"
39
+ File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
18
40
  )
19
41
  end
20
42
 
21
- private
43
+ def create_route_namespace
44
+ data = route_scope
45
+ return if data.nil?
46
+ return if File.read(File.join(destination_root, "config", "routes.rb")).include?(data)
22
47
 
23
- def wrap_with_configured_module(&block)
24
- indentation_amount =
25
- if Super.configuration.controller_namespace.present?
26
- 2
27
- else
28
- 0
29
- end
48
+ inject_into_file(
49
+ "config/routes.rb",
50
+ "#{data}\nend\n".indent(2),
51
+ after: /^Rails\.application\.routes\.draw\b.*$\r?\n\r?/,
52
+ verbose: true,
53
+ force: false
54
+ )
55
+ end
30
56
 
31
- inner = capture(&block)
32
- inner = indent(inner, indentation_amount).chomp
57
+ def add_admin_route
58
+ data = route_scope
33
59
 
34
- if Super.configuration.controller_namespace.present?
35
- concat("module #{Super.configuration.controller_namespace.camelize}\n")
60
+ if data.nil?
61
+ route("resources :#{file_name.pluralize}")
62
+ else
63
+ inject_into_file(
64
+ "config/routes.rb",
65
+ "resources :#{file_name.pluralize}\n".indent(4),
66
+ after: /#{data}.*$\r?\n\r?/,
67
+ verbose: true,
68
+ force: false
69
+ )
36
70
  end
71
+ end
37
72
 
38
- concat(inner)
39
- concat("\n")
73
+ private
40
74
 
41
- if Super.configuration.controller_namespace.present?
42
- concat("end\n")
43
- end
75
+ def parent_controller_name
76
+ controller_namespace.presence || "admin"
44
77
  end
45
78
 
46
- def parent_controller_name
47
- if Super.configuration.controller_namespace.present?
48
- "#{Super.configuration.controller_namespace.camelize}Controller"
49
- else
50
- "AdminController"
79
+ def controller_namespace
80
+ Super.configuration.generator_module.strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip.underscore
81
+ end
82
+
83
+ def route_scope
84
+ return nil if no_scope?
85
+
86
+ if use_scope?
87
+ kwargs = []
88
+ kwargs.push(%(path: "/#{g_path}")) if g_path.present?
89
+ kwargs.push(%(module: "#{g_module}")) if g_module.present?
90
+ kwargs.push(%(as: "#{g_as}")) if g_as.present?
91
+ return %(scope #{kwargs.join(", ")} do)
51
92
  end
93
+
94
+ %(namespace :#{g_module} do)
95
+ end
96
+
97
+ def use_scope?
98
+ return true if !same?
99
+ return true if g_module.include?("/")
100
+ return true if g_path.include?("/")
101
+
102
+ false
103
+ end
104
+
105
+ def no_scope?
106
+ g_module.blank? && g_path.blank? && g_as.blank?
107
+ end
108
+
109
+ def same?
110
+ g_module == g_path && g_path == g_as
111
+ end
112
+
113
+ def g_module
114
+ normalized_scope_part(Super.configuration.generator_module || "")
115
+ end
116
+
117
+ def g_path
118
+ normalized_scope_part(Super.configuration.path || "")
119
+ end
120
+
121
+ def g_as
122
+ normalized_scope_part(Super.configuration.generator_as || "")
123
+ end
124
+
125
+ def normalized_scope_part(part)
126
+ part.strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip
52
127
  end
53
128
  end
54
129
  end
@@ -1,12 +1,6 @@
1
- <% wrap_with_configured_module do -%>
2
- class <%= class_name.pluralize %>Controller < <%= parent_controller_name %>
3
- private
4
-
5
- def new_controls
6
- Controls.new
7
- end
8
-
9
- class Controls < Super::Controls
1
+ <% module_namespacing do -%>
2
+ class <%= controller_class_name %>Controller < <%= parent_controller_name.classify %>Controller
3
+ class Controls < <%= parent_controller_name.classify.demodulize %>Controls
10
4
  def model
11
5
  <%= class_name %>
12
6
  end