super 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +3 -3
  3. data/Rakefile +3 -1
  4. data/app/assets/config/super_manifest.js +2 -1
  5. data/app/controllers/super/application_controller.rb +43 -10
  6. data/app/views/layouts/super/application.html.erb +2 -0
  7. data/app/views/super/application/_flash.html.erb +17 -0
  8. data/app/views/super/application/_form.html.erb +2 -0
  9. data/app/views/super/application/_index.html.erb +5 -3
  10. data/app/views/super/application/_show.html.erb +12 -0
  11. data/app/views/super/application/edit.html.erb +0 -1
  12. data/app/views/super/application/index.html.erb +1 -1
  13. data/app/views/super/application/new.html.erb +0 -1
  14. data/app/views/super/application/nothing.html.erb +0 -0
  15. data/app/views/super/application/show.html.erb +1 -10
  16. data/lib/generators/super/install/USAGE +4 -2
  17. data/lib/generators/super/install/install_generator.rb +2 -3
  18. data/lib/generators/super/resource/USAGE +1 -2
  19. data/lib/generators/super/resource/resource_generator.rb +0 -2
  20. data/lib/generators/super/resource/templates/resources_controller.rb.tt +38 -2
  21. data/lib/super.rb +1 -0
  22. data/lib/super/action_inquirer.rb +88 -0
  23. data/lib/super/error.rb +8 -0
  24. data/lib/super/test_support/{templates → copy_app_templates}/20190216224956_create_members.rb +0 -0
  25. data/lib/super/test_support/{templates → copy_app_templates}/20190803143320_create_ships.rb +0 -0
  26. data/lib/super/test_support/{templates → copy_app_templates}/20190806014121_add_ship_to_members.rb +0 -0
  27. data/lib/super/test_support/{templates → copy_app_templates}/member.rb +0 -0
  28. data/lib/super/test_support/copy_app_templates/members_controller.rb +52 -0
  29. data/lib/super/test_support/{templates → copy_app_templates}/routes.rb +0 -0
  30. data/lib/super/test_support/{templates → copy_app_templates}/seeds.rb +0 -0
  31. data/lib/super/test_support/{templates → copy_app_templates}/ship.rb +0 -0
  32. data/lib/super/test_support/copy_app_templates/ships_controller.rb +47 -0
  33. data/lib/super/test_support/generate_copy_app.rb +52 -0
  34. data/lib/super/test_support/generate_dummy.rb +94 -0
  35. data/lib/super/version.rb +1 -1
  36. metadata +49 -20
  37. data/lib/generators/super/resource/templates/resource_dashboard.rb.tt +0 -65
  38. data/lib/super/test_support/setup.rb +0 -79
  39. data/lib/super/test_support/templates/admin/members_controller.rb +0 -9
  40. data/lib/super/test_support/templates/admin/ships_controller.rb +0 -9
  41. data/lib/super/test_support/templates/admin_controller.rb +0 -2
  42. data/lib/super/test_support/templates/member_dashboard.rb +0 -90
  43. data/lib/super/test_support/templates/ship_dashboard.rb +0 -79
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b163f7e235c08db1d35265eb7d775ed897efc11efcb2a20afb488c9bf1a3a5f4
4
- data.tar.gz: b09f70d36011346bd2d159a10f2fe3a0e355b33b8fd85f358b0d4468e779e9e2
3
+ metadata.gz: 74ba324687da6f66c601cc930761a2e7c6b7d6372551cac3a6a3f1dd0a1625fb
4
+ data.tar.gz: f241d0809a63163acbe5f0490bee1adc45c503c3d40285cd5d4fc85bbccc4ae3
5
5
  SHA512:
6
- metadata.gz: a98e6f5cacff41948d7bf5eba93c1b73e0425180b142e214a66e07c3e10ee56f5c8236e80658f0d9bccf32201cd576b628a1f06abffd684c00df1a390ebac518
7
- data.tar.gz: 840ab8f2d560c5f0fb5abdc9de0e2398be6a2f6fc835af76d7a66b0d2a41c2c2f35fd664069948808c8839d5e6c19a649bc420731abd424e9410e62751edb44c
6
+ metadata.gz: df043e99295ce0abd1849843092c6e6ae56a131fdcbccd07174576047853927aade45d3ca9267b2ee7b4ba0cecb346937dfffcc5d5244542c143e32af9cc0ac3
7
+ data.tar.gz: 4953c826d8eab8fdd6b265a25a5cc598a481e3c32240bcb8ecf2266f4703e30c99960df08c0337b64b89f498645473f1cbe5572a1bf8dd4cd6cdacd406d56d07
data/README.md CHANGED
@@ -59,9 +59,9 @@ notified of its availability or for brief, occasional updates.
59
59
  $ bundle exec rails g super:resource Thing # check out the `--help` option!
