trestle 0.9.8 → 0.9.9

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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +4 -2
  3. data/.gitignore +4 -0
  4. data/app/assets/bundle/trestle/bundle.css +4 -4
  5. data/app/assets/bundle/trestle/bundle.js +12 -26
  6. data/app/controllers/concerns/trestle/controller/toolbars.rb +1 -1
  7. data/app/controllers/concerns/trestle/resource/controller/actions.rb +5 -5
  8. data/app/controllers/concerns/trestle/resource/controller/redirection.rb +5 -3
  9. data/app/controllers/trestle/admin_controller.rb +4 -0
  10. data/app/helpers/trestle/card_helper.rb +2 -2
  11. data/app/helpers/trestle/navigation_helper.rb +3 -1
  12. data/app/helpers/trestle/toolbars_helper.rb +1 -1
  13. data/app/views/trestle/resource/_scopes.html.erb +1 -1
  14. data/config/locales/vi.yml +1 -1
  15. data/frontend/css/components/_toolbars.scss +1 -19
  16. data/frontend/css/core/_mixins.scss +1 -4
  17. data/frontend/css/layout/_content.scss +1 -1
  18. data/lib/trestle/adapters/active_record_adapter.rb +1 -1
  19. data/lib/trestle/admin/builder.rb +7 -0
  20. data/lib/trestle/admin.rb +12 -6
  21. data/lib/trestle/configurable.rb +2 -2
  22. data/lib/trestle/form/automatic.rb +3 -1
  23. data/lib/trestle/hook/helpers.rb +1 -1
  24. data/lib/trestle/reloader.rb +2 -11
  25. data/lib/trestle/resource/builder.rb +1 -8
  26. data/lib/trestle/resource.rb +2 -2
  27. data/lib/trestle/scopes/block.rb +7 -7
  28. data/lib/trestle/scopes/definition.rb +2 -2
  29. data/lib/trestle/scopes/scope.rb +4 -0
  30. data/lib/trestle/version.rb +1 -1
  31. data/lib/trestle.rb +4 -0
  32. data/package.json +1 -1
  33. data/trestle.gemspec +7 -7
  34. data/webpack.config.js +8 -1
  35. data/yarn.lock +1197 -2344
  36. metadata +21 -21
@@ -18,7 +18,7 @@ module Trestle
18
18
 
19
19
  toolbar = (toolbars[name.to_s] ||= Toolbar.new(builder))
20
20
  toolbar.clear! if options[:clear]
21
- toolbar.prepend(&block) if block_given?
21
+ toolbar.append(&block) if block_given?
22
22
  toolbar
23
23
  end
24
24
 
@@ -25,7 +25,7 @@ module Trestle
25
25
  respond_to do |format|
26
26
  format.html do
27
27
  flash[:message] = flash_message("create.success", title: "Success!", message: "The %{lowercase_model_name} was successfully created.")
28
- redirect_to_return_location(:create, instance, default: admin.instance_path(instance))
28
+ redirect_to_return_location(:create, instance) { admin.instance_path(instance) }
29
29
  end
30
30
  format.json { render json: instance, status: :created, location: admin.instance_path(instance) }
31
31
 
@@ -85,7 +85,7 @@ module Trestle
85
85
  respond_to do |format|
86
86
  format.html do
87
87
  flash[:message] = flash_message("update.success", title: "Success!", message: "The %{lowercase_model_name} was successfully updated.")
88
- redirect_to_return_location(:update, instance, default: admin.instance_path(instance))
88
+ redirect_to_return_location(:update, instance) { admin.instance_path(instance) }
89
89
  end
90
90
  format.json { render json: instance, status: :ok }
91
91
 
@@ -111,14 +111,14 @@ module Trestle
111
111
  format.html do
112
112
  if success
113
113
  flash[:message] = flash_message("destroy.success", title: "Success!", message: "The %{lowercase_model_name} was successfully deleted.")
114
- redirect_to_return_location(:destroy, instance, default: admin.path(:index))
114
+ redirect_to_return_location(:destroy, instance) { admin.path(:index) }
115
115
  else
116
116
  flash[:error] = flash_message("destroy.failure", title: "Warning!", message: "Could not delete %{lowercase_model_name}.")
117
117
 
118
118
  if load_instance
