super 0.0.0 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +10 -0
  3. data/LICENSE +165 -0
  4. data/README.md +66 -18
  5. data/Rakefile +3 -1
  6. data/app/assets/config/super_manifest.js +2 -0
  7. data/app/assets/javascripts/super/application.js +3618 -0
  8. data/app/assets/stylesheets/super/application.css +98584 -0
  9. data/app/controllers/super/application_controller.rb +103 -0
  10. data/app/helpers/super/application_helper.rb +32 -0
  11. data/app/views/layouts/super/application.html.erb +39 -0
  12. data/app/views/super/application/_flash.html.erb +17 -0
  13. data/app/views/super/application/_form.html.erb +17 -0
  14. data/app/views/super/application/_form_field__destroy.html.erb +9 -0
  15. data/app/views/super/application/_form_field_select.html.erb +23 -0
  16. data/app/views/super/application/_form_field_text.html.erb +13 -0
  17. data/app/views/super/application/_form_fieldset.html.erb +8 -0
  18. data/app/views/super/application/_form_has_many.html.erb +21 -0
  19. data/app/views/super/application/_form_has_one.html.erb +11 -0
  20. data/app/views/super/application/_form_inline_errors.html.erb +10 -0
  21. data/app/views/super/application/_index.html.erb +45 -0
  22. data/app/views/super/application/_resource_header.html.erb +16 -0
  23. data/app/views/super/application/_resources_header.html.erb +16 -0
  24. data/app/views/super/application/_show.html.erb +10 -0
  25. data/app/views/super/application/_super_layout.html.erb +34 -0
  26. data/app/views/super/application/_super_panel.html.erb +11 -0
  27. data/app/views/super/application/edit.html.erb +6 -0
  28. data/app/views/super/application/index.html.erb +6 -0
  29. data/app/views/super/application/new.html.erb +6 -0
  30. data/app/views/super/application/nothing.html.erb +0 -0
  31. data/app/views/super/application/show.html.erb +6 -0
  32. data/app/views/super/feather/README.md +32 -0
  33. data/app/views/super/feather/_chevron_down.svg +1 -0
  34. data/docs/README.md +6 -0
  35. data/docs/controls.md +39 -0
  36. data/docs/faq.md +44 -0
  37. data/docs/quick_start.md +45 -0
  38. data/docs/webpacker.md +17 -0
  39. data/docs/yard_customizations.rb +41 -0
  40. data/frontend/super-frontend/build.js +36 -0
  41. data/frontend/super-frontend/dist/application.css +98584 -0
  42. data/frontend/super-frontend/dist/application.js +3618 -0
  43. data/frontend/super-frontend/package.json +21 -0
  44. data/frontend/super-frontend/postcss.config.js +6 -0
  45. data/frontend/super-frontend/src/javascripts/super/application.ts +18 -0
  46. data/frontend/super-frontend/src/javascripts/super/apply_template_controller.ts +21 -0
  47. data/frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts +1 -0
  48. data/frontend/super-frontend/src/javascripts/super/toggle_pending_destruction_controller.ts +15 -0
  49. data/frontend/super-frontend/src/stylesheets/super/application.css +77 -0
  50. data/frontend/super-frontend/tailwind.config.js +9 -0
  51. data/frontend/super-frontend/tsconfig.json +13 -0
  52. data/frontend/super-frontend/yarn.lock +5540 -0
  53. data/lib/generators/super/install/USAGE +34 -0
  54. data/lib/generators/super/install/install_generator.rb +46 -0
  55. data/lib/generators/super/install/templates/base_controller.rb.tt +2 -0
  56. data/lib/generators/super/install/templates/initializer.rb.tt +5 -0
  57. data/lib/generators/super/resource/USAGE +8 -0
  58. data/lib/generators/super/resource/resource_generator.rb +52 -0
  59. data/lib/generators/super/resource/templates/resources_controller.rb.tt +45 -0
  60. data/lib/generators/super/webpacker/USAGE +14 -0
  61. data/lib/generators/super/webpacker/templates/pack_super_application.js.erb.tt +2 -0
  62. data/lib/generators/super/webpacker/webpacker_generator.rb +25 -0
  63. data/lib/super.rb +22 -4
  64. data/lib/super/action_inquirer.rb +101 -0
  65. data/lib/super/assets.rb +63 -0
  66. data/lib/super/compatibility.rb +13 -0
  67. data/lib/super/configuration.rb +103 -0
  68. data/lib/super/controls.rb +120 -0
  69. data/lib/super/display.rb +9 -0
  70. data/lib/super/display/schema_types.rb +40 -0
  71. data/lib/super/engine.rb +6 -0
  72. data/lib/super/error.rb +18 -0
  73. data/lib/super/form/schema_types.rb +115 -0
  74. data/lib/super/layout.rb +19 -0
  75. data/lib/super/link.rb +87 -0
  76. data/lib/super/navigation/automatic.rb +71 -0
  77. data/lib/super/pagination.rb +70 -0
  78. data/lib/super/panel.rb +17 -0
  79. data/lib/super/partial.rb +11 -0
  80. data/lib/super/plugin.rb +89 -0
  81. data/lib/super/schema.rb +73 -0
  82. data/lib/super/step.rb +36 -0
  83. data/lib/super/version.rb +1 -1
  84. data/lib/super/view_helper.rb +43 -0
  85. metadata +215 -14
  86. data/LICENSE.txt +0 -40
