super 0.0.2 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +11 -0
  3. data/README.md +68 -76
  4. data/app/assets/javascripts/super/application.js +1252 -316
  5. data/app/assets/stylesheets/super/application.css +102704 -17321
  6. data/app/controllers/super/application_controller.rb +49 -71
  7. data/app/views/layouts/super/application.html.erb +10 -8
  8. data/app/views/super/application/_collection_header.html.erb +15 -0
  9. data/app/views/super/application/_filter.html.erb +14 -0
  10. data/app/views/super/application/_filter_type_select.html.erb +31 -0
  11. data/app/views/super/application/_filter_type_text.html.erb +22 -0
  12. data/app/views/super/application/_filter_type_timestamp.html.erb +35 -0
  13. data/app/views/super/application/_flash.html.erb +13 -13
  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/_member_header.html.erb +16 -0
  22. data/app/views/super/application/_super_layout.html.erb +29 -0
  23. data/app/views/super/application/_super_pagination.html.erb +16 -0
  24. data/app/views/super/application/_super_panel.html.erb +7 -0
  25. data/app/views/super/application/_super_schema_display_actions.html.erb +5 -0
  26. data/app/views/super/application/_super_schema_display_index.html.erb +24 -0
  27. data/app/views/super/application/_super_schema_display_show.html.erb +8 -0
  28. data/app/views/super/application/_super_schema_form.html.erb +15 -0
  29. data/app/views/super/application/edit.html.erb +1 -6
  30. data/app/views/super/application/index.html.erb +1 -1
  31. data/app/views/super/application/new.html.erb +1 -6
  32. data/app/views/super/application/show.html.erb +1 -1
  33. data/app/views/super/feather/{_chevron_down.svg → _chevron_down.html} +0 -0
  34. data/config/locales/en.yml +5 -0
  35. data/docs/README.md +6 -0
  36. data/docs/cheat.md +41 -0
  37. data/docs/faq.md +44 -0
  38. data/docs/quick_start.md +45 -0
  39. data/docs/webpacker.md +17 -0
  40. data/docs/yard_customizations.rb +41 -0
  41. data/frontend/super-frontend/build.js +14 -12
  42. data/frontend/super-frontend/dist/application.css +102704 -17321
  43. data/frontend/super-frontend/dist/application.js +1252 -316
  44. data/frontend/super-frontend/package.json +11 -4
  45. data/frontend/super-frontend/postcss.config.js +4 -4
  46. data/frontend/super-frontend/src/javascripts/super/application.ts +18 -0
  47. data/frontend/super-frontend/src/javascripts/super/apply_template_controller.ts +19 -0
  48. data/frontend/super-frontend/src/javascripts/super/rails__ujs.d.ts +1 -0
  49. data/frontend/super-frontend/src/javascripts/super/toggle_pending_destruction_controller.ts +15 -0
  50. data/frontend/super-frontend/src/stylesheets/super/application.css +63 -0
  51. data/frontend/super-frontend/tailwind.config.js +12 -4
  52. data/frontend/super-frontend/tsconfig.json +13 -0
  53. data/frontend/super-frontend/yarn.lock +1891 -1798
  54. data/lib/generators/super/install/install_generator.rb +16 -0
  55. data/lib/generators/super/webpacker/webpacker_generator.rb +8 -0
  56. data/lib/super.rb +16 -6
  57. data/lib/super/action_inquirer.rb +14 -1
  58. data/lib/super/assets.rb +1 -0
  59. data/lib/super/client_error.rb +43 -0
  60. data/lib/super/compatibility.rb +25 -0
  61. data/lib/super/configuration.rb +66 -44
  62. data/lib/super/controls.rb +26 -15
  63. data/lib/super/controls/optional.rb +54 -0
  64. data/lib/super/controls/required.rb +41 -0
  65. data/lib/super/controls/steps.rb +128 -0
  66. data/lib/super/display/schema_types.rb +90 -18
  67. data/lib/super/engine.rb +7 -0
  68. data/lib/super/error.rb +9 -8
  69. data/lib/super/filter.rb +137 -0
  70. data/lib/super/filter/operator.rb +103 -0
  71. data/lib/super/filter/schema_types.rb +118 -0
  72. data/lib/super/form.rb +48 -0
  73. data/lib/super/form/schema_types.rb +96 -21
  74. data/lib/super/layout.rb +47 -0
  75. data/lib/super/link.rb +110 -0
  76. data/lib/super/navigation/automatic.rb +2 -0
  77. data/lib/super/pagination.rb +80 -8
  78. data/lib/super/panel.rb +30 -0
  79. data/lib/super/partial.rb +23 -0
  80. data/lib/super/partial/resolving.rb +24 -0
  81. data/lib/super/plugin.rb +34 -63
  82. data/lib/super/schema.rb +65 -1
  83. data/lib/super/version.rb +1 -1
  84. data/lib/super/view_helper.rb +43 -0
  85. metadata +132 -33
  86. data/app/views/super/application/_form.html.erb +0 -15
  87. data/app/views/super/application/_form_field.html.erb +0 -7
  88. data/app/views/super/application/_form_generic_select.html.erb +0 -19
  89. data/app/views/super/application/_form_generic_text.html.erb +0 -7
  90. data/app/views/super/application/_index.html.erb +0 -60
  91. data/app/views/super/application/_show.html.erb +0 -12
  92. data/frontend/super-frontend/src/javascripts/super/application.js +0 -11
  93. data/lib/super/display.rb +0 -9
  94. data/lib/super/inline_callback.rb +0 -82
  95. data/lib/super/test_support/copy_app_templates/20190216224956_create_members.rb +0 -11
  96. data/lib/super/test_support/copy_app_templates/20190803143320_create_ships.rb +0 -11
  97. data/lib/super/test_support/copy_app_templates/20190806014121_add_ship_to_members.rb +0 -5
  98. data/lib/super/test_support/copy_app_templates/member.rb +0 -16
  99. data/lib/super/test_support/copy_app_templates/members_controller.rb +0 -52
  100. data/lib/super/test_support/copy_app_templates/routes.rb +0 -10
  101. data/lib/super/test_support/copy_app_templates/seeds.rb +0 -2
  102. data/lib/super/test_support/copy_app_templates/ship.rb +0 -3
  103. data/lib/super/test_support/copy_app_templates/ships_controller.rb +0 -47
  104. data/lib/super/test_support/fixtures/members.yml +0 -336
  105. data/lib/super/test_support/fixtures/ships.yml +0 -10
  106. data/lib/super/test_support/generate_copy_app.rb +0 -52
  107. data/lib/super/test_support/generate_dummy.rb +0 -94
  108. data/lib/super/test_support/starfleet_seeder.rb +0 -49
  109. data/lib/super/view.rb +0 -25
  110. data/lib/tasks/super_tasks.rake +0 -4