119
- redirect_to_return_location(:update, instance, default: admin.instance_path(instance))
119
+ redirect_to_return_location(:update, instance) { admin.instance_path(instance) }
120
120
  else
121
- redirect_to_return_location(:destroy, instance, default: admin.path(:index))
121
+ redirect_to_return_location(:destroy, instance) { admin.path(:index) }
122
122
  end
123
123
  end
124
124
  end
@@ -3,18 +3,20 @@ module Trestle
3
3
  module Controller
4
4
  module Redirection
5
5
  protected
6
- def redirect_to_return_location(action, instance, default:)
6
+ def redirect_to_return_location(action, instance, default: nil, &block)
7
+ fallback_location = block_given? ? block : default
8
+
7
9
  if admin.return_locations[action] && !dialog_request?
8
10
  location = instance_exec(instance, &admin.return_locations[action])
9
11
 
10
12
  case location
11
13
  when :back
12
- redirect_back fallback_location: default, turbolinks: false
14
+ redirect_back fallback_location: fallback_location, turbolinks: false
13
15
  else
14
16
  redirect_to location, turbolinks: false
15
17
  end
16
18
  else
17
- redirect_to default, turbolinks: false
19
+ redirect_to fallback_location, turbolinks: false
18
20
  end
19
21
  end
20
22
  end
@@ -1,4 +1,8 @@
1
1
  class Trestle::AdminController < Trestle::ApplicationController
2
+ if respond_to?(:raise_on_missing_callback_actions=)
3
+ self.raise_on_missing_callback_actions = false
4
+ end
5
+
2
6
  def index
3
7
  end
4
8
 
@@ -11,12 +11,12 @@ module Trestle
11
11
  end
12
12
 
13
13
  def panel(options={}, &block)
14
- ActiveSupport::Deprecation.warn("The panel helper is deprecated and will be removed in future versions of Trestle. Please use the card helper instead.")
14
+ Trestle.deprecator.warn("The panel helper is deprecated and will be removed in future versions of Trestle. Please use the card helper instead.")
15
15
  card(options.merge(header: options[:title]), &block)
16
16
  end
17
17
 
18
18
  def well(options={}, &block)
19
- ActiveSupport::Deprecation.warn("The well helper is deprecated and will be removed in future versions of Trestle. Please use the card helper instead.")
19
+ Trestle.deprecator.warn("The well helper is deprecated and will be removed in future versions of Trestle. Please use the card helper instead.")
20
20
  card(options, &block)
21
21
  end
22
22
  end
@@ -5,7 +5,9 @@ module Trestle
5
5
  end
6
6
 
7
7
  def current_admin?(admin)
8
- respond_to?(:admin) && self.admin && self.admin.name == admin.name
8
+ respond_to?(:admin) &&
9
+ self.admin.respond_to?(:name) &&
10
+ self.admin.name == admin.name
9
11
  end
10
12
 
11
13
  def navigation_group_collapsed?(group)
@@ -16,7 +16,7 @@ module Trestle
16
16
 
17
17
  def deprecated_toolbar(name)
18
18
  if content_for?(:"#{name}_toolbar")
19
- ActiveSupport::Deprecation.warn("Using content_for(:#{name}_toolbar) is deprecated. Please use toolbar(:#{name}) instead.")
19
+ Trestle.deprecator.warn("Using content_for(:#{name}_toolbar) is deprecated. Please use toolbar(:#{name}) instead.")
20
20
  content_for(:"#{name}_toolbar")
21
21
  end
22
22
  end
@@ -8,7 +8,7 @@
8
8
  <li>
9
9
  <%= link_to persistent_params.merge(scope: (scope unless scope.active?(params))), class: ["scope", ("active" if scope.active?(params))] do %>
10
10
  <strong><%= scope.label %></strong>
11
- (<%= number_with_delimiter(scope.count(admin.collection(params))) %>)
11
+ <% if scope.count? %>(<%= number_with_delimiter(scope.count(admin.collection(params))) %>)<% end %>
12
12
  <% end %>
13
13
  </li>
14
14
  <% end %>
@@ -42,7 +42,7 @@ vi:
42
42
  titles:
43
43
  index: "Danh sách %{pluralized_model_name}"
44
44
  new: "Tạo mới %{model_name}"