@@ -0,0 +1,34 @@
1
+ Description:
2
+ Set up all required files for the Super admin framework.
3
+
4
+ Options:
5
+ --controller-namespace
6
+ This specifies the directory into which generated controllers should be
7
+ placed. This also specifies the parent controller that all Super admin
8
+ pages would inherit from (see examples). Generated controllers will
9
+ automatically inherit from the controller that is specified through this
10
+ option.
11
+
12
+ --route-namespace
13
+ Since this generator only creates one inheritable parent controller,
14
+ this option only affects the generated initializer.
15
+
16
+ Example:
17
+ rails generate super:install
18
+
19
+ This will create:
20
+ config/initializers/super.rb
21
+ app/controllers/admin_controller.rb
22
+ app/controllers/admin/.keep
23
+
24
+ This will also update your Sprockets manifest as necessary.
25
+
26
+ Example:
27
+ rails generate super:install --controller-namespace badminton
28
+
29
+ This will create:
30
+ config/initializers/super.rb
31
+ app/controllers/badminton_controller.rb
32
+ app/controllers/badminton/.keep
33
+
34
+ This will also update your Sprockets manifest as necessary.
@@ -0,0 +1,46 @@
1
+ module Super
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("templates", __dir__)
4
+
5
+ class_option :controller_namespace, type: :string, default: "admin",
6
+ banner: "Specifies where to place generated admin controllers"
7
+ class_option :route_namespace, type: :string, default: "admin",
8
+ banner: "Specifies the route namespace for admin controllers"
9
+
10
+ def create_initializer
11
+ template("initializer.rb", "config/initializers/super.rb")
12
+ end
13
+
14
+ def create_base_admin_controller
15
+ template(
16
+ "base_controller.rb",
17
+ "app/controllers/#{controller_namespace}_controller.rb",
18
+ controller_namespace: controller_namespace
19
+ )
20
+ end
21
+
22
+ def create_directory_for_admin_controllers
23
+ if options["controller_namespace"].blank?
24
+ empty_directory("app/controllers")
25
+ return
26
+ end
27
+
28
+ empty_directory("app/controllers/#{controller_namespace}")
29
+ create_file("app/controllers/#{controller_namespace}/.keep", "")
30
+ end
31
+
32
+ def setup_sprockets4_manifest
33
+ append_to_file "app/assets/config/manifest.js", "//= link super_manifest.js\n"
34
+ end
35
+
36
+ private
37
+
38
+ def controller_namespace
39
+ if options["controller_namespace"].blank?
40
+ "admin"
41
+ else
42
+ options["controller_namespace"]
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,2 @@
1
+ class <%= config[:controller_namespace].classify %>Controller < Super::ApplicationController
2
+ end
@@ -0,0 +1,5 @@
1
+ Super.configuration do |c|
2
+ c.title = "My Admin Site"
3
+ c.controller_namespace = "<%= options["controller_namespace"] %>"
4
+ c.route_namespace = "<%= options["route_namespace"] %>"
5
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Creates a controller
3
+
4
+ Example:
5
+ rails generate super:resource Thing
6
+
7
+ This will create:
8
+ app/controllers/admin/things_controller.rb
@@ -0,0 +1,52 @@
1
+ module Super
2
+ class ResourceGenerator < Rails::Generators::NamedBase
3
+ source_root File.expand_path("templates", __dir__)
4
+
5
+ def create_controller
6
+ controller_subdir =
7
+ if Super.configuration.controller_namespace.present?
8
+ "#{Super.configuration.controller_namespace}/"
9
+ else
10
+ ""
11
+ end
12
+
13
+ template(
14
+ "resources_controller.rb",
15
+ "app/controllers/#{controller_subdir}#{file_path.pluralize}_controller.rb"
16
+ )
17
+ end
18
+
19
+ private
20
+
21
+ def wrap_with_configured_module(&block)
22
+ indentation_amount =
23
+ if Super.configuration.controller_namespace.present?
24
+ 2
25
+ else
26
+ 0
27
+ end
28
+
29
+ inner = capture(&block)
30
+ inner = indent(inner, indentation_amount).chomp
31
+
32
+ if Super.configuration.controller_namespace.present?
33
+ concat("module #{Super.configuration.controller_namespace.camelize}\n")
34
+ end
35
+
36
+ concat(inner)
37
+ concat("\n")
38
+
39
+ if Super.configuration.controller_namespace.present?
40
+ concat("end\n")
41
+ end
42
+ end
43
+
44
+ def parent_controller_name
45
+ if Super.configuration.controller_namespace.present?
46
+ "#{Super.configuration.controller_namespace.camelize}Controller"
47
+ else
48
+ "AdminController"
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,45 @@
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
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
43
+ end
44
+ end
45
+ <% end -%>
@@ -0,0 +1,14 @@
1
+ Description:
2
+ Creates the necessary files for assets to be served under Webpacker
3
+
4
+ Webpacker support requires ERB support. There are no other dependencies.
5
+
6
+ Installing ERB on webpacker is usually done by running the command:
7
+ `rails webpacker:install:erb`
8
+
9
+ Example:
10
+ rails webpacker:install:erb # if you hadn't set up ERB already
11
+ rails generate super:install:webpacker
12
+
13
+ This will create:
14
+ app/javascript/packs/super/application.js.erb
@@ -0,0 +1,2 @@
1
+ import Super from "<%%= Super::Assets.dist("super", "super-frontend").join("application") %>";
2
+ import "<%%= Super::Assets.dist("super", "super-frontend").join("application.css") %>";
@@ -0,0 +1,25 @@
1
+ module Super
2
+ class WebpackerGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("templates", __dir__)
4
+
5
+ def copy_the_pack_file
6
+ template(
7
+ "pack_super_application.js.erb",
8
+ "app/javascript/packs/super/application.js.erb"
9
+ )
10
+ end
11
+
12
+ def set_asset_handler_to_webpacker
13
+ insert_into_file(
14
+ "config/initializers/super.rb",
15
+ " c.asset_handler = Super::Assets.webpacker\n",
16
+ before: /\bend\b/
17
+ )
18
+ end
19
+
20
+ def remind_about_erb
21
+ say "Make sure ERB is set up for Webpacker!", :bold
22
+ say "Run if needed: rails webpacker:install:erb", :bold
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,23 @@
1
- require "super/engine"
1
+ require "active_support/concern"
2
2
 