@@ -1,5 +1,7 @@
1
1
  module Super
2
2
  class Navigation
3
+ # Traverses the defined Rails Routes and attempts to build a list of links.
4
+ # This is used for building the nav bar on each admin page.
3
5
  class Automatic
4
6
  def initialize(route_namespace:)
5
7
  route_namespace = route_namespace.to_s
@@ -29,19 +29,15 @@ module Super
29
29
  end
30
30
  end
31
31
 
32
+ def necessary?
33
+ pages > 1
34
+ end
35
+
32
36
  def each
33
37
  if !block_given?
34
38
  return enum_for(:each)
35
39
  end
36
40
 
37
- quotient, remainder = @total_count.divmod(@limit)
38
- pages =
39
- if remainder.zero?
40
- quotient
41
- else
42
- quotient + 1
43
- end
44
-
45
41
  (1..pages).each do |pageno|
46
42
  is_current_page = pageno == current_pageno
47
43
  display = pageno.to_s
@@ -55,5 +51,81 @@ module Super
55
51
  yield(page_query_params, is_current_page, display)
56
52
  end
57
53
  end
54
+
55
+ def to_partial_path
56
+ "super_pagination"
57
+ end
58
+
59
+ private
60
+
61
+ def pages
62
+ @pages ||=
63
+ begin
64
+ quotient, remainder = @total_count.divmod(@limit)
65
+
66
+ if remainder.zero?
67
+ quotient
68
+ else
69
+ quotient + 1
70
+ end
71
+ end
72
+ end
73
+
74
+ module ControllerMethods
75
+ def index
76
+ super
77
+ @pagination = controls.initialize_pagination(action: action_inquirer, records: @records, query_params: request.GET)
78
+ @records = controls.paginate_records(action: action_inquirer, records: @records, pagination: @pagination)
79
+ @view.mains.first.parts.push(:@pagination)
80
+ end
81
+ end
82
+ end
83
+
84
+ class Controls
85
+ module Optional
86
+ # Specifies how many records to show per page
87
+ #
88
+ # @param action [ActionInquirer]
89
+ # @param query_params [Hash]
90
+ # @return [ActiveRecord::Relation]
91
+ def records_per_page(action:, query_params:)
92
+ default_for(:records_per_page, action: action, query_params: query_params) do
93
+ Super.configuration.index_records_per_page
94
+ end
95
+ end
96
+ end
97
+
98
+ module Steps
99
+ # Sets up pagination
100
+ #
101
+ # @param action [ActionInquirer]
102
+ # @param records [ActiveRecord::Relation]
103
+ # @param query_params [Hash]
104
+ # @return [Pagination]
105
+ def initialize_pagination(action:, records:, query_params:)
106
+ default_for(:initialize_pagination, action: action, records: records, query_params: query_params) do
107
+ Pagination.new(
108
+ total_count: records.size,
109
+ limit: records_per_page(action: action, query_params: query_params),
110
+ query_params: query_params,
111
+ page_query_param: :page
112
+ )
113
+ end
114
+ end
115
+
116
+ # Paginates
117
+ #
118
+ # @param action [ActionInquirer]
119
+ # @param records [ActiveRecord::Relation]
120
+ # @param pagination [Pagination]
121
+ # @return [ActiveRecord::Relation]
122
+ def paginate_records(action:, records:, pagination:)
123
+ default_for(:paginate_records, action: action, records: records, pagination: pagination) do
124
+ records
125
+ .limit(pagination.limit)
126
+ .offset(pagination.offset)
127
+ end
128
+ end
129
+ end
58
130
  end
