super 0.0.8 → 0.0.13

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 (120) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +0 -7
  3. data/README.md +53 -79
  4. data/app/assets/javascripts/super/application.js +2728 -96
  5. data/app/assets/stylesheets/super/application.css +6405 -0
  6. data/app/controllers/super/application_controller.rb +19 -13
  7. data/app/helpers/super/form_builder_helper.rb +25 -0
  8. data/app/views/layouts/super/application.html.erb +11 -5
  9. data/app/views/super/application/{_super_schema_display_actions.html.erb → _display_actions.html.erb} +0 -0
  10. data/app/views/super/application/{_super_schema_display_index.html.erb → _display_index.html.erb} +5 -5
  11. data/app/views/super/application/_display_rich_text.html.erb +1 -0
  12. data/app/views/super/application/_display_show.html.erb +8 -0
  13. data/app/views/super/application/_filter.html.erb +5 -13
  14. data/app/views/super/application/_filter_type_select.html.erb +9 -19
  15. data/app/views/super/application/_filter_type_text.html.erb +7 -11
  16. data/app/views/super/application/_filter_type_timestamp.html.erb +6 -17
  17. data/app/views/super/application/_form.html.erb +15 -0
  18. data/app/views/super/application/_form_field__destroy.html.erb +1 -9
  19. data/app/views/super/application/_form_field_checkbox.html.erb +1 -0
  20. data/app/views/super/application/_form_field_flatpickr_date.html.erb +8 -0
  21. data/app/views/super/application/_form_field_flatpickr_datetime.html.erb +8 -0
  22. data/app/views/super/application/_form_field_flatpickr_time.html.erb +8 -0
  23. data/app/views/super/application/_form_field_rich_text_area.html.erb +1 -0
  24. data/app/views/super/application/_form_field_select.html.erb +1 -23
  25. data/app/views/super/application/_form_field_text.html.erb +1 -13
  26. data/app/views/super/application/{_super_layout.html.erb → _layout.html.erb} +7 -7
  27. data/app/views/super/application/{_super_pagination.html.erb → _pagination.html.erb} +1 -1
  28. data/app/views/super/application/{_super_panel.html.erb → _panel.html.erb} +2 -2
  29. data/app/views/super/application/_query.html.erb +18 -0
  30. data/app/views/super/application/_sort.html.erb +18 -0
  31. data/app/views/super/application/_sort_expression.html.erb +25 -0
  32. data/app/views/super/application/edit.html.erb +1 -0
  33. data/app/views/super/application/index.html.erb +1 -0
  34. data/app/views/super/application/new.html.erb +1 -0
  35. data/app/views/super/application/show.html.erb +1 -0
  36. data/app/views/super/feather/README.md +1 -0
  37. data/app/views/super/feather/_x.html +15 -0
  38. data/config/routes.rb +2 -0
  39. data/docs/cheat.md +8 -8
  40. data/frontend/super-frontend/dist/application.css +6405 -0
  41. data/frontend/super-frontend/dist/application.js +2728 -96
  42. data/lib/generators/super/action_text/USAGE +23 -0
  43. data/lib/generators/super/action_text/action_text_generator.rb +32 -0
  44. data/lib/generators/super/action_text/templates/pack_super_action_text.css +23 -0
  45. data/lib/generators/super/action_text/templates/pack_super_action_text.js +4 -0
  46. data/lib/generators/super/install/install_generator.rb +18 -7
  47. data/lib/generators/super/install/templates/base_controller.rb.tt +9 -1
  48. data/lib/generators/super/install/templates/initializer.rb.tt +9 -2
  49. data/lib/generators/super/resource/resource_generator.rb +107 -30
  50. data/lib/generators/super/resource/templates/resources_controller.rb.tt +3 -9
  51. data/lib/generators/super/webpacker/USAGE +5 -4
  52. data/lib/generators/super/webpacker/webpacker_generator.rb +2 -0
  53. data/lib/super.rb +7 -1
  54. data/lib/super/action_inquirer.rb +2 -0
  55. data/lib/super/assets.rb +6 -0
  56. data/lib/super/client_error.rb +2 -0
  57. data/lib/super/compatibility.rb +2 -0
  58. data/lib/super/configuration.rb +16 -24
  59. data/lib/super/controls.rb +11 -2
  60. data/lib/super/controls/optional.rb +35 -1
  61. data/lib/super/controls/steps.rb +27 -35
  62. data/lib/super/controls/view.rb +55 -0
  63. data/lib/super/display.rb +29 -13
  64. data/lib/super/display/guesser.rb +4 -0
  65. data/lib/super/display/schema_types.rb +74 -28
  66. data/lib/super/engine.rb +4 -0
  67. data/lib/super/error.rb +21 -0
  68. data/lib/super/filter.rb +2 -0
  69. data/lib/super/filter/form_object.rb +5 -8
  70. data/lib/super/filter/guesser.rb +2 -0
  71. data/lib/super/filter/operator.rb +2 -0
  72. data/lib/super/filter/schema_types.rb +2 -0
  73. data/lib/super/form.rb +3 -1
  74. data/lib/super/form/builder.rb +289 -39
  75. data/lib/super/form/guesser.rb +12 -1
  76. data/lib/super/form/inline_errors.rb +28 -0
  77. data/lib/super/form/schema_types.rb +25 -0
  78. data/lib/super/form/strong_params.rb +2 -0
  79. data/lib/super/layout.rb +3 -1
  80. data/lib/super/link.rb +7 -0
  81. data/lib/super/navigation/automatic.rb +4 -2
  82. data/lib/super/pagination.rb +3 -1
  83. data/lib/super/panel.rb +3 -1
  84. data/lib/super/partial.rb +2 -0
  85. data/lib/super/partial/resolving.rb +2 -0
  86. data/lib/super/plugin.rb +2 -0
  87. data/lib/super/query/form_object.rb +48 -0
  88. data/lib/super/schema.rb +2 -0
  89. data/lib/super/schema/common.rb +2 -0
  90. data/lib/super/schema/guesser.rb +2 -0
  91. data/lib/super/sort.rb +110 -0
  92. data/lib/super/useful/builder.rb +25 -0
  93. data/lib/super/useful/enum.rb +63 -0
  94. data/lib/super/version.rb +3 -1
  95. data/lib/super/view_helper.rb +2 -19
  96. metadata +56 -38
  97. data/CONTRIBUTING.md +0 -56
  98. data/Rakefile +0 -34
  99. data/STABILITY.md +0 -50
  100. data/app/views/super/application/_form_inline_errors.html.erb +0 -10
  101. data/app/views/super/application/_super_schema_display_show.html.erb +0 -8
  102. data/app/views/super/application/_super_schema_form.html.erb +0 -15
  103. data/docs/README.md +0 -6
  104. data/docs/faq.md +0 -44
  105. data/docs/quick_start.md +0 -45
  106. data/docs/webpacker.md +0 -17
  107. data/docs/yard_customizations.rb +0 -41
  108. data/frontend/super-frontend/build.js +0 -36
  109. data/frontend/super-frontend/package.json +0 -21
  110. data/frontend/super-frontend/postcss.config.js +0 -6
  111. data/frontend/super-frontend/src/javascripts/super/application.ts +0 -15
  112. data/frontend/super-frontend/src/javascripts/super/apply_template_controller.ts +0 -19
  113. data/frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts +0 -1
  114. data/frontend/super-frontend/src/javascripts/super/toggle_pending_destruction_controller.ts +0 -15
  115. data/frontend/super-frontend/src/stylesheets/super/application.css +0 -77
  116. data/frontend/super-frontend/tailwind.config.js +0 -15
  117. data/frontend/super-frontend/tsconfig.json +0 -13
  118. data/frontend/super-frontend/yarn.lock +0 -5448
  119. data/lib/super/controls/required.rb +0 -13
  120. data/lib/super/filter/plugin.rb +0 -47
