super 0.0.0 → 0.0.1
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.
- checksums.yaml +4 -4
- data/LICENSE +165 -0
- data/README.md +102 -8
- data/app/assets/config/super_manifest.js +1 -0
- data/app/assets/javascripts/super/application.js +3483 -0
- data/app/assets/stylesheets/super/application.css +35265 -0
- data/app/controllers/super/application_controller.rb +84 -0
- data/app/views/layouts/super/application.html.erb +39 -0
- data/app/views/super/application/_form.html.erb +13 -0
- data/app/views/super/application/_form_field.html.erb +7 -0
- data/app/views/super/application/_form_generic_select.html.erb +19 -0
- data/app/views/super/application/_form_generic_text.html.erb +7 -0
- data/app/views/super/application/_index.html.erb +58 -0
- data/app/views/super/application/edit.html.erb +7 -0
- data/app/views/super/application/index.html.erb +1 -0
- data/app/views/super/application/new.html.erb +7 -0
- data/app/views/super/application/show.html.erb +10 -0
- data/app/views/super/feather/README.md +32 -0
- data/app/views/super/feather/_chevron_down.svg +1 -0
- data/frontend/super-frontend/build.js +34 -0
- data/frontend/super-frontend/dist/application.css +35265 -0
- data/frontend/super-frontend/dist/application.js +3483 -0
- data/frontend/super-frontend/package.json +14 -0
- data/frontend/super-frontend/postcss.config.js +6 -0
- data/frontend/super-frontend/src/javascripts/super/application.js +11 -0
- data/frontend/super-frontend/src/stylesheets/super/application.css +14 -0
- data/frontend/super-frontend/tailwind.config.js +7 -0
- data/frontend/super-frontend/yarn.lock +5355 -0
- data/lib/generators/super/install/USAGE +32 -0
- data/lib/generators/super/install/install_generator.rb +47 -0
- data/lib/generators/super/install/templates/base_controller.rb.tt +2 -0
- data/lib/generators/super/install/templates/initializer.rb.tt +5 -0
- data/lib/generators/super/resource/USAGE +9 -0
- data/lib/generators/super/resource/resource_generator.rb +54 -0
- data/lib/generators/super/resource/templates/resource_dashboard.rb.tt +65 -0
- data/lib/generators/super/resource/templates/resources_controller.rb.tt +9 -0
- data/lib/generators/super/webpacker/USAGE +14 -0
- data/lib/generators/super/webpacker/templates/pack_super_application.js.erb.tt +2 -0
- data/lib/generators/super/webpacker/webpacker_generator.rb +17 -0
- data/lib/super.rb +17 -4
- data/lib/super/assets.rb +62 -0
- data/lib/super/configuration.rb +88 -0
- data/lib/super/controls.rb +25 -0
- data/lib/super/display.rb +9 -0
- data/lib/super/display/schema_types.rb +41 -0
- data/lib/super/engine.rb +5 -0
- data/lib/super/error.rb +8 -0
- data/lib/super/form/schema_types.rb +47 -0
- data/lib/super/inline_callback.rb +82 -0
- data/lib/super/navigation/automatic.rb +69 -0
- data/lib/super/pagination.rb +59 -0
- data/lib/super/plugin.rb +89 -0
- data/lib/super/schema.rb +24 -0
- data/lib/super/test_support/fixtures/members.yml +336 -0
- data/lib/super/test_support/fixtures/ships.yml +10 -0
- data/lib/super/test_support/setup.rb +79 -0
- data/lib/super/test_support/starfleet_seeder.rb +49 -0
- data/lib/super/test_support/templates/20190216224956_create_members.rb +11 -0
- data/lib/super/test_support/templates/20190803143320_create_ships.rb +11 -0
- data/lib/super/test_support/templates/20190806014121_add_ship_to_members.rb +5 -0
- data/lib/super/test_support/templates/admin/members_controller.rb +9 -0
- data/lib/super/test_support/templates/admin/ships_controller.rb +9 -0
- data/lib/super/test_support/templates/admin_controller.rb +2 -0
- data/lib/super/test_support/templates/member.rb +16 -0
- data/lib/super/test_support/templates/member_dashboard.rb +90 -0
- data/lib/super/test_support/templates/routes.rb +10 -0
- data/lib/super/test_support/templates/seeds.rb +2 -0
- data/lib/super/test_support/templates/ship.rb +3 -0
- data/lib/super/test_support/templates/ship_dashboard.rb +79 -0
- data/lib/super/version.rb +1 -1
- data/lib/super/view.rb +25 -0
- metadata +131 -12
- data/LICENSE.txt +0 -40
@@ -0,0 +1,32 @@
|
|
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
|
+
app/super/.keep
|
24
|
+
|
25
|
+
Example:
|
26
|
+
rails generate super:install --controller-namespace badminton
|
27
|
+
|
28
|
+
This will create:
|
29
|
+
config/initializers/super.rb
|
30
|
+
app/controllers/badminton_controller.rb
|
31
|
+
app/controllers/badminton/.keep
|
32
|
+
app/super/.keep
|
@@ -0,0 +1,47 @@
|
|
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 create_directory_for_dashboards_slash_setup
|
33
|
+
empty_directory("app/super")
|
34
|
+
create_file("app/super/.keep", "")
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def controller_namespace
|
40
|
+
if options["controller_namespace"].blank?
|
41
|
+
"admin"
|
42
|
+
else
|
43
|
+
options["controller_namespace"]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,54 @@
|
|
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
|
+
|
18
|
+
template("resource_dashboard.rb", "app/super/#{file_path}_dashboard.rb")
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
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
|
30
|
+
|
31
|
+
inner = capture(&block)
|
32
|
+
inner = indent(inner, indentation_amount).chomp
|
33
|
+
|
34
|
+
if Super.configuration.controller_namespace.present?
|
35
|
+
concat("module #{Super.configuration.controller_namespace.camelize}\n")
|
36
|
+
end
|
37
|
+
|
38
|
+
concat(inner)
|
39
|
+
concat("\n")
|
40
|
+
|
41
|
+
if Super.configuration.controller_namespace.present?
|
42
|
+
concat("end\n")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def parent_controller_name
|
47
|
+
if Super.configuration.controller_namespace.present?
|
48
|
+
"#{Super.configuration.controller_namespace.camelize}Controller"
|
49
|
+
else
|
50
|
+
"AdminController"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,65 @@
|
|
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
|
@@ -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,17 @@
|
|
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 remind_about_erb
|
13
|
+
say "Make sure ERB is set up for Webpacker!", :bold
|
14
|
+
say "Run if needed: rails webpacker:install:erb", :bold
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/super.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
|
-
require "
|
1
|
+
require "tsort"
|
2
|
+
require "active_support/concern"
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
require "super/assets"
|
5
|
+
require "super/configuration"
|
6
|
+
require "super/controls"
|
7
|
+
require "super/engine"
|
8
|
+
require "super/error"
|
9
|
+
require "super/display"
|
10
|
+
require "super/display/schema_types"
|
11
|
+
require "super/form/schema_types"
|
12
|
+
require "super/inline_callback"
|
13
|
+
require "super/navigation/automatic"
|
14
|
+
require "super/pagination"
|
15
|
+
require "super/plugin"
|
16
|
+
require "super/schema"
|
17
|
+
require "super/version"
|
18
|
+
require "super/view"
|
data/lib/super/assets.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Super
|
2
|
+
class Assets
|
3
|
+
def self.sprockets_available?
|
4
|
+
Gem::Dependency.new("sprockets").matching_specs.any?
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.dist(gem_name, package_name)
|
8
|
+
gem_name = gem_name.to_s
|
9
|
+
|
10
|
+
@gem_paths ||= {}
|
11
|
+
@gem_paths[gem_name] ||= Pathname.new(Gem.loaded_specs[gem_name].full_gem_path).expand_path
|
12
|
+
gem_path = @gem_paths[gem_name]
|
13
|
+
|
14
|
+
gem_path.join("frontend", package_name, "dist")
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.auto
|
18
|
+
@auto ||=
|
19
|
+
if Gem::Dependency.new("sprockets", "~> 4.0").matching_specs.any?
|
20
|
+
sprockets
|
21
|
+
elsif Gem::Dependency.new("sprockets", "~> 3.0").matching_specs.any?
|
22
|
+
sprockets
|
23
|
+
elsif Gem::Dependency.new("sprockets", "~> 2.0").matching_specs.any?
|
24
|
+
sprockets
|
25
|
+
elsif Gem::Dependency.new("webpacker", "~> 4.0").matching_specs.any?
|
26
|
+
webpacker
|
27
|
+
elsif Gem::Dependency.new("webpacker", "~> 3.0").matching_specs.any?
|
28
|
+
webpacker
|
29
|
+
else
|
30
|
+
none
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.sprockets
|
35
|
+
new(:sprockets)
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.webpacker
|
39
|
+
new(:webpacker)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.none
|
43
|
+
new(:none)
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize(asset_handler)
|
47
|
+
@asset_handler = asset_handler
|
48
|
+
end
|
49
|
+
|
50
|
+
def sprockets?
|
51
|
+
@asset_handler == :sprockets
|
52
|
+
end
|
53
|
+
|
54
|
+
def webpacker?
|
55
|
+
@asset_handler == :webpacker
|
56
|
+
end
|
57
|
+
|
58
|
+
def none?
|
59
|
+
@asset_handler == :none
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
module Super
|
2
|
+
def self.configuration
|
3
|
+
@configuration ||= Configuration.new
|
4
|
+
|
5
|
+
if block_given?
|
6
|
+
yield(@configuration)
|
7
|
+
end
|
8
|
+
|
9
|
+
@configuration
|
10
|
+
end
|
11
|
+
|
12
|
+
module ConfigurationLogic
|
13
|
+
def self.included(base)
|
14
|
+
base.extend(ClassMethods)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
self.class.defaults.each do |key, value|
|
19
|
+
if value.respond_to?(:call)
|
20
|
+
value = value.call
|
21
|
+
end
|
22
|
+
|
23
|
+
public_send("#{key}=", value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def configured?(attr)
|
28
|
+
instance_variable_defined?("@#{attr}")
|
29
|
+
end
|
30
|
+
|
31
|
+
module ClassMethods
|
32
|
+
def defaults
|
33
|
+
@defaults ||= {}
|
34
|
+
end
|
35
|
+
|
36
|
+
def wraps
|
37
|
+
@wraps ||= {}
|
38
|
+
end
|
39
|
+
|
40
|
+
def configure(attr, wrap: nil, enum: nil, **kwargs)
|
41
|
+
if kwargs.key?(:default)
|
42
|
+
defaults[attr] = kwargs[:default]
|
43
|
+
end
|
44
|
+
|
45
|
+
define_method(attr) do
|
46
|
+
if !configured?(attr)
|
47
|
+
raise Error::UnconfiguredConfiguration, "unconfigured: #{attr}"
|
48
|
+
end
|
49
|
+
|
50
|
+
result = instance_variable_get("@#{attr}")
|
51
|
+
|
52
|
+
if wrap.nil?
|
53
|
+
result
|
54
|
+
else
|
55
|
+
wrap.call(result)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
define_method("#{attr}=") do |value|
|
60
|
+
if enum.is_a?(Array)
|
61
|
+
if !enum.include?(value)
|
62
|
+
raise Error::InvalidConfiguration,
|
63
|
+
"tried to set `#{attr}` to `#{value.inspect}`, " \
|
64
|
+
"expected: #{enum.join(", ")}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
instance_variable_set("@#{attr}", value)
|
69
|
+
value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
class Configuration
|
76
|
+
include ConfigurationLogic
|
77
|
+
|
78
|
+
configure :title
|
79
|
+
configure :index_resources_per_page, default: 20
|
80
|
+
configure :controller_namespace, default: "admin"
|
81
|
+
configure :route_namespace, default: :admin, wrap: -> (val) { [val].flatten }
|
82
|
+
configure :asset_handler, default: -> { Super::Assets.auto }
|
83
|
+
|
84
|
+
def path_parts(*parts)
|
85
|
+
route_namespace + parts
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|