59
131
  end
@@ -0,0 +1,30 @@
1
+ require "super/partial/resolving"
2
+
3
+ module Super
4
+ class Panel
5
+ include Super::Partial::Resolving
6
+
7
+ def initialize(*parts)
8
+ if block_given?
9
+ @parts = Array.new(yield)
10
+ end
11
+
12
+ @parts = parts
13
+ end
14
+
15
+ attr_reader :parts
16
+
17
+ def resolve(template, block)
18
+ @resolved_parts ||= resolve_for_rendering(template, parts, block)
19
+ self
20
+ end
21
+
22
+ def resolved_parts
23
+ @resolved_parts || []
24
+ end
25
+
26
+ def to_partial_path
27
+ "super_panel"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,23 @@
1
+ module Super
2
+ class Partial
3
+ def self.render(partialish, template:)
4
+ if partialish.respond_to?(:to_partial_path)
5
+ if partialish.respond_to?(:locals)
6
+ template.render(partialish, partialish.locals)
7
+ else
8
+ template.render(partialish)
9
+ end
10
+ else
11
+ partialish
12
+ end
13
+ end
14
+
15
+ def initialize(path, locals: {})
16
+ @to_partial_path = path
17
+ @locals = locals
18
+ end
19
+
20
+ attr_reader :to_partial_path
21
+ attr_reader :locals
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ module Super
2
+ class Partial
3
+ module Resolving
4
+ module_function
5
+
6
+ def resolve_for_rendering(template, partials, block)
7
+ if block
8
+ partials = [block.call, *parts]
9
+ end
10
+
11
+ partials =
12
+ partials.map do |partial|
13
+ if partial.is_a?(Symbol)
14
+ template.instance_variable_get(partial)
15
+ else
16
+ partial
17
+ end
18
+ end
19
+
20
+ partials.compact
21
+ end
22
+ end
23
+ end
24
+ end
@@ -1,88 +1,59 @@
1
1
  module Super