@@ -0,0 +1,23 @@
1
+ Description:
2
+ Creates the necessary files for Super to support ActionText
3
+
4
+ Prerequisites:
5
+
6
+ * Webpacker must be installed on your Rails app
7
+ * Run: bundle exec rails webpacker:install
8
+
9
+ * ActionText must be installed on your Rails app
10
+ * Run: bundle exec rails action_text:install
11
+
12
+ Note that Super does NOT need to be configured to use Webpacker. But if you
13
+ do use Super with Webpacker, you can merge `action_text.js` into
14
+ `application.js.erb` file.
15
+
16
+ Example:
17
+ bin/rails webpacker:install # if you haven't already
18
+ bin/rails action_text:install # if you haven't already
19
+ bin/rails generate super:action_text
20
+
21
+ This will:
22
+ Create app/javascript/packs/super/action_text.js
23
+ Modify config/initializers/super.rb
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Super
4
+ class ActionTextGenerator < Rails::Generators::Base
5
+ source_root File.expand_path("templates", __dir__)
6
+
7
+ def copy_the_pack_files
8
+ template(
9
+ "pack_super_action_text.js",
10
+ "app/javascript/packs/super/action_text.js"
11
+ )
12
+ template(
13
+ "pack_super_action_text.css",
14
+ "app/javascript/packs/super/action_text.css"
15
+ )
16
+ end
17
+
18
+ def add_action_text_assets_to_config
19
+ insert_into_file(
20
+ "config/initializers/super.rb",
21
+ " c.javascripts.push(Super::Assets.webpacker(\"super/action_text\"))\n" \
22
+ " c.stylesheets.push(Super::Assets.webpacker(\"super/action_text\"))\n",
23
+ before: /\bend\b/
24
+ )
25
+ end
26
+
27
+ def remind_about_webpacker
28
+ say "Make sure Webpacker is set up on your application!", :bold
29
+ say "Run if needed: bundle exec rails webpacker:install"
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ @import "trix/dist/trix";
2
+
3
+ /* This is the SCSS that the ActionText installation generator adds, compiled to CSS */
4
+ .trix-content .attachment-gallery > action-text-attachment,
5
+ .trix-content .attachment-gallery > .attachment {
6
+ flex: 1 0 33%;
7
+ padding: 0 0.5em;
8
+ max-width: 33%; }
9
+ .trix-content .attachment-gallery.attachment-gallery--2 > action-text-attachment,
10
+ .trix-content .attachment-gallery.attachment-gallery--2 > .attachment,
11
+ .trix-content .attachment-gallery.attachment-gallery--4 > action-text-attachment,
12
+ .trix-content .attachment-gallery.attachment-gallery--4 > .attachment {
13
+ flex-basis: 50%;
14
+ max-width: 50%; }
15
+ .trix-content action-text-attachment .attachment {
16
+ padding: 0 !important;
17
+ max-width: 100% !important; }
18
+
19
+ /* This is for getting Tailwind to work with Trix */
20
+ .trix-content ul {
21
+ list-style-type: disc; }
22
+ .trix-content ol {
23
+ list-style-type: decimal; }
@@ -0,0 +1,4 @@
1
+ import * as ActiveStorage from "@rails/activestorage"
2
+ ActiveStorage.start()
3
+ require("trix")
4
+ require("@rails/actiontext")
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class InstallGenerator < Rails::Generators::Base
3
5
  source_root File.expand_path("templates", __dir__)