3
- module Super
4
- # Your code goes here...
5
- end
3
+ require "super/action_inquirer"
4
+ require "super/assets"
5
+ require "super/compatibility"
6
+ require "super/configuration"
7
+ require "super/controls"
8
+ require "super/display"
9
+ require "super/display/schema_types"
10
+ require "super/engine"
11
+ require "super/error"
12
+ require "super/form/schema_types"
13
+ require "super/layout"
14
+ require "super/link"
15
+ require "super/navigation/automatic"
16
+ require "super/pagination"
17
+ require "super/panel"
18
+ require "super/partial"
19
+ require "super/plugin"
20
+ require "super/schema"
21
+ require "super/step"
22
+ require "super/version"
23
+ require "super/view_helper"
@@ -0,0 +1,101 @@
1
+ module Super
2
+ # ```ruby
3
+ # action = Super::ActionInquirer.new(
4
+ # Super::ActionInquirer.default_resources,
5
+ # :index
6
+ # )
7
+ #
8
+ # action.read? # => true
9
+ # action.index? # => true
10
+ # action.show? # => false
11
+ # action.write? # => false
12
+ # ```
13
+ class ActionInquirer
14
+ attr_reader :action
15
+
16
+ # @return [Hash<Symbol, Array<Symbol>>] default settings for initialization
17
+ #
18
+ def self.default_resources
19
+ {
20
+ read: %i[index show new edit],
21
+ write: %i[create update destroy],
22
+ delete: %i[destroy]
23
+ }
24
+ end
25
+
26
+ def initialize(categories_and_their_actions, action)
27
+ @categories = categories_and_their_actions.keys.map(&:to_s)
28
+ @actions = categories_and_their_actions.values.flatten.uniq.map(&:to_s)
29
+ @actions_categories = {}
30
+
31
+ categories_and_their_actions.each do |c, actions|
32
+ c = c.to_s
33
+
34
+ actions.each do |a|
35
+ a = a.to_s
36
+ @actions_categories[a] ||= []
37
+ @actions_categories[a].push(c)
38
+ end
39
+ end
40
+
41
+ intersection = @categories & @actions
42
+ if intersection.any?
43
+ raise Error::ActionInquirerError,
44
+ "Found shared elements between categories and actions: #{intersection.join(", ")}"
45
+ end
46
+
47
+ self.action = action
48
+ end
49
+
50
+ def action=(new_action)
51
+ new_action = new_action.to_s
52
+ if !@actions.include?(new_action)
53
+ raise Error::ActionInquirerError, "Unknown action: #{new_action}"
54
+ end
55
+
56
+ @action = new_action
57
+ end
58
+
59
+ def respond_to_missing?(method_name, *)
60
+ inquiry = parse_inquiry(method_name)
61
+
62
+ return super if !inquiry
63
+
64
+ @actions.include?(inquiry) || @categories.include?(inquiry) || super
65
+ end
66
+
67
+ def method_missing(method_name, *)
68
+ inquiry = parse_inquiry(method_name)
69
+
70
+ return super if !inquiry
71
+
72
+ if @actions.include?(inquiry)
73
+ matches_action?(inquiry)
74
+ elsif @categories.include?(inquiry)
75
+ matches_category?(inquiry)
76
+ else
77
+ super
78
+ end
79
+ end
80
+
81
+ private
82
+
83
+ def parse_inquiry(method_name)
84
+ inquiry = method_name.to_s
85
+
86
+ if inquiry[-1] != "?"
87
+ return nil
88
+ end
89
+
90
+ inquiry.chomp("?")
91
+ end
92
+
93
+ def matches_action?(inquiry)
94
+ @action == inquiry
95
+ end
96
+
97
+ def matches_category?(inquiry)
98
+ @actions_categories[@action].include?(inquiry)
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,63 @@
1
+ module Super
2
+ # Utilities for determining whether to use Sprockets or Webpacker
3
+ class Assets
4
+ def self.sprockets_available?
5
+ Gem::Dependency.new("sprockets").matching_specs.any?
6
+ end
7
+
8
+ def self.dist(gem_name, package_name)
9
+ gem_name = gem_name.to_s
10
+
11
+ @gem_paths ||= {}
12
+ @gem_paths[gem_name] ||= Pathname.new(Gem.loaded_specs[gem_name].full_gem_path).expand_path
13
+ gem_path = @gem_paths[gem_name]
14
+
15
+ gem_path.join("frontend", package_name, "dist")
16
+ end
17
+
18
+ def self.auto
19
+ @auto ||=
20
+ if Gem::Dependency.new("sprockets", "~> 4.0").matching_specs.any?
21
+ sprockets
22
+ elsif Gem::Dependency.new("sprockets", "~> 3.0").matching_specs.any?
23
+ sprockets
24
+ elsif Gem::Dependency.new("sprockets", "~> 2.0").matching_specs.any?
25
+ sprockets
26
+ elsif Gem::Dependency.new("webpacker", "~> 4.0").matching_specs.any?
27
+ webpacker
28
+ elsif Gem::Dependency.new("webpacker", "~> 3.0").matching_specs.any?
29
+ webpacker
30
+ else
31
+ none
32
+ end
33
+ end
34
+
35
+ def self.sprockets
36
+ new(:sprockets)
37
+ end
38
+
39
+ def self.webpacker
40
+ new(:webpacker)
41
+ end
42
+
43
+ def self.none
44
+ new(:none)
45
+ end
46
+
47
+ def initialize(asset_handler)
48
+ @asset_handler = asset_handler
49
+ end
50
+
51
+ def sprockets?
52
+ @asset_handler == :sprockets
53
+ end
54
+
55
+ def webpacker?
56
+ @asset_handler == :webpacker
57
+ end
58
+
59
+ def none?
60
+ @asset_handler == :none
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,13 @@
1
+ module Super
2
+ module Compatability
3
+ module_function
4
+
5
+ def rails_50_errable_fields(field)
6
+ if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR == 0
7
+ [field.to_s, field.to_sym]
8
+ else
9
+ field
10
+ end
11
+ end
12
+ end
13
+ end