2
- class Pluggable < Module
3
- def initialize(registry_name)
4
- @registry_name = registry_name
5
- end
6
-
7
- def included(base)
8
- super
9
-
10
- PluginRegistry.base_set(@registry_name, base)
11
-
12
- plugins = PluginRegistry.plugins_for(@registry_name)
13
-
14
- plugins.each do |klass, method_name|
15
- base.public_send(method_name, klass)
2
+ module Plugin
3
+ class Registry
4
+ class << self
5
+ def controller
6
+ @controller ||= Registry.new
7
+ end
16
8
  end
17
- end
18
- end
19
9
 
20
- class PluginRegistry
21
- class << self
22
- def include_to(name, klass)
23
- plugin_push(name.to_sym, :include, klass)
10
+ def initialize
11
+ @registry = {}
12
+ @ordering = Hash.new { |hash, key| hash[key] = [] }
24
13
  end
25
14
 
26
- def prepend_to(name, klass)
27
- plugin_push(name.to_sym, :prepend, klass)
15
+ def use(include: nil, prepend: nil)
16
+ register(include: include, prepend: prepend, before: [], after: [])
28
17
  end
29
18
 
30
- def plugins_for(name)
31
- name = name.to_sym
32
-
33
- plugins.fetch(name) { {} }
19
+ def insert_before(*before, include: nil, prepend: nil)
20
+ register(include: include, prepend: prepend, before: before, after: [])
34
21
  end
35
22
 
36
- def base_set(name, klass)
37
- name = name.to_sym
38
-
39
- if !klass.kind_of?(Class)
40
- raise Error::InvalidPluginArgument,
41
- "Received `#{klass}` which must be a class"
42
- end
43
-
44
- bases[name] = klass
45
-
46
- true
23
+ def insert_after(*after, include: nil, prepend: nil)
24
+ register(include: include, prepend: prepend, before: [], after: after)
47
25
  end
48
26
 
49
- def base_get(name)
50
- name = name.to_sym
27
+ def classes_ordered
28
+ each_node = -> (&b) { @ordering.each_key(&b) }
29
+ each_child = -> (cb, &b) { @ordering[cb].each(&b) }
51
30
 
52
- bases[name]
31
+ TSort.tsort(each_node, each_child)
53
32
  end
54
33
 
55
- private
56
-
57
- def plugin_push(name, method_name, klass)
58
- if ![:include, :prepend].include?(method_name)
59
- raise Error::InvalidPluginArgument,
60
- "Received `#{method_name.inspect}`, must be either :include or :prepend"
34
+ def ordered
35
+ classes_ordered.each do |class_name|
36
+ yield class_name, @registry[class_name]
61
37
  end
38
+ end
62
39
 
63
- if !klass.kind_of?(Module)
64
- raise Error::InvalidPluginArgument,
65
- "Received `#{klass}` which must be a module"
66
- end
40
+ private
67
41
 
68
- plugins[name] ||= {}
69
- plugins[name][klass] = method_name
42
+ def register(include:, prepend:, before: [], after: [])
43
+ raise Error::InvalidPluginArgument, "only one of :include or :prepend can be filled out" if include && prepend
44
+ raise Error::InvalidPluginArgument, "at least one of :include or :prepend must be filled out" if include.nil? && prepend.nil?
70
45
 
71
- base = base_get(name)
46
+ klass = include || prepend
47
+ @registry[klass] = :include if include
48
+ @registry[klass] = :prepend if prepend
72
49
 
73
- if base
74
- base.public_send(method_name, klass)
50
+ before.each do |b|
51
+ @ordering[b].push(klass)
75
52
  end