@@ -7,6 +9,12 @@ module Super
7
9
  class_option :route_namespace, type: :string, default: "admin",
8
10
  banner: "Specifies the route namespace for admin controllers"
9
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
+
10
18
  def create_initializer
11
19
  template("initializer.rb", "config/initializers/super.rb")
12
20
  end
@@ -14,8 +22,7 @@ module Super
14
22
  def create_base_admin_controller
15
23
  template(
16
24
  "base_controller.rb",
17
- "app/controllers/#{controller_namespace}_controller.rb",
18
- controller_namespace: controller_namespace
25
+ "app/controllers/#{parent_controller_name}_controller.rb"
19
26
  )
20
27
  end
21
28
 
@@ -51,12 +58,16 @@ module Super
51
58
 
52
59
  private
53
60
 
61
+ def route_namespace
62
+ options[:route_namespace].strip.gsub(%r{\A/+}, "").gsub(%r{/+\z}, "").strip.underscore
63
+ end
64
+
54
65
  def controller_namespace
55
- if options["controller_namespace"].blank?
56
- "admin"
57
- else
58
- options["controller_namespace"]
59
- 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"
60
71
  end
61
72
  end
62
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,52 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails/generators/resource_helpers"
4
+
1
5
  module Super
2
6
  class ResourceGenerator < Rails::Generators::NamedBase
7
+ include Rails::Generators::ResourceHelpers
3
8
  source_root File.expand_path("templates", __dir__)
4
9
 