45
- edit: Chỉnh sửa %{model_name}"
45
+ edit: "Chỉnh sửa %{model_name}"
46
46
 
47
47
  buttons:
48
48
  new: "Tạo mới %{model_name}"
@@ -1,23 +1,5 @@
1
1
  .btn-toolbar {
2
- .btn,
3
- .btn-group,
4
- .input-group {
5
- + .btn,
6
- + .btn-group,
7
- + .input-group {
8
- margin-left: 5px;
9
- }
10
- }
11
-
12
- .btn-group {
13
- .btn,
14
- .btn-group {
15
- + .btn,
16
- + .btn-group {
17
- margin-left: 0;
18
- }
19
- }
20
- }
2
+ gap: 5px;
21
3
  }
22
4
 
23
5
  .primary-toolbar {
@@ -26,13 +26,10 @@
26
26
  height: 100%;
27
27
  }
28
28
 
29
- %fa {
29
+ @mixin icon-fa($content) {
30
30
  font-family: 'Font Awesome 5 Free';
31
31
  font-weight: 900;
32
- }
33
32
 
34
- @mixin icon-fa($content) {
35
- @extend %fa;
36
33
  content: fa-content($content);
37
34
  }
38
35
 
@@ -34,7 +34,7 @@
34
34
  }
35
35
 
36
36
  .btn-toolbar {
37
- justify-content: flex-end;
37
+ flex-direction: row-reverse;
38
38
  }
39
39
 