76
53
 
77
- true
78
- end
79
-
80
- def plugins
81
- @plugins ||= {}
82
- end
54
+ @ordering[klass].push(*after)
83
55
 
84
- def bases
85
- @bases ||= {}
56
+ nil
86
57
  end
87
58
  end
88
59
  end
@@ -8,17 +8,81 @@ module Super
8
8
  # @param schema_type [Display::SchemaTypes, Form::SchemaTypes]
9
9
  def initialize(schema_type)
10
10
  @schema_type = schema_type
11
- @fields = {}
11
+ @fields = Fields.new
12
+
13
+ @schema_type.before_yield(fields: @fields)
12
14
 
13
15
  if block_given?
14
16
  yield(@fields, @schema_type)
15
17
  end
18
+
19
+ @schema_type.after_yield
16
20
  end
17
21
 
18
22
  attr_reader :fields
23
+ attr_reader :schema_type
19
24
 
20
25
  def field_keys
21
26
  fields.keys
22
27
  end
28
+
29
+ def to_partial_path
30
+ @schema_type.to_partial_path
31
+ end
32
+
33
+ # This class can be thought of as a Hash, where the keys usually refer to
34
+ # the model's column name and the value refers to the column type. Note
35
+ # though that this isn't always the case—different `SchemaTypes` can do
36
+ # whatever makes sense in their context
37
+ class Fields
38
+ include Enumerable
39
+
40
+ def initialize
41
+ @backing = {}
42
+ end
43
+
44
+ def [](key)
45
+ @backing[key]
46
+ end
47
+
48
+ def []=(key, value)
49
+ @backing[key] = value
50
+ end
51
+
52
+ def keys
53
+ @backing.keys
54
+ end
55
+
56
+ def values
57
+ @backing.values
58
+ end
59
+
60
+ def each(&block)
61
+ if block_given?
62
+ return @backing.each(&block)
63
+ end
64
+
65
+ enum_for(:each)
66
+ end
67
+
68
+ def replace(other)
69
+ @backing = other
70
+ end
71
+
72
+ def to_h
73
+ @backing
74
+ end
75
+
76
+ def nested
77
+ outside = @backing
78
+ inside = {}
79
+ @backing = inside
80
+ yield
81
+ return inside
82
+ ensure
83
+ @backing = outside
84
+ inside
85
+ end
86
+ end
23
87
  end
24
88
  end
@@ -1,3 +1,3 @@
1
1
  module Super
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -0,0 +1,43 @@
1
+ module Super
2
+ module ViewHelper
3
+ module_function
4
+
5
+ # For example, calling `classes("always", ["sometimes", condition])` would
6
+ # return the string "always sometimes" or "always"
7
+ def classes(*list)
8
+ result = list.map do |c|
9
+ case c
10
+ when String
11
+ c
12
+ when Array
13
+ if c.size != 2
14
+ raise %(Expected exactly two elements (["class", some_condition]), got: #{c.inspect})
15
+ end
16
+
17
+ c.first if c.last
18
+ end
19
+ end
20
+
21
+ result.compact.join(" ")
22
+ end
23
+
24
+ def errors_accounting_for_reflections(model_instance, column_or_association)
25
+ errable_fields(model_instance, column_or_association)
26
+ .flat_map { |field| Compatability.errable_fields(field) }
27
+ .flat_map { |field| model_instance.errors.full_messages_for(field) }
28
+ .uniq
29
+ end
30
+
31
+ def errable_fields(model_instance, column_or_association)
32
+ column_or_association = column_or_association.to_s
33
+ reflection = model_instance.class.reflect_on_association(column_or_association)
34
+ reflection ||= model_instance.class.reflections.values.find { |r| r.foreign_key == column_or_association }
35
+
36
+ if reflection
37
+ [reflection.name.to_s, reflection.foreign_key.to_s]
38
+ else
39
+ [column_or_association]
40
+ end
41
+ end
42
+ end
43
+ end