5
- def create_controller
6
- controller_subdir =
7
- if Super.configuration.controller_namespace.present?
8
- "#{Super.configuration.controller_namespace}/"
9
- else
10
- ""
11
- 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
12
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
35
+
36
+ def create_controller
13
37
  template(
14
38
  "resources_controller.rb",
15
- "app/controllers/#{controller_subdir}#{file_path.pluralize}_controller.rb"
39
+ File.join("app/controllers", controller_class_path, "#{controller_file_name}_controller.rb")
16
40
  )
17
41
  end
18
42
 
19
- 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)
20
47
 
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
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
28
56
 
29
- inner = capture(&block)
30
- inner = indent(inner, indentation_amount).chomp
57
+ def add_admin_route
58
+ data = route_scope
31
59
 
32
- if Super.configuration.controller_namespace.present?
33
- 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
+ )
34
70
  end
71
+ end
35
72
 
36
- concat(inner)
37
- concat("\n")
73
+ private
38
74
 
39
- if Super.configuration.controller_namespace.present?
40
- concat("end\n")
41
- end
75
+ def parent_controller_name
76
+ controller_namespace.presence || "admin"
42
77
  end
43
78
 
44
- def parent_controller_name
45
- if Super.configuration.controller_namespace.present?
46
- "#{Super.configuration.controller_namespace.camelize}Controller"
47
- else
48
- "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)
49
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
50
127
  end
51
128
  end
52
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
@@ -1,14 +1,15 @@
1
1
  Description:
2
2
  Creates the necessary files for assets to be served under Webpacker
3
3
 
4
- Webpacker support requires ERB support. There are no other dependencies.
4
+ Webpacker support requires that you install ERB support for Webpacker.
5
5
 
6
6
  Installing ERB on webpacker is usually done by running the command:
7
7
  `rails webpacker:install:erb`
8
8
 
9
9
  Example:
10
10
  rails webpacker:install:erb # if you hadn't set up ERB already
11
- rails generate super:install:webpacker
11
+ rails generate super:webpacker
12
12
 
13
- This will create:
14
- app/javascript/packs/super/application.js.erb
13
+ This will:
14
+ Create app/javascript/packs/super/application.js.erb
15
+ Modify config/initializers/super.rb
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  class WebpackerGenerator < Rails::Generators::Base
3
5
  source_root File.expand_path("templates", __dir__)
data/lib/super.rb CHANGED
@@ -1,8 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "tsort"
2
4
 
3
5
  require "rails/engine"
4
6
 
5
7
  require "super/schema/common"
8
+ require "super/useful/builder"
9
+ require "super/useful/enum"
6
10
 
7
11
  require "super/action_inquirer"
8
12
  require "super/assets"
@@ -18,11 +22,11 @@ require "super/filter"
18
22
  require "super/filter/form_object"
19
23
  require "super/filter/guesser"
20
24
  require "super/filter/operator"
21
- require "super/filter/plugin"
22
25
  require "super/filter/schema_types"
23
26
  require "super/form"
24
27
  require "super/form/builder"
25
28
  require "super/form/guesser"
29
+ require "super/form/inline_errors"
26
30
  require "super/form/schema_types"
27
31
  require "super/form/strong_params"
28
32
  require "super/layout"
@@ -32,8 +36,10 @@ require "super/pagination"
32
36
  require "super/panel"
33
37
  require "super/partial"
34
38
  require "super/plugin"
39
+ require "super/query/form_object"
35
40
  require "super/schema"
36
41
  require "super/schema/guesser"
42
+ require "super/sort"
37
43
  require "super/version"
38
44
  require "super/view_helper"
39
45
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # ```ruby
3
5
  # action = Super::ActionInquirer.new(
data/lib/super/assets.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # Utilities for determining whether to use Sprockets or Webpacker
3
5
  class Assets
@@ -80,6 +82,10 @@ module Super
80
82
  sprockets
81
83
  elsif Gem::Dependency.new("sprockets", "~> 2.0").matching_specs.any?
82
84
  sprockets
85
+ elsif Gem::Dependency.new("webpacker", "~> 6.0").matching_specs.any?
86
+ webpacker
87
+ elsif Gem::Dependency.new("webpacker", "~> 5.0").matching_specs.any?
88
+ webpacker
83
89
  elsif Gem::Dependency.new("webpacker", "~> 4.0").matching_specs.any?
84
90
  webpacker
85
91
  elsif Gem::Dependency.new("webpacker", "~> 3.0").matching_specs.any?
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  # A container class for all user-facing (4xx) errors thrown by this library.
3
5
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Super
2
4
  module Compatability
3
5
  module_function