40
40
  .secondary-toolbar {
@@ -90,7 +90,7 @@ module Trestle
90
90
 
91
91
  def enum_values(column)
92
92
  model.defined_enums[column.name].map { |key, value|
93
- [value, enum_human_name(column, key)]
93
+ [key, enum_human_name(column, key)]
94
94
  }
95
95
  end
96
96
 
@@ -88,6 +88,13 @@ module Trestle
88
88
  end
89
89
  end
90
90
 
91
+ def remove_action(*actions)
92
+ actions.each do |action|
93
+ controller.remove_possible_method(action.to_sym)
94
+ @admin.actions.delete(action.to_sym)
95
+ end
96
+ end
97
+
91
98
  protected
92
99
  def normalize_table_options(name, options)
93
100
  if name.is_a?(Hash)
data/lib/trestle/admin.rb CHANGED
@@ -2,8 +2,6 @@ module Trestle
2
2
  class Admin
3
3
  require_relative "admin/builder"
4
4
 
5
- delegate :to_param, to: :class
6
-
7
5
  def initialize(context=nil)
8
6
  @context = context
9
7
  end
@@ -52,13 +50,13 @@ module Trestle
52
50
  end
53
51
 
54
52
  def breadcrumbs
55
- Breadcrumb::Trail.new(Array(Trestle.config.root_breadcrumbs) + [breadcrumb])
53
+ Breadcrumb::Trail.new(Array(Trestle.config.root_breadcrumbs) + [breadcrumb].compact)
56
54
  end
57
55
 
58
56
  def breadcrumb
59
57
  if @breadcrumb
60
58
  Breadcrumb.cast(@breadcrumb.call)
61
- else
59
+ elsif actions.include?(:index)
62
60
  default_breadcrumb
63
61
  end
64
62
  end
@@ -128,10 +126,14 @@ module Trestle
128
126
  raise NoMethodError, "#to_param called on non-resourceful admin. You may need to explicitly specify the admin."
129
127
  end
130
128
 
131
- def actions
129
+ def default_actions
132
130
  [:index]
133
131
  end
134
132
 
133
+ def actions
134
+ @actions ||= default_actions.dup
135
+ end
136
+
135
137
  def root_action
136
138
  :index
137
139
  end
@@ -145,7 +147,7 @@ module Trestle
145
147
 
146
148
  Proc.new do
147
149
  scope controller: admin.controller_namespace, path: admin.options[:path] || admin.admin_name do
148
- get "", action: "index", as: admin.route_name
150
+ get "", action: "index", as: admin.route_name if admin.actions.include?(:index)
149
151
 
150
152
  admin.additional_routes.each do |block|
151
153
  instance_exec(&block)
@@ -176,5 +178,9 @@ module Trestle
176
178
  end
177
179
  end
178
180
  end
181
+
182
+ # This delegate call is deferred until the class method is defined,
183
+ # since the method signature is different from Object#to_param.
184
+ delegate :to_param, to: :class
179
185
  end
180
186
  end
@@ -71,11 +71,11 @@ module Trestle
71
71
 
72
72
  def deprecated_option(name, message=nil)
73
73
  define_method("#{name}=") do |value|
74
- ActiveSupport::Deprecation.warn(message)
74
+ Trestle.deprecator.warn(message)
75
75
  end
76
76
 
77
77
  define_method(name) do |*args|
78
- ActiveSupport::Deprecation.warn(message)
78
+ Trestle.deprecator.warn(message)
79
79
  end
80
80
  end
81
81
  end
@@ -31,7 +31,9 @@ module Trestle
31
31
  when :datetime
32
32
  datetime_field attribute.name
33
33
  when :boolean
34
- check_box attribute.name
34
+ form_group label: false do
35
+ check_box attribute.name
36
+ end
35
37
  when :enum
36
38
  collection_radio_buttons attribute.name, attribute.options[:values] || [], :first, :last
37
39
  when :json, :jsonb
@@ -24,7 +24,7 @@ module Trestle
24
24
 
25
25
  def hook_sets
26
26
  @_hook_sets ||= [
27
- (admin.hooks if defined?(admin) && admin),
27
+ (admin.hooks if defined?(admin) && admin.respond_to?(:hooks)),
28
28
  Trestle.config.hooks
29
29
  ].compact
30
30
  end
@@ -38,17 +38,8 @@ module Trestle
38
38
 
39
39
  app.reloaders << reloader
40
40
 
41
- if app.respond_to?(:reloader)
42
- # Rails >= 5.0
43
- app.reloader.to_run do
44
- reloader.execute_if_updated
45
- true # Rails <= 5.1
46
- end
47
- else
48
- # Rails 4.2
49
- ActionDispatch::Reloader.to_prepare do
50
- reloader.execute_if_updated
51
- end
41
+ app.reloader.to_run do
42
+ reloader.execute_if_updated
52
43
  end
53
44
 
54
45
  reloader.execute
@@ -14,13 +14,6 @@ module Trestle
14
14
  admin.adapter_class = adapter
15
15
  end
16
16
 
17
- def remove_action(*actions)
18
- actions.each do |action|
19
- controller.remove_possible_method(action.to_sym)
20
- admin.actions.delete(action.to_sym)
21
- end
22
- end
23
-
24
17
  def collection(&block)
25
18
  admin.define_adapter_method(:collection, &block)
26
19
  end
@@ -85,7 +78,7 @@ module Trestle
85
78
 
86
79
  def scopes(options={}, &block)
87
80
  admin.scopes.options.merge!(options)
88
- admin.scopes.append(&block) if block_given?
81
+ admin.scopes.append(options, &block) if block_given?
89
82
  end
90
83
 
91
84
  def scope(name, scope=nil, options={}, &block)
@@ -88,8 +88,8 @@ module Trestle
88
88
  model_name.plural
89
89
  end
90
90
 
91
- def actions
92
- @actions ||= (readonly? ? READONLY_ACTIONS : RESOURCE_ACTIONS).dup
91
+ def default_actions
92
+ readonly? ? READONLY_ACTIONS : RESOURCE_ACTIONS
93
93
  end
94
94
 
95
95
  def root_action
@@ -1,16 +1,16 @@
1
1
  module Trestle
2
2
  class Scopes
3
3
  class Block
4
- attr_reader :block
4
+ attr_reader :block, :options
5
5
 
6
- def initialize(&block)
7
- @block = block
6
+ def initialize(options={}, &block)
7
+ @options, @block = options, block
8
8
  end
9
9
 
10
10
  # Evaluates the scope block within the given admin context
11
11
  # and returns an array of the scopes that were defined.
12
12
  def scopes(context)
13
- context = Evaluator.new(context)
13
+ context = Evaluator.new(context, options)
14
14
  context.instance_exec(context, &block)
15
15
  context.scopes
16
16
  end
@@ -20,8 +20,8 @@ module Trestle
20
20
 
21
21
  attr_reader :scopes
22
22
 
23
- def initialize(context=nil)
24
- @context = context
23
+ def initialize(context=nil, defaults={})
24
+ @context, @defaults = context, defaults
25
25
  @scopes = []
26
26
  end
27
27
 
@@ -31,7 +31,7 @@ module Trestle
31
31
  scope = nil
32
32
  end
33
33
 
34
- scopes << Scope.new(@context, name, options, &(scope || block))
34
+ scopes << Scope.new(@context, name, @defaults.merge(options), &(scope || block))
35
35
  end
36
36
  end
37
37
  end
@@ -8,8 +8,8 @@ module Trestle
8
8
  @options = {}
9
9
  end
10
10
 
11
- def append(&block)
12
- @blocks << Block.new(&block)
11
+ def append(options={}, &block)
12
+ @blocks << Block.new(options, &block)
13
13
  end
14
14
 
15
15
  # Evaluates each of the scope blocks within the given admin context
@@ -23,6 +23,10 @@ module Trestle
23
23
  @options[:default] == true
24
24
  end
25
25
 
26
+ def count?
27
+ @options[:count] != false
28
+ end
29
+
26
30
  def apply(collection)
27
31
  if @block
28
32
  if @block.arity == 1
@@ -1,3 +1,3 @@
1
1
  module Trestle
2
- VERSION = "0.9.8"
2
+ VERSION = "0.9.9"
3
3
  end
data/lib/trestle.rb CHANGED
@@ -85,6 +85,10 @@ module Trestle
85
85
  [locale]
86
86
  end
87
87
  end
88
+
89
+ def self.deprecator
90
+ @deprecator ||= ActiveSupport::Deprecation.new
91
+ end
88
92
  end
89
93
 
90
94
  require_relative "trestle/engine" if defined?(Rails)
data/package.json CHANGED
@@ -22,9 +22,9 @@
22
22
  "css-minimizer-webpack-plugin": "^3.0.2",
23
23
  "expose-loader": "^3.0.0",
24
24
  "mini-css-extract-plugin": "^2.0.0",
25
- "node-sass": "^7.0.1",
26
25
  "postcss": "^8.3.5",
27
26
  "postcss-loader": "^6.1.1",
27
+ "sass": "^1.76.0",
28
28
  "sass-loader": "^12.1.0",
29
29
  "webpack": "^5.42.0",
30
30
  "webpack-cli": "^4.7.2"
data/trestle.gemspec CHANGED
@@ -20,18 +20,18 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = ">= 2.2.2"
22
22
 
23
- spec.add_dependency "railties", ">= 4.2.0"
24
- spec.add_dependency "activemodel", ">= 4.2.0"
23
+ spec.add_dependency "railties", ">= 5.2.0"
24
+ spec.add_dependency "activemodel", ">= 5.2.0"
25
25
  spec.add_dependency "sprockets-rails", ">= 2.0.0"
26
26
  spec.add_dependency "kaminari", ">= 1.1.0"
27
27
 
28
- spec.add_development_dependency "rspec-rails", "~> 3.5"
29
- spec.add_development_dependency "rspec-html-matchers", "~> 0.9.2"
30
- spec.add_development_dependency "database_cleaner", "~> 1.8.3"
31
- spec.add_development_dependency "ammeter", "~> 1.1.4"
28
+ spec.add_development_dependency "rspec-rails", ">= 5.1.2"
29
+ spec.add_development_dependency "rspec-html-matchers", "~> 0.10.0"
30
+ spec.add_development_dependency "database_cleaner", "~> 2.0.2"
31
+ spec.add_development_dependency "ammeter", "~> 1.1.5"
32
32
 
33
33
  spec.add_development_dependency "bundler"
34
34
  spec.add_development_dependency "rake"
35
- spec.add_development_dependency "sqlite3", "~> 1.3.6"
35
+ spec.add_development_dependency "sqlite3"
36
36
  spec.add_development_dependency "turbolinks"
37
37
  end
data/webpack.config.js CHANGED
@@ -54,7 +54,14 @@ module.exports = {
54
54
  }
55
55
  }
56
56
  },
57
- { loader: 'sass-loader' }
57
+ {
58
+ loader: 'sass-loader',
59
+ options: {
60
+ sassOptions: {
61
+ quietDeps: true
62
+ }
63
+ }
64
+ }
58
65
  ]
59
66
  },
60
67
  {