60
60
  ```
61
61
 
62
- In the example above, it will create two files, the appropriate admin controller
63
- and its related "dashboard" file. The dashboard file is where most configuration
64
- lives, so it's unlikely you'll need to modify the controller.
62
+ The example above will create the appropriate admin controller. It generates a
63
+ `Controls` class inside the controller as well; it's where most configuration
64
+ lives. You generally won't need to edit the controller actions themselves.
65
65
 
66
66
  In addition, you'll have to manually update your routes file. It'll probably
67
67
  look something like the following:
data/Rakefile CHANGED
@@ -14,7 +14,9 @@ RDoc::Task.new(:rdoc) do |rdoc|
14
14
  rdoc.rdoc_files.include('lib/**/*.rb')
15
15
  end
16
16
 
17
- APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
17
+ require_relative "dummy_path"
18
+
19
+ APP_RAKEFILE = File.expand_path("#{SUPER_DUMMY_PATH}/Rakefile", __dir__)
18
20
  load 'rails/tasks/engine.rake'
19
21
 
20
22
  load 'rails/tasks/statistics.rake'
@@ -1 +1,2 @@
1
- //= link_tree ../frontend
1
+ //= link super/application.css
2
+ //= link super/application.js
@@ -5,16 +5,42 @@ module Super
5
5
 
6
6
  register_inline_callback(:index_paginate, on: :index, after: :yield)
7
7
 
8
+ helper_method :action_inquirer
8
9
  helper_method :controls
9
10
 
11
+ rescue_from Error::ClientError do |exception|
12
+ code, default_message =
13
+ case exception
14
+ when Error::UnprocessableEntity
15
+ [422, "Unprocessable entity"]
16
+ when Error::NotFound
17
+ [404, "Not found"]
18
+ when Error::Forbidden
19
+ [403, "Forbidden"]
20
+ when Error::Unauthorized
21
+ [401, "Unauthorized"]
22
+ when Error::BadRequest, Error::ClientError
23
+ [400, "Bad request"]
24
+ end
25
+
26
+ flash.now.alert =
27
+ if exception.message == exception.class.name.to_s
28
+ default_message
29
+ else
30
+ exception.message
31
+ end
32
+
33
+ render "nothing", status: code
34
+ end
35
+
10
36
  def index
11
37
  with_inline_callbacks do
12
- @resources = controls.index_scope
38
+ @resources = controls.scope(action: action_inquirer)
13
39
  end
14
40
  end
15
41
 
16
42
  def create
17
- @resource = controls.create_scope.build(create_permitted_params)
43
+ @resource = controls.scope(action: action_inquirer).build(create_permitted_params)
18
44
 
19
45
  if @resource.save
20
46
  redirect_to polymorphic_path(Super.configuration.path_parts(@resource))
@@ -24,19 +50,19 @@ module Super
24
50
  end
25
51
 
26
52
  def new
27
- @resource = controls.new_scope.build
53
+ @resource = controls.scope(action: action_inquirer).build
28
54
  end
29
55
 
30
56
  def edit
31
- @resource = controls.edit_scope.find(params[:id])
57
+ @resource = controls.scope(action: action_inquirer).find(params[:id])
32
58
  end
33
59
 
34
60
  def show
35
- @resource = controls.show_scope.find(params[:id])
61
+ @resource = controls.scope(action: action_inquirer).find(params[:id])
36
62
  end
37
63
 
38
64
  def update
39
- @resource = controls.update_scope.find(params[:id])
65
+ @resource = controls.scope(action: action_inquirer).find(params[:id])
40
66
 
41
67
  if @resource.update(update_permitted_params)
42
68
  redirect_to polymorphic_path(Super.configuration.path_parts(@resource))
@@ -46,7 +72,7 @@ module Super
46
72
  end
47
73
 
48
74
  def destroy
49
- @resource = controls.destroy_scope.find(params[:id])
75
+ @resource = controls.scope(action: action_inquirer).find(params[:id])
50
76
  if @resource.destroy
51
77
  redirect_to polymorphic_path(Super.configuration.path_parts(controls.model))
52
78
  else
@@ -70,15 +96,22 @@ module Super
70
96
  end
71
97
 
72
98
  def controls
73
- Controls.new(dashboard)
99
+ Super::Controls.new(new_controls)
74
100
  end
75
101
 
76
102
  def create_permitted_params
77
- controls.create_permitted_params(params)
103
+ controls.permitted_params(params, action: action_inquirer)
78
104
  end
79
105
 
80
106
  def update_permitted_params
81
- controls.update_permitted_params(params)
107
+ controls.permitted_params(params, action: action_inquirer)
108
+ end
109
+
110
+ def action_inquirer
111
+ @action_inquirer ||= ActionInquirer.new(
112
+ ActionInquirer.default_resources,
113
+ params[:action]
114
+ )
82
115
  end
83
116
  end
84
117
  end
@@ -27,6 +27,8 @@
27
27
  <% end %>
28
28
  </header>
29
29
 
30
+ <%= render "flash" %>
31
+
30
32
  <div class="pt-8"></div>
31
33
 
32
34
  <% if content_for?(:header) %>
@@ -0,0 +1,17 @@
1
+ <%
2
+ colors = {
3
+ "notice" => { bg: "bg-blue-100", fg: "text-blue-400", border: "border-blue-600" },
4
+ "alert" => { bg: "bg-red-100", fg: "text-red-400", border: "border-red-600" },
5
+ }
6
+ %>
7
+
8
+ <div data-flash="anchor">
9
+ <% flash.each do |level, messages| %>
10
+ <% Array(messages).each do |message| %>
11
+ <% color = colors[level.to_s] || colors["notice"] %>
12
+ <div class="<%= "%<bg>s %<fg>s border-l-4 %<border>s p-4 mt-2" % color %>">
13
+ <%= message %>
14
+ </div>
15
+ <% end %>
16
+ <% end %>
17
+ </div>
@@ -1,3 +1,5 @@
1
+ <% schema = controls.form_schema(action: action_inquirer) %>
2
+
1
3
  <%= form_for(Super.configuration.path_parts(resource)) do |f| %>
2
4
  <% schema.fields.each do |field, type| %>
3
5
  <%= render(
@@ -1,3 +1,5 @@
1
+ <% schema = controls.display_schema(action: action_inquirer) %>
2
+
1
3
  <% content_for(:header) do %>
2
4
  <header>
3
5
  <h1 class="text-3xl inline-block">
@@ -14,7 +16,7 @@
14
16
  <table class="w-full leading-loose mt-4">
15
17
  <thead class="border-gray-400 border-solid">
16
18
  <tr>
17
- <% (controls.index_schema.field_keys + ["Actions"]).each do |column| %>
19
+ <% (schema.field_keys + ["Actions"]).each do |column| %>
18
20
  <th class="text-left"><%= column.to_s.humanize %></th>
19
21
  <% end %>
20
22
  </tr>
@@ -22,8 +24,8 @@
22
24
  <tbody>
23
25
  <% @resources.each.with_index do |resource, index| %>
24
26
  <tr id="resource-pk-<%= resource.id %>" class="<%= index.even? ? "bg-gray-100" : "" %>" >
25
- <% controls.index_schema.field_keys.each do |column| %>
26
- <td><%= Super::Display.format(controls.index_schema, resource, column) %></td>
27
+ <% schema.field_keys.each do |column| %>
28
+ <td><%= Super::Display.format(schema, resource, column) %></td>
27
29
  <% end %>
28
30
  <td>
29
31
  <%= link_to(
@@ -0,0 +1,12 @@
1
+ <% schema = controls.display_schema(action: action_inquirer) %>
2
+
3
+ <h1 class="text-3xl"><%= controls.title %></h1>
4
+
5
+ <table class="max-w-full leading-loose mt-4">
6
+ <% schema.field_keys.each do |column| %>
7
+ <tr>
8
+ <th class="text-right px-4"><%= column.to_s.humanize %></th>
9
+ <td><%= Super::Display.format(schema, @resource, column) %></td>
10
+ </tr>
11
+ <% end %>
12
+ </table>
@@ -2,6 +2,5 @@
2
2
  partial: "form",
3
3
  locals: {
4
4
  resource: @resource,
5
- schema: controls.edit_schema,
6
5
  }
7
6
  ) %>
@@ -1 +1 @@
1
- <%= render "index" %>
1
+ <%= render("index") %>
@@ -2,6 +2,5 @@
2
2
  partial: "form",
3
3
  locals: {
4
4
  resource: @resource,
5
- schema: controls.new_schema,
6
5
  }
7
6
  ) %>
@@ -1,10 +1 @@
1
- <h1 class="text-3xl"><%= controls.title %></h1>
2
-
3
- <table class="max-w-full leading-loose mt-4">
4
- <% controls.show_schema.field_keys.each do |column| %>
5
- <tr>
6
- <th class="text-right px-4"><%= column.to_s.humanize %></th>
7
- <td><%= Super::Display.format(controls.show_schema, @resource, column) %></td>
8
- </tr>
9
- <% end %>
10
- </table>
1
+ <%= render("show") %>
@@ -20,7 +20,8 @@ Example:
20
20
  config/initializers/super.rb
21
21
  app/controllers/admin_controller.rb
22
22
  app/controllers/admin/.keep
23
- app/super/.keep
23
+
24
+ This will also update your Sprockets manifest as necessary.
24
25
 
25
26
  Example:
26
27
  rails generate super:install --controller-namespace badminton
@@ -29,4 +30,5 @@ Example:
29
30
  config/initializers/super.rb
30
31
  app/controllers/badminton_controller.rb
31
32
  app/controllers/badminton/.keep
32
- app/super/.keep
33
+
34
+ This will also update your Sprockets manifest as necessary.
@@ -29,9 +29,8 @@ module Super
29
29
  create_file("app/controllers/#{controller_namespace}/.keep", "")
30
30
  end
31
31
 
32
- def create_directory_for_dashboards_slash_setup
33
- empty_directory("app/super")
34
- create_file("app/super/.keep", "")
32
+ def setup_sprockets4_manifest
33
+ append_to_file "app/assets/config/manifest.js", "//= link super_manifest.js\n"
35
34
  end
36
35
 
37
36
  private
@@ -1,9 +1,8 @@
1
1
  Description:
2
- Creates a controller and its respective "control".
2
+ Creates a controller
3
3
 
4
4
  Example:
5
5
  rails generate super:resource Thing
6
6
 
7
7
  This will create:
8
8
  app/controllers/admin/things_controller.rb
9
- app/controls/thing_controls.rb
@@ -14,8 +14,6 @@ module Super
14
14
  "resources_controller.rb",
15
15
  "app/controllers/#{controller_subdir}#{file_path.pluralize}_controller.rb"
16
16
  )
17
-
18
- template("resource_dashboard.rb", "app/super/#{file_path}_dashboard.rb")
19
17
  end
20
18
 
21
19
  private
@@ -2,8 +2,44 @@
2
2
  class <%= class_name.pluralize %>Controller < <%= parent_controller_name %>
3
3
  private
4
4
 
5
- def dashboard
6
- <%= class_name %>Dashboard.new
5
+ def new_controls
6
+ Controls.new
7
+ end
8
+
9
+ class Controls
10
+ def title
11
+ <%= class_name %>.name.pluralize
12
+ end
13
+
14
+ def model
15
+ <%= class_name %>
16
+ end
17
+
18
+ def scope(action:)
19
+ if action.read?
20
+ <%= class_name %>.all
21
+ else
22
+ <%= class_name %>.all
23
+ end
24
+ end
25
+
26
+ def permitted_params(params, action:)
27
+ if action.create?
28
+ params.require(:<%= file_name %>).permit()
29
+ else
30
+ params.require(:<%= file_name %>).permit()
31
+ end
32
+ end
33
+
34
+ def display_schema(action:)
35
+ Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
36
+ end
37
+ end
38
+
39
+ def form_schema(action:)
40
+ Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
41
+ end
42
+ end
7
43
  end
8
44
  end
9
45
  <% end -%>
@@ -1,6 +1,7 @@
1
1
  require "tsort"
2
2
  require "active_support/concern"
3
3
 
4
+ require "super/action_inquirer"
4
5
  require "super/assets"
5
6
  require "super/configuration"
6
7
  require "super/controls"
@@ -0,0 +1,88 @@
1
+ module Super
2
+ class ActionInquirer
3
+ attr_reader :action
4
+
5
+ def self.default_resources
6
+ {
7
+ read: %i[index show new edit],
8
+ write: %i[create update destroy],
9
+ delete: %i[destroy]
10
+ }
11
+ end
12
+
13
+ def initialize(categories_and_their_actions, action)
14
+ @categories = categories_and_their_actions.keys.map(&:to_s)
15
+ @actions = categories_and_their_actions.values.flatten.uniq.map(&:to_s)
16
+ @actions_categories = {}
17
+
18
+ categories_and_their_actions.each do |c, actions|
19
+ c = c.to_s
20
+
21
+ actions.each do |a|
22
+ a = a.to_s
23
+ @actions_categories[a] ||= []
24
+ @actions_categories[a].push(c)
25
+ end
26
+ end
27
+
28
+ intersection = @categories & @actions
29
+ if intersection.any?
30
+ raise Error::ActionInquirerError,
31
+ "Found shared elements between categories and actions: #{intersection.join(", ")}"
32
+ end
33
+
34
+ self.action = action
35
+ end
36
+
37
+ def action=(new_action)
38
+ new_action = new_action.to_s
39
+ if !@actions.include?(new_action)
40
+ raise Error::ActionInquirerError, "Unknown action: #{new_action}"
41
+ end
42
+
43
+ @action = new_action
44
+ end
45
+
46
+ def respond_to_missing?(method_name, *)
47
+ inquiry = parse_inquiry(method_name)
48
+
49
+ return super if !inquiry
50
+
51
+ @actions.include?(inquiry) || @categories.include?(inquiry) || super
52
+ end
53
+
54
+ def method_missing(method_name, *)
55
+ inquiry = parse_inquiry(method_name)
56
+
57
+ return super if !inquiry
58
+
59
+ if @actions.include?(inquiry)
60
+ matches_action?(inquiry)
61
+ elsif @categories.include?(inquiry)
62
+ matches_category?(inquiry)
63
+ else
64
+ super
65
+ end
66
+ end
67
+
68
+ private
69
+
70
+ def parse_inquiry(method_name)
71
+ inquiry = method_name.to_s
72
+
73
+ if inquiry[-1] != "?"
74
+ return nil
75
+ end
76
+
77
+ inquiry.chomp("?")
78
+ end
79
+
80
+ def matches_action?(inquiry)
81
+ @action == inquiry
82
+ end
83
+
84
+ def matches_category?(inquiry)
85
+ @actions_categories[@action].include?(inquiry)
86
+ end
87
+ end
88
+ end
@@ -4,5 +4,13 @@ module Super
4
4
  class InvalidConfiguration < Error; end
5
5
  class InvalidStyle < Error; end
6
6
  class InvalidPluginArgument < Error; end
7
+ class ActionInquirerError < Error; end
8
+
9
+ class ClientError < Error; end
10
+ class BadRequest < ClientError; end
11
+ class Unauthorized < ClientError; end
12
+ class Forbidden < ClientError; end
13
+ class NotFound < ClientError; end
14
+ class UnprocessableEntity < ClientError; end
7
15
  end
8
16
  end
@@ -0,0 +1,52 @@
1
+ module Admin
2
+ class MembersController < AdminController
3
+ private
4
+
5
+ def new_controls
6
+ Controls.new
7
+ end
8
+
9
+ class Controls
10
+ def title
11
+ Member.name.pluralize
12
+ end
13
+
14
+ def model
15
+ Member
16
+ end
17
+
18
+ def scope(action:)
19
+ Member.all
20
+ end
21
+
22
+ def permitted_params(params, action:)
23
+ params.require(:member).permit(:name, :rank, :position, :ship_id)
24
+ end
25
+
26
+ def display_schema(action:)
27
+ Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
28
+ fields[:name] = type.dynamic(&:itself)
29
+ fields[:rank] = type.dynamic(&:itself)
30
+ fields[:position] = type.dynamic(&:itself)
31
+ fields[:ship] = type.dynamic { |ship| "#{ship.name} (Ship ##{ship.id})" }
32
+ fields[:created_at] = type.dynamic(&:iso8601)
33
+ if action.show?
34
+ fields[:updated_at] = type.dynamic(&:iso8601)
35
+ end
36
+ end
37
+ end
38
+
39
+ def form_schema(action:)
40
+ Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
41
+ fields[:name] = type.generic("form_generic_text")
42
+ fields[:rank] = type.generic("form_generic_select", collection: Member.ranks.keys)
43
+ fields[:position] = type.generic("form_generic_text")
44
+ fields[:ship_id] = type.generic(
45
+ "form_generic_select",
46
+ collection: Ship.all.map { |s| ["#{s.name} (Ship ##{s.id})", s.id] },
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,47 @@
1
+ module Admin
2
+ class ShipsController < AdminController
3
+ private
4
+
5
+ def new_controls
6
+ Controls.new
7
+ end
8
+
9
+ class Controls
10
+ def title
11
+ Ship.name.pluralize
12
+ end
13
+
14
+ def model
15
+ Ship
16
+ end
17
+
18
+ def scope(action:)
19
+ Ship.all
20
+ end
21
+
22
+ def permitted_params(params, action:)
23
+ params.require(:ship).permit(:name, :registry, :class_name)
24
+ end
25
+
26
+ def display_schema(action:)
27
+ Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
28
+ fields[:name] = type.dynamic(&:itself)
29
+ fields[:registry] = type.dynamic(&:itself)
30
+ fields[:class_name] = type.dynamic(&:itself)
31
+ if action.show?
32
+ fields[:created_at] = type.dynamic(&:iso8601)
33
+ fields[:updated_at] = type.dynamic(&:iso8601)
34
+ end
35
+ end
36
+ end
37
+
38
+ def form_schema(action:)
39
+ Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
40
+ fields[:name] = type.generic("form_generic_text")
41
+ fields[:registry] = type.generic("form_generic_text")
42
+ fields[:class_name] = type.generic("form_generic_text")
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rails/generators"
4
+
5
+ class SuperCopyAppGenerator < Rails::Generators::Base
6
+ source_root(File.expand_path("copy_app_templates", __dir__))
7
+
8
+ class_option :destination, required: true
9
+
10
+ def set_destination_root
11
+ self.destination_root = options[:destination]
12
+ end
13
+
14
+ def ensure_reasonable_directory
15
+ app_path = File.join(destination_root, "app")
16
+ if !File.directory?(app_path)
17
+ raise "Can't find dir: #{app_path}"
18
+ end
19
+ end
20
+
21
+ def install_super
22
+ Rails::Generators.invoke("super:install", [], destination_root: destination_root)
23
+ end
24
+
25
+ def copy_app
26
+ copy_file "member.rb", "app/models/member.rb"
27
+ copy_file "ship.rb", "app/models/ship.rb"
28
+
29
+ copy_file "ships_controller.rb", "app/controllers/admin/ships_controller.rb"
30
+ copy_file "members_controller.rb", "app/controllers/admin/members_controller.rb"
31
+ end
32
+
33
+ def copy_db
34
+ migrations = [
35
+ "20190216224956_create_members.rb",
36
+ "20190803143320_create_ships.rb",
37
+ "20190806014121_add_ship_to_members.rb",
38
+ ]
39
+
40
+ migrations.each do |migration|
41
+ copy_file migration, "db/migrate/#{migration}"
42
+ end
43
+
44
+ copy_file "seeds.rb", "db/seeds.rb"
45
+ end
46
+
47
+ def copy_config
48
+ copy_file "routes.rb", "config/routes.rb"
49
+ end
50
+ end
51
+
52
+ SuperCopyAppGenerator.start
@@ -0,0 +1,94 @@
1
+ require "fileutils"
2
+ require "tmpdir"
3
+
4
+ require "rails"
5
+ require "rails/generators/rails/app/app_generator"
6
+ require "rails/generators/rails/plugin/plugin_generator"
7
+ require "generators/super/install/install_generator"
8
+
9
+ module Rails
10
+ module Generators
11
+ class AppGenerator
12
+ def valid_const?
13
+ true
14
+ end
15
+ end
16
+
17
+ class PluginGenerator
18
+ def valid_const?
19
+ true
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ class SuperDummyGenerator < Rails::Generators::Base
26
+ source_root(File.expand_path("templates", __dir__))
27
+
28
+ class_option :destination, required: true
29
+
30
+ def create_new_plugin
31
+ if plugin_name.blank?
32
+ warn "Not currently in a plugin directory"
33
+ exit
34
+ end
35
+
36
+ opts = {
37
+ force: true,
38
+ skip_active_storage: true,
39
+ skip_action_mailer: true,
40
+ skip_action_mailbox: true,
41
+ skip_action_text: true,
42
+ skip_active_storage: true,
43
+ skip_action_cable: true,
44
+ skip_puma: true,
45
+ skip_coffee: true,
46
+ database: "sqlite3",
47
+ }
48
+
49
+ Dir.mktmpdir do |dir|
50
+ plugin_path = File.join(dir, plugin_name)
51
+ generated_dummy_path = File.join(plugin_path, "test/dummy")
52
+
53
+ invoke(Rails::Generators::PluginGenerator, [plugin_path], opts)
54
+
55
+ inside(generated_dummy_path) do
56
+ remove_file(".ruby-version")
57
+ end
58
+
59
+ FileUtils.rm_rf(dummy_path)
60
+ FileUtils.mv(generated_dummy_path, dummy_path)
61
+ end
62
+ end
63
+
64
+ def delete_unnecessary_files
65
+ inside(dummy_path) do
66
+ remove_file("app/assets/javascripts/cable.js")
67
+ remove_file("app/channels/")
68
+ remove_file("public/apple-touch-icon-precomposed.png")
69
+ remove_file("public/apple-touch-icon.png")
70
+ remove_file("public/favicon.ico")
71
+ end
72
+ end
73
+
74
+ private
75
+
76
+ def dummy_path
77
+ @dummy_path ||= File.expand_path(options[:destination], destination_root)
78
+ end
79
+
80
+ def plugin_name
81
+ @plugin_name ||=
82
+ begin
83
+ filename = Dir.glob("*.gemspec").first
84
+
85
+ if filename.present?
86
+ File.basename(filename, ".gemspec")
87
+ else
88
+ ""
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ SuperDummyGenerator.start
@@ -1,3 +1,3 @@
1
1
  module Super
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: super
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-18 00:00:00.000000000 Z
11
+ date: 2019-11-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 1.3.6
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 1.3.6
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,34 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: yard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: mocha
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description:
98
126
  email:
99
127
  - engineering@zachahn.com
@@ -109,14 +137,17 @@ files:
109
137
  - app/assets/stylesheets/super/application.css
110
138
  - app/controllers/super/application_controller.rb
111
139
  - app/views/layouts/super/application.html.erb
140
+ - app/views/super/application/_flash.html.erb
112
141
  - app/views/super/application/_form.html.erb
113
142
  - app/views/super/application/_form_field.html.erb
114
143
  - app/views/super/application/_form_generic_select.html.erb
115
144
  - app/views/super/application/_form_generic_text.html.erb
116
145
  - app/views/super/application/_index.html.erb
146
+ - app/views/super/application/_show.html.erb
117
147
  - app/views/super/application/edit.html.erb
118
148
  - app/views/super/application/index.html.erb
119
149
  - app/views/super/application/new.html.erb
150
+ - app/views/super/application/nothing.html.erb
120
151
  - app/views/super/application/show.html.erb
121
152
  - app/views/super/feather/README.md
122
153
  - app/views/super/feather/_chevron_down.svg
@@ -136,12 +167,12 @@ files:
136
167
  - lib/generators/super/install/templates/initializer.rb.tt
137
168
  - lib/generators/super/resource/USAGE
138
169
  - lib/generators/super/resource/resource_generator.rb
139
- - lib/generators/super/resource/templates/resource_dashboard.rb.tt
140
170
  - lib/generators/super/resource/templates/resources_controller.rb.tt
141
171
  - lib/generators/super/webpacker/USAGE
142
172
  - lib/generators/super/webpacker/templates/pack_super_application.js.erb.tt
143
173
  - lib/generators/super/webpacker/webpacker_generator.rb
144
174
  - lib/super.rb
175
+ - lib/super/action_inquirer.rb
145
176
  - lib/super/assets.rb
146
177
  - lib/super/configuration.rb
147
178
  - lib/super/controls.rb
@@ -155,22 +186,20 @@ files:
155
186
  - lib/super/pagination.rb
156
187
  - lib/super/plugin.rb
157
188
  - lib/super/schema.rb
189
+ - lib/super/test_support/copy_app_templates/20190216224956_create_members.rb
190
+ - lib/super/test_support/copy_app_templates/20190803143320_create_ships.rb
191
+ - lib/super/test_support/copy_app_templates/20190806014121_add_ship_to_members.rb
192
+ - lib/super/test_support/copy_app_templates/member.rb
193
+ - lib/super/test_support/copy_app_templates/members_controller.rb
194
+ - lib/super/test_support/copy_app_templates/routes.rb
195
+ - lib/super/test_support/copy_app_templates/seeds.rb
196
+ - lib/super/test_support/copy_app_templates/ship.rb
197
+ - lib/super/test_support/copy_app_templates/ships_controller.rb
158
198
  - lib/super/test_support/fixtures/members.yml
159
199
  - lib/super/test_support/fixtures/ships.yml
160
- - lib/super/test_support/setup.rb
200
+ - lib/super/test_support/generate_copy_app.rb
201
+ - lib/super/test_support/generate_dummy.rb
161
202
  - lib/super/test_support/starfleet_seeder.rb
162
- - lib/super/test_support/templates/20190216224956_create_members.rb
163
- - lib/super/test_support/templates/20190803143320_create_ships.rb
164
- - lib/super/test_support/templates/20190806014121_add_ship_to_members.rb
165
- - lib/super/test_support/templates/admin/members_controller.rb
166
- - lib/super/test_support/templates/admin/ships_controller.rb
167
- - lib/super/test_support/templates/admin_controller.rb
168
- - lib/super/test_support/templates/member.rb
169
- - lib/super/test_support/templates/member_dashboard.rb
170
- - lib/super/test_support/templates/routes.rb
171
- - lib/super/test_support/templates/seeds.rb
172
- - lib/super/test_support/templates/ship.rb
173
- - lib/super/test_support/templates/ship_dashboard.rb
174
203
  - lib/super/version.rb
175
204
  - lib/super/view.rb
176
205
  - lib/tasks/super_tasks.rake
@@ -1,65 +0,0 @@
1
- class <%= class_name %>Dashboard
2
- def title
3
- <%= class_name %>.name.pluralize
4
- end
5
-
6
- def model
7
- <%= class_name %>
8
- end
9
-
10
- def index_scope
11
- <%= class_name %>.all
12
- end
13
-
14
- def index_schema
15
- Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
16
- end
17
- end
18
-
19
- def create_scope
20
- <%= class_name %>.all
21
- end
22
-
23
- def create_permitted_params(params)
24
- params.require(:<%= file_name %>).permit()
25
- end
26
-
27
- def new_scope
28
- <%= class_name %>.all
29
- end
30
-
31
- def new_schema
32
- Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
33
- end
34
- end
35
-
36
- def edit_scope
37
- <%= class_name %>.all
38
- end
39
-
40
- def edit_schema
41
- Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
42
- end
43
- end
44
-
45
- def show_scope
46
- <%= class_name %>.all
47
- end
48
-
49
- def show_schema
50
- Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
51
- end
52
- end
53
-
54
- def update_scope
55
- <%= class_name %>.all
56
- end
57
-
58
- def update_permitted_params(params)
59
- params.require(:<%= file_name %>).permit()
60
- end
61
-
62
- def destroy_scope
63
- <%= class_name %>.all
64
- end
65
- end
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "fileutils"
4
- require "pathname"
5
-
6
- def help!
7
- puts "usage: #{$0} path/to/dest/app"
8
- exit
9
- end
10
-
11
- def assert(message)
12
- if !yield
13
- puts message
14
- exit(1)
15
- end
16
- end
17
-
18
- def act(message, if_not:)
19
- if !if_not.call
20
- yield
21
- puts message
22
- end
23
- end
24
-
25
- if ARGV.size != 1
26
- help!
27
- end
28
-
29
- dest = ARGV.first
30
- dest = File.expand_path(dest, Dir.pwd)
31
- dest = Pathname.new(dest)
32
-
33
- src = File.expand_path("templates", __dir__)
34
- src = Pathname.new(src)
35
-
36
- assert("Path doesn't exist: #{dest.join("app")}") do
37
- dest.join("app").exist?
38
- end
39
-
40
- assert("Path doesn't exist: #{dest.join("app/models")}") do
41
- dest.join("app/models").exist?
42
- end
43
-
44
- FileUtils.cp(src.join("member.rb"), dest.join("app/models/member.rb"))
45
- FileUtils.cp(src.join("ship.rb"), dest.join("app/models/ship.rb"))
46
-
47
- assert("Path doesn't exist: #{dest.join("app/controllers")}") do
48
- dest.join("app/controllers").exist?
49
- end
50
-
51
- FileUtils.cp(src.join("admin_controller.rb"), dest.join("app/controllers/admin_controller.rb"))
52
-
53
- act "Created #{dest.join("app/controllers/admin")}", if_not: -> { dest.join("app/controllers/admin").exist? } do
54
- FileUtils.mkdir(dest.join("app/controllers/admin"))
55
- end
56
-
57
- FileUtils.cp(src.join("admin/members_controller.rb"), dest.join("app/controllers/admin/members_controller.rb"))
58
- FileUtils.cp(src.join("admin/ships_controller.rb"), dest.join("app/controllers/admin/ships_controller.rb"))
59
-
60
- act "Created #{dest.join("app/super")}", if_not: -> { dest.join("app/super").exist? } do
61
- FileUtils.mkdir(dest.join("app/super"))
62
- end
63
-
64
- FileUtils.cp(src.join("member_dashboard.rb"), dest.join("app/super/member_dashboard.rb"))
65
- FileUtils.cp(src.join("ship_dashboard.rb"), dest.join("app/super/ship_dashboard.rb"))
66
-
67
- act "Created #{dest.join("db/migrate")}", if_not: -> { dest.join("db/migrate").exist? } do
68
- FileUtils.mkdir(dest.join("db/migrate"))
69
- end
70
-
71
- FileUtils.cp(src.join("20190216224956_create_members.rb"), dest.join("db/migrate/20190216224956_create_members.rb"))
72
- FileUtils.cp(src.join("20190803143320_create_ships.rb"), dest.join("db/migrate/20190803143320_create_ships.rb"))
73
- FileUtils.cp(src.join("20190806014121_add_ship_to_members.rb"), dest.join("db/migrate/20190806014121_add_ship_to_members.rb"))
74
-
75
- FileUtils.cp(src.join("seeds.rb"), dest.join("db/seeds.rb"))
76
-
77
- FileUtils.cp(src.join("routes.rb"), dest.join("config/routes.rb"))
78
-
79
- puts "Done!"
@@ -1,9 +0,0 @@
1
- module Admin
2
- class MembersController < AdminController
3
- private
4
-
5
- def dashboard
6
- MemberDashboard.new
7
- end
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- module Admin
2
- class ShipsController < AdminController
3
- private
4
-
5
- def dashboard
6
- ShipDashboard.new
7
- end
8
- end
9
- end
@@ -1,2 +0,0 @@
1
- class AdminController < Super::ApplicationController
2
- end
@@ -1,90 +0,0 @@
1
- class MemberDashboard
2
- def title
3
- Member.name.pluralize
4
- end
5
-
6
- def model
7
- Member
8
- end
9
-
10
- def index_scope
11
- Member.all
12
- end
13
-
14
- def index_schema
15
- Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
16
- fields[:name] = type.dynamic { |name| name }
17
- fields[:rank] = type.dynamic { |rank| rank }
18
- fields[:position] = type.dynamic { |position| position }
19
- fields[:ship] = type.dynamic { |ship| "#{ship.name} (Ship ##{ship.id})" }
20
- fields[:created_at] = type.dynamic(&:iso8601)
21
- end
22
- end
23
-
24
- def create_scope
25
- Member.all
26
- end
27
-
28
- def create_permitted_params(params)
29
- params.require(:member).permit(:name, :rank, :position, :ship_id)
30
- end
31
-
32
- def new_scope
33
- Member.all
34
- end
35
-
36
- def new_schema
37
- Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
38
- fields[:name] = type.generic("form_generic_text")
39
- fields[:rank] = type.generic("form_generic_select", collection: Member.ranks.keys)
40
- fields[:position] = type.generic("form_generic_text")
41
- fields[:ship_id] = type.generic(
42
- "form_generic_select",
43
- collection: Ship.all.map { |s| ["#{s.name} (Ship ##{s.id})", s.id] },
44
- )
45
- end
46
- end
47
-
48
- def edit_scope
49
- Member.all
50
- end
51
-
52
- def edit_schema
53
- Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
54
- fields[:name] = type.generic("form_generic_text")
55
- fields[:rank] = type.generic("form_generic_select", collection: Member.ranks.keys)
56
- fields[:position] = type.generic("form_generic_text")
57
- fields[:ship_id] = type.generic(
58
- "form_generic_select",
59
- collection: Ship.all.map { |s| ["#{s.name} (Ship ##{s.id})", s.id] },
60
- )
61
- end
62
- end
63
-
64
- def show_scope
65
- Member.all
66
- end
67
-
68
- def show_schema
69
- Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
70
- fields[:name] = type.dynamic { |name| name }
71
- fields[:rank] = type.dynamic { |rank| rank }
72
- fields[:position] = type.dynamic { |position| position }
73
- fields[:ship] = type.dynamic { |ship| "#{ship.name} (Ship ##{ship.id})" }
74
- fields[:created_at] = type.dynamic(&:iso8601)
75
- fields[:updated_at] = type.dynamic(&:iso8601)
76
- end
77
- end
78
-
79
- def update_scope
80
- Member.all
81
- end
82
-
83
- def update_permitted_params(params)
84
- params.require(:member).permit(:name, :rank, :position, :ship_id)
85
- end
86
-
87
- def destroy_scope
88
- Member.all
89
- end
90
- end
@@ -1,79 +0,0 @@
1
- class ShipDashboard
2
- def title
3
- Ship.name.pluralize
4
- end
5
-
6
- def model
7
- Ship
8
- end
9
-
10
- def index_scope
11
- Ship.all
12
- end
13
-
14
- def index_schema
15
- Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
16
- fields[:name] = type.dynamic { |name| name }
17
- fields[:registry] = type.dynamic { |registry| registry }
18
- fields[:class_name] = type.dynamic { |class_name| class_name }
19
- end
20
- end
21
-
22
- def create_scope
23
- Ship.all
24
- end
25
-
26
- def create_permitted_params(params)
27
- params.require(:ship).permit(:name, :registry, :class_name)
28
- end
29
-
30
- def new_scope
31
- Ship.all
32
- end
33
-
34
- def new_schema
35
- Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
36
- fields[:name] = type.generic("form_generic_text")
37
- fields[:registry] = type.generic("form_generic_text")
38
- fields[:class_name] = type.generic("form_generic_text")
39
- end
40
- end
41
-
42
- def edit_scope
43
- Ship.all
44
- end
45
-
46
- def edit_schema
47
- Super::Schema.new(Super::Form::SchemaTypes.new) do |fields, type|
48
- fields[:name] = type.generic("form_generic_text")
49
- fields[:registry] = type.generic("form_generic_text")
50
- fields[:class_name] = type.generic("form_generic_text")
51
- end
52
- end
53
-
54
- def show_scope
55
- Ship.all
56
- end
57
-
58
- def show_schema
59
- Super::Schema.new(Super::Display::SchemaTypes.new) do |fields, type|
60
- fields[:name] = type.dynamic { |name| name }
61
- fields[:registry] = type.dynamic { |registry| registry }
62
- fields[:class_name] = type.dynamic { |class_name| class_name }
63
- fields[:created_at] = type.dynamic(&:iso8601)
64
- fields[:updated_at] = type.dynamic(&:iso8601)
65
- end
66
- end
67
-
68
- def update_scope
69
- Ship.all
70
- end
71
-
72
- def update_permitted_params(params)
73
- params.require(:ship).permit(:name, :registry, :class_name)
74
- end
75
-
76
- def destroy_scope
77
- Ship.all
78
- end
79
- end