trestle 0.10.0.pre2 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/rspec.yml +4 -0
  3. data/Gemfile +2 -2
  4. data/README.md +1 -1
  5. data/app/assets/bundle/trestle/admin.css +9 -9
  6. data/app/assets/bundle/trestle/admin.js +13 -13
  7. data/app/assets/bundle/trestle/fa-brands-400.ttf +0 -0
  8. data/app/assets/bundle/trestle/fa-brands-400.woff2 +0 -0
  9. data/app/assets/bundle/trestle/fa-regular-400.ttf +0 -0
  10. data/app/assets/bundle/trestle/fa-regular-400.woff2 +0 -0
  11. data/app/assets/bundle/trestle/fa-solid-900.ttf +0 -0
  12. data/app/assets/bundle/trestle/fa-solid-900.woff2 +0 -0
  13. data/app/assets/bundle/trestle/photoswipe-2d522a3abaa59f8a8f73.digested.js +6 -0
  14. data/app/assets/sprockets/trestle/icons/font-awesome.css.erb +1 -1
  15. data/app/controllers/concerns/trestle/controller/modal.rb +3 -1
  16. data/app/helpers/trestle/avatar_helper.rb +20 -14
  17. data/app/helpers/trestle/card_helper.rb +27 -9
  18. data/app/helpers/trestle/container_helper.rb +37 -6
  19. data/app/helpers/trestle/display_helper.rb +11 -0
  20. data/app/helpers/trestle/flash_helper.rb +1 -10
  21. data/app/helpers/trestle/form_helper.rb +32 -18
  22. data/app/helpers/trestle/format_helper.rb +47 -17
  23. data/app/helpers/trestle/gravatar_helper.rb +48 -0
  24. data/app/helpers/trestle/grid_helper.rb +12 -14
  25. data/app/helpers/trestle/headings_helper.rb +2 -23
  26. data/app/helpers/trestle/i18n_helper.rb +1 -0
  27. data/app/helpers/trestle/icon_helper.rb +16 -3
  28. data/app/helpers/trestle/layout_helper.rb +1 -0
  29. data/app/helpers/trestle/modal_helper.rb +21 -2
  30. data/app/helpers/trestle/navigation_helper.rb +1 -0
  31. data/app/helpers/trestle/pagination_helper.rb +1 -0
  32. data/app/helpers/trestle/params_helper.rb +32 -0
  33. data/app/helpers/trestle/sort_helper.rb +38 -7
  34. data/app/helpers/trestle/status_helper.rb +19 -3
  35. data/app/helpers/trestle/tab_helper.rb +42 -7
  36. data/app/helpers/trestle/table_helper.rb +23 -23
  37. data/app/helpers/trestle/timestamp_helper.rb +18 -25
  38. data/app/helpers/trestle/title_helper.rb +2 -0
  39. data/app/helpers/trestle/toolbars_helper.rb +2 -1
  40. data/app/helpers/trestle/turbo/frame_helper.rb +25 -14
  41. data/app/helpers/trestle/url_helper.rb +124 -54
  42. data/app/views/kaminari/trestle/_first_page.html.erb +1 -2
  43. data/app/views/kaminari/trestle/_gap.html.erb +0 -1
  44. data/app/views/kaminari/trestle/_last_page.html.erb +1 -2
  45. data/app/views/kaminari/trestle/_page.html.erb +1 -2
  46. data/app/views/kaminari/trestle/_paginator.html.erb +0 -1
  47. data/app/views/layouts/trestle/admin.html.erb +3 -3
  48. data/app/views/layouts/trestle/modal.html.erb +2 -2
  49. data/app/views/trestle/application/_layout.html.erb +22 -18
  50. data/app/views/trestle/application/_tabs.html.erb +1 -1
  51. data/app/views/trestle/flash/_alert.html.erb +3 -1
  52. data/app/views/trestle/flash/_flash.html.erb +7 -4
  53. data/app/views/trestle/resource/_scopes.html.erb +3 -3
  54. data/app/views/trestle/resource/create.turbo_stream.erb +1 -0
  55. data/app/views/trestle/resource/destroy.turbo_stream.erb +2 -0
  56. data/app/views/trestle/resource/index.html.erb +10 -12
  57. data/app/views/trestle/resource/update.turbo_stream.erb +1 -0
  58. data/app/views/trestle/shared/_sidebar.html.erb +8 -8
  59. data/app/views/trestle/table/_table.html.erb +2 -2
  60. data/config/locales/pt-BR.yml +13 -13
  61. data/frontend/css/components/_scopes.scss +6 -7
  62. data/frontend/css/core/_theme.scss +3 -3
  63. data/frontend/css/layout/_sidebar.scss +9 -5
  64. data/frontend/css/variables/_trestle.scss +3 -0
  65. data/frontend/js/controllers/confirm_delete_controller.js +4 -4
  66. data/frontend/js/controllers/flatpickr_controller.js +2 -2
  67. data/frontend/js/controllers/gallery_controller.js +2 -0
  68. data/frontend/js/controllers/lightbox_controller.js +3 -5
  69. data/frontend/js/controllers/modal_trigger_controller.js +2 -2
  70. data/frontend/js/controllers/sidebar_controller.js +13 -3
  71. data/frontend/js/controllers/tab_errors_controller.js +2 -2
  72. data/frontend/js/core/backdrop.js +30 -28
  73. data/frontend/js/core/error_modal.js +7 -9
  74. data/frontend/js/core/fetch.js +2 -0
  75. data/lib/trestle/admin.rb +9 -2
  76. data/lib/trestle/configuration.rb +3 -0
  77. data/lib/trestle/engine.rb +1 -1
  78. data/lib/trestle/evaluation_context.rb +2 -4
  79. data/lib/trestle/form/automatic.rb +1 -1
  80. data/lib/trestle/form/field.rb +1 -1
  81. data/lib/trestle/form/fields/check_box.rb +1 -1
  82. data/lib/trestle/form/fields/collection_check_boxes.rb +1 -1
  83. data/lib/trestle/form/fields/collection_radio_buttons.rb +1 -1
  84. data/lib/trestle/form/fields/date_select.rb +1 -1
  85. data/lib/trestle/form/fields/datetime_select.rb +1 -1
  86. data/lib/trestle/form/fields/form_control.rb +2 -2
  87. data/lib/trestle/form/fields/form_group.rb +4 -4
  88. data/lib/trestle/form/fields/radio_button.rb +1 -1
  89. data/lib/trestle/form/fields/static_field.rb +1 -1
  90. data/lib/trestle/form/fields/time_select.rb +1 -1
  91. data/lib/trestle/form/renderer.rb +3 -5
  92. data/lib/trestle/hook/helpers.rb +21 -0
  93. data/lib/trestle/navigation/block.rb +8 -15
  94. data/lib/trestle/navigation/group.rb +2 -2
  95. data/lib/trestle/navigation/item.rb +21 -4
  96. data/lib/trestle/registry.rb +14 -11
  97. data/lib/trestle/resource/builder.rb +9 -6
  98. data/lib/trestle/resource/toolbar.rb +5 -5
  99. data/lib/trestle/resource.rb +7 -5
  100. data/lib/trestle/scopes/block.rb +8 -12
  101. data/lib/trestle/scopes/definition.rb +6 -2
  102. data/lib/trestle/scopes/scope.rb +13 -10
  103. data/lib/trestle/tab.rb +2 -2
  104. data/lib/trestle/table/column.rb +4 -3
  105. data/lib/trestle/table/row.rb +1 -1
  106. data/lib/trestle/toolbar/builder.rb +6 -6
  107. data/lib/trestle/toolbar/context.rb +2 -4
  108. data/lib/trestle/toolbar/item.rb +10 -19
  109. data/lib/trestle/toolbar/menu.rb +9 -9
  110. data/lib/trestle/version.rb +1 -1
  111. data/lib/trestle.rb +2 -2
  112. data/package.json +7 -7
  113. data/trestle.gemspec +1 -1
  114. data/yarn.lock +751 -796
  115. metadata +7 -7
  116. data/app/assets/bundle/trestle/photoswipe-7aa1aec9c3c1fd65c382.digested.js +0 -6
  117. data/app/views/layouts/trestle/admin.turbo_stream.erb +0 -4
@@ -1,6 +1,25 @@
1
1
  module Trestle
2
2
  class Hook
3
3
  module Helpers
4
+ # Evaluates any defined hooks with the given name and returns the result.
5
+ #
6
+ # Each hook is evaluated and passed any provided arguments, and the result
7
+ # is concatenated together. If no hooks are defined, and a block is passed
8
+ # to this helper, then the block will be evaluated instead.
9
+ #
10
+ # name - Name of hook to evaluate
11
+ # args - Arguments to pass to hook blocks
12
+ # block - Optional block to evaluate as a fallback if no hooks are defined
13
+ #
14
+ # Examples
15
+ #
16
+ # <%= hook("index.toolbar.primary", toolbar) %>
17
+ #
18
+ # <%= hook("view.title") do %>
19
+ # Default Title
20
+ # <% end %>
21
+ #
22
+ # Returns a HTML-safe string.
4
23
  def hook(name, *args, &block)
5
24
  hooks = hooks(name)
6
25
 
@@ -13,6 +32,8 @@ module Trestle
13
32
  end
14
33
  end
15
34
 
35
+ # Returns true or false depending on whether there are any defined hooks
36
+ # (either on the current admin or globally) with the given name.
16
37
  def hook?(name)
17
38
  hooks(name).any?
18
39
  end
@@ -17,6 +17,8 @@ module Trestle
17
17
  class Evaluator
18
18
  include EvaluationContext
19
19
 
20
+ delegate :path, to: :@admin
21
+
20
22
  attr_reader :items
21
23
 
22
24
  def initialize(admin=nil, context=nil)
@@ -24,30 +26,21 @@ module Trestle
24
26
  @items = []
25
27
  end
26
28
 
27
- def default_path
28
- @admin ? @admin.path : nil
29
- end
30
-
31
- def item(name, path=nil, options={})
32
- if path.is_a?(Hash)
33
- options = path
34
- path = nil
35
- end
36
-
29
+ def item(name, path=nil, **options)
37
30
  if options[:group]
38
31
  group = Group.new(options[:group])
39
32
  elsif @current_group
40
33
  group = @current_group
41
34
  end
42
35
 
43
- options = options.merge(group: group) if group
44
- options = options.merge(admin: @admin) if @admin
36
+ options.merge!(group: group) if group
37
+ options.merge!(admin: @admin) if @admin
45
38
 
46
- items << Item.new(name, path || default_path, options)
39
+ items << Item.new(name, path, **options)
47
40
  end
48
41
 
49
- def group(name, options={})
50
- @current_group = Group.new(name, options)
42
+ def group(name, **options)
43
+ @current_group = Group.new(name, **options)
51
44
  yield
52
45
  ensure
53
46
  @current_group = nil
@@ -3,7 +3,7 @@ module Trestle
3
3
  class Group
4
4
  attr_reader :name, :options
5
5
 
6
- def initialize(name, options={})
6
+ def initialize(name, **options)
7
7
  @name, @options = name.to_s, options
8
8
  end
9
9
 
@@ -26,7 +26,7 @@ module Trestle
26
26
  end
27
27
 
28
28
  def merge(other)
29
- self.class.new(name, options.merge(other.options))
29
+ self.class.new(name, **options.merge(other.options))
30
30
  end
31
31
 
32
32
  def priority
@@ -1,9 +1,9 @@
1
1
  module Trestle
2
2
  class Navigation
3
3
  class Item
4
- attr_reader :name, :path, :options
4
+ attr_reader :name, :options
5
5
 
6
- def initialize(name, path=nil, options={})
6
+ def initialize(name, path=nil, **options)
7
7
  @name, @path, @options = name.to_s, path, options
8
8
  end
9
9
 
@@ -35,8 +35,25 @@ module Trestle
35
35
  options[:group] || NullGroup.new
36
36
  end
37
37
 
38
+ def path
39
+ if @path
40
+ @path
41
+ elsif admin = self.admin
42
+ admin.path(options[:action])
43
+ else
44
+ "#"
45
+ end
46
+ end
47
+
38
48
  def admin
39
- options[:admin]
49
+ case options[:admin]
50
+ when nil, false
51
+ return
52
+ when Symbol, String
53
+ Trestle.lookup(options[:admin]) or raise ActionController::UrlGenerationError, "No admin found named #{options[:admin].inspect}"
54
+ else
55
+ options[:admin]
56
+ end
40
57
  end
41
58
 
42
59
  def label
@@ -56,7 +73,7 @@ module Trestle
56
73
  end
57
74
 
58
75
  def html_options
59
- options.except(:admin, :badge, :group, :icon, :if, :label, :priority, :unless)
76
+ options.except(:action, :admin, :badge, :group, :icon, :if, :label, :priority, :unless)
60
77
  end
61
78
 
62
79
  def visible?(context)
@@ -15,27 +15,24 @@ module Trestle
15
15
 
16
16
  def reset!
17
17
  @admins = {}
18
- @models = {}
18
+ @models = nil
19
19
  end
20
20
 
21
21
  def empty?
22
22
  none?
23
23
  end
24
24
 
25
- def register(admin, register_model: true)
25
+ def register(admin)
26
26
  @admins[admin.admin_name] = admin
27
-
28
- if register_model && register_admin_for_model_loookup?(admin)
29
- @models[admin.model.name] ||= admin
30
- end
31
-
32
- admin
33
27
  end
34
28
 
35
29
  def lookup_admin(admin)
36
30
  # Given object is already an admin class
37
31
  return admin if admin.is_a?(Class) && admin < Trestle::Admin
38
32
 
33
+ # Given object is already an admin instance
34
+ return admin if admin.is_a?(Trestle::Admin)
35
+
39
36
  @admins[admin.to_s]
40
37
  end
41
38
  alias lookup lookup_admin
@@ -43,7 +40,7 @@ module Trestle
43
40
  def lookup_model(model)
44
41
  # Lookup each class in the model's ancestor chain
45
42
  while model
46
- admin = @models[model.name]
43
+ admin = models[model.name]
47
44
  return admin if admin
48
45
 
49
46
  model = model.superclass
@@ -54,8 +51,14 @@ module Trestle
54
51
  end
55
52
 
56
53
  private
57
- def register_admin_for_model_loookup?(admin)
58
- admin.respond_to?(:model) && !(admin.respond_to?(:singular?) && admin.singular?)
54
+ def models
55
+ @models ||= @admins.values.inject({}) { |result, admin|
56
+ if admin.respond_to?(:register_model?) && admin.register_model?
57
+ result[admin.model.name] ||= admin
58
+ end
59
+
60
+ result
61
+ }
59
62
  end
60
63
  end
61
64
  end
@@ -43,9 +43,10 @@ module Trestle
43
43
  admin.define_adapter_method(:to_param, &block)
44
44
  end
45
45
 
46
- def params(&block)
46
+ def permitted_params(&block)
47
47
  admin.define_adapter_method(:permitted_params, &block)
48
48
  end
49
+ alias params permitted_params
49
50
 
50
51
  def decorator(decorator)
51
52
  admin.decorator = decorator
@@ -76,14 +77,16 @@ module Trestle
76
77
  admin.define_adapter_method(:count, &block)
77
78
  end
78
79
 
79
- def scopes(options={}, &block)
80
- admin.scopes.options.merge!(options)
81
- admin.scopes.append(options, &block) if block_given?
80
+ def scopes(defaults: {}, **options, &block)
81
+ defaults = defaults.merge(options.slice(:count))
82
+
83
+ admin.scopes.apply_options!(options)
84
+ admin.scopes.append(**defaults, &block) if block_given?
82
85
  end
83
86
 
84
- def scope(name, scope=nil, options={}, &block)
87
+ def scope(name, scope=nil, **options, &block)
85
88
  scopes do
86
- scope(name, scope, options, &block)
89
+ scope(name, scope, **options, &block)
87
90
  end
88
91
  end
89
92
 
@@ -9,26 +9,26 @@ module Trestle
9
9
  return unless action?(:new)
10
10
 
11
11
  defaults = { action: :new, style: :light, icon: "fa fa-plus", class: "btn-new-resource" }
12
- link(label, defaults.merge(attrs))
12
+ link(label, **defaults.merge(attrs))
13
13
  end
14
14
 
15
15
  def save(label: t("buttons.save", default: "Save %{model_name}"), **attrs)
16
16
  defaults = { style: :success }
17
- button(label, defaults.merge(attrs))
17
+ button(label, **defaults.merge(attrs))
18
18
  end
19
19
 
20
20
  def delete(label: t("buttons.delete", default: "Delete %{model_name}"), **attrs)
21
21
  return unless action?(:destroy)
22
22
 
23
- defaults = Trestle::Options.new(action: :destroy, style: :danger, icon: "fa fa-trash", data: { turbo_method: "delete", controller: "confirm-delete", confirm_delete_placement_value: "bottom" })
24
- link(label, instance, defaults.merge(attrs))
23
+ defaults = Trestle::Options.new(action: :destroy, style: :danger, icon: "fa fa-trash", data: { turbo_method: "delete", turbo_frame: "_top", controller: "confirm-delete", confirm_delete_placement_value: "bottom" })
24
+ link(label, instance, **defaults.merge(attrs))
25
25
  end
26
26
 
27
27
  def dismiss(label: t("buttons.ok", default: "OK"), **attrs)
28
28
  return unless @template.modal_request?
29
29
 
30
30
  defaults = Trestle::Options.new(type: :button, style: :light, data: { bs_dismiss: "modal" })
31
- button(label, defaults.merge(attrs))
31
+ button(label, **defaults.merge(attrs))
32
32
  end
33
33
  alias ok dismiss
34
34
 
@@ -104,6 +104,10 @@ module Trestle
104
104
  options[:singular]
105
105
  end
106
106
 
107
+ def register_model?
108
+ options[:register_model] != false && !singular?
109
+ end
110
+
107
111
  def translate(key, options={})
108
112
  super(key, options.merge({
109
113
  model_name: model_name.titleize,
@@ -113,10 +117,8 @@ module Trestle
113
117
  end
114
118
  alias t translate
115
119
 
116
- def instance_path(instance, options={})
117
- action = options.fetch(:action) { :show }
118
- options = options.merge(id: to_param(instance)) unless singular?
119
-
120
+ def instance_path(instance, action: :show, **options)
121
+ options.merge!(id: to_param(instance)) unless singular?
120
122
  path(action, options)
121
123
  end
122
124
 
@@ -133,7 +135,7 @@ module Trestle
133
135
  }
134
136
 
135
137
  Proc.new do
136
- public_send(resource_method, resource_name, resource_options) do
138
+ public_send(resource_method, resource_name, **resource_options) do
137
139
  admin.additional_routes.each do |block|
138
140
  instance_exec(&block)
139
141
  end
@@ -1,37 +1,33 @@
1
1
  module Trestle
2
2
  class Scopes
3
3
  class Block
4
- attr_reader :block, :options
4
+ attr_reader :block, :defaults
5
5
 
6
- def initialize(options={}, &block)
7
- @options, @block = options, block
6
+ def initialize(**defaults, &block)
7
+ @defaults, @block = defaults, 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, options)
13
+ context = Evaluator.new(context, **defaults)
14
14
  context.instance_exec(context, &block)
15
15
  context.scopes
16
16
  end
17
17
 
18
+ protected
18
19
  class Evaluator
19
20
  include EvaluationContext
20
21
 
21
22
  attr_reader :scopes
22
23
 
23
- def initialize(context=nil, defaults={})
24
+ def initialize(context=nil, **defaults)
24
25
  @context, @defaults = context, defaults
25
26
  @scopes = []
26
27
  end
27
28
 
28
- def scope(name, scope=nil, options={}, &block)
29
- if scope.is_a?(Hash)
30
- options = scope
31
- scope = nil
32
- end
33
-
34
- scopes << Scope.new(@context, name, @defaults.merge(options), &(scope || block))
29
+ def scope(name, scope=nil, **options, &block)
30
+ scopes << Scope.new(@context, name, **@defaults.merge(options), &(scope || block))
35
31
  end
36
32
  end
37
33
  end
@@ -8,8 +8,12 @@ module Trestle
8
8
  @options = {}
9
9
  end
10
10
 
11
- def append(options={}, &block)
12
- @blocks << Block.new(options, &block)
11
+ def append(**defaults, &block)
12
+ @blocks << Block.new(**defaults, &block)
13
+ end
14
+
15
+ def apply_options!(options)
16
+ @options.merge!(options)
13
17
  end
14
18
 
15
19
  # Evaluates each of the scope blocks within the given admin context
@@ -1,10 +1,11 @@
1
1
  module Trestle
2
2
  class Scopes
3
3
  class Scope
4
- attr_reader :name, :options, :block
4
+ attr_reader :name, :group, :block
5
5
 
6
- def initialize(admin, name, options={}, &block)
7
- @admin, @name, @options, @block = admin, name, options, block
6
+ def initialize(admin, name, label: nil, group: nil, default: false, count: true, &block)
7
+ @admin, @name, @block = admin, name, block
8
+ @label, @group, @default, @count = label, group, default, count
8
9
  end
9
10
 
10
11
  def to_param
@@ -12,19 +13,15 @@ module Trestle
12
13
  end
13
14
 
14
15
  def label
15
- @options[:label] || @admin.t("scopes.#{name}", default: name.to_s.humanize.titleize)
16
- end
17
-
18
- def group
19
- @options[:group]
16
+ @label || default_label
20
17
  end
21
18
 
22
19
  def default?
23
- @options[:default] == true
20
+ @default
24
21
  end
25
22
 
26
23
  def count?
27
- @options[:count] != false
24
+ @count
28
25
  end
29
26
 
30
27
  def apply(collection)
@@ -40,6 +37,7 @@ module Trestle
40
37
  end
41
38
 
42
39
  def count(collection)
40
+ return unless count?
43
41
  @admin.count(@admin.merge_scopes(collection, apply(collection)))
44
42
  end
45
43
 
@@ -52,6 +50,11 @@ module Trestle
52
50
  default?
53
51
  end
54
52
  end
53
+
54
+ protected
55
+ def default_label
56
+ @admin.t("scopes.#{name}", default: name.to_s.humanize.titleize)
57
+ end
55
58
  end
56
59
  end
57
60
  end
data/lib/trestle/tab.rb CHANGED
@@ -6,7 +6,7 @@ module Trestle
6
6
 
7
7
  attr_reader :name, :options
8
8
 
9
- def initialize(name, options={})
9
+ def initialize(name, **options)
10
10
  @name, @options = name, options
11
11
  end
12
12
 
@@ -19,7 +19,7 @@ module Trestle
19
19
  end
20
20
 
21
21
  def badge
22
- content_tag(:span, options[:badge], class: "badge") if options[:badge]
22
+ tag.span(options[:badge], class: "badge") if options[:badge]
23
23
  end
24
24
  end
25
25
  end
@@ -36,7 +36,7 @@ module Trestle
36
36
  end
37
37
 
38
38
  def render(instance)
39
- @template.content_tag(:td, content(instance), class: classes, data: data)
39
+ @template.tag.td(content(instance), class: classes, data: data)
40
40
  end
41
41
 
42
42
  def render?
@@ -61,7 +61,8 @@ module Trestle
61
61
  return if options.key?(:header) && options[:header].in?([nil, false])
62
62
 
63
63
  if @table.sortable? && @column.sortable?
64
- @template.sort_link(header_text, @column.sort_field, @column.sort_options)
64
+ link_options = @column.sort_options.slice(:default, :default_order)
65
+ @template.sort_link(header_text, @column.sort_field, **link_options)
65
66
  else
66
67
  header_text
67
68
  end
@@ -69,7 +70,7 @@ module Trestle
69
70
 
70
71
  def content(instance)
71
72
  value = column_value(instance)
72
- content = @template.format_value(value, options)
73
+ content = @template.format_value(value, **options)
73
74
 
74
75
  if value.respond_to?(:id) && options[:link] != false
75
76
  # Column value was a model instance (e.g. from an association).
@@ -24,7 +24,7 @@ module Trestle
24
24
  end
25
25
 
26
26
  def render(instance)
27
- @template.content_tag(:tr, options(instance)) do
27
+ @template.tag.tr(**options(instance)) do
28
28
  @template.safe_join(columns.map { |column| column.render(instance) }, "\n")
29
29
  end
30
30
  end
@@ -5,16 +5,16 @@ module Trestle
5
5
  @template = template
6
6
  end
7
7
 
8
- def button(label, options={}, &block)
9
- Button.new(@template, label, options, &block)
8
+ def button(label, **options, &block)
9
+ Button.new(@template, label, **options, &block)
10
10
  end
11
11
 
12
- def link(label, instance_or_url={}, options={}, &block)
13
- Link.new(@template, label, instance_or_url, options, &block)
12
+ def link(label, instance_or_url=nil, **options, &block)
13
+ Link.new(@template, label, instance_or_url, **options, &block)
14
14
  end
15
15
 
16
- def dropdown(label=nil, options={}, &block)
17
- Dropdown.new(@template, label, options, &block)
16
+ def dropdown(label=nil, **options, &block)
17
+ Dropdown.new(@template, label, **options, &block)
18
18
  end
19
19
 
20
20
  # Only methods explicitly tagged as builder methods will be automatically
@@ -21,10 +21,7 @@ module Trestle
21
21
  end
22
22
 
23
23
  private
24
- def self.ruby2_keywords(*)
25
- end unless respond_to?(:ruby2_keywords, true)
26
-
27
- ruby2_keywords def method_missing(name, *args, &block)
24
+ def method_missing(name, *args, &block)
28
25
  result = builder.send(name, *args, &block)
29
26
 
30
27
  if builder.builder_methods.include?(name)
@@ -33,6 +30,7 @@ module Trestle
33
30
  result
34
31
  end
35
32
  end
33
+ ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
36
34
 
37
35
  def respond_to_missing?(name, include_all=false)
38
36
  builder.respond_to?(name) || super
@@ -3,17 +3,16 @@ module Trestle
3
3
  class Item
4
4
  attr_reader :label, :menu
5
5
 
6
- delegate :admin_link_to, :button_tag, :content_tag, :safe_join, :icon, to: :@template
6
+ delegate :admin_link_to, :button_tag, :tag, :safe_join, :icon, to: :@template
7
7
 
8
- def initialize(template, label, options={}, &block)
8
+ def initialize(template, label, icon: nil, style: nil, **options, &block)
9
9
  @template = template
10
10
  @label, @options, @block = label, options
11
11
 
12
12
  @menu = Menu.new(template)
13
13
  @menu.build(&block) if block_given?
14
14
 
15
- @icon = options.delete(:icon)
16
- @style = options.delete(:style)
15
+ @icon, @style = icon, style
17
16
  end
18
17
 
19
18
  def ==(other)
@@ -22,7 +21,7 @@ module Trestle
22
21
 
23
22
  def to_s
24
23
  if menu.items.any?
25
- content_tag(:div, class: "btn-group", role: "group") do
24
+ tag.div(class: "btn-group", role: "group") do
26
25
  safe_join([render, render_menu], "\n")
27
26
  end
28
27
  else
@@ -54,7 +53,7 @@ module Trestle
54
53
 
55
54
  def button_label(content, options)
56
55
  icon = icon(@icon) if @icon
57
- label = content_tag(:span, content, class: "btn-label")
56
+ label = tag.span(content, class: "btn-label")
58
57
 
59
58
  safe_join([icon, label].compact, " ")
60
59
  end
@@ -77,21 +76,13 @@ module Trestle
77
76
  class Link < Item
78
77
  attr_reader :instance_or_url
79
78
 
80
- def initialize(template, label, instance_or_url={}, options={}, &block)
81
- if instance_or_url.is_a?(Hash)
82
- super(template, label, instance_or_url, &block)
83
- else
84
- super(template, label, options, &block)
85
- @instance_or_url = instance_or_url
86
- end
79
+ def initialize(template, label, instance_or_url=nil, **options, &block)
80
+ super(template, label, **options, &block)
81
+ @instance_or_url = instance_or_url
87
82
  end
88
83
 
89
84
  def render
90
- if @instance_or_url
91
- admin_link_to(button_label(label, options), instance_or_url, options)
92
- else
93
- admin_link_to(button_label(label, options), options)
94
- end
85
+ admin_link_to(button_label(label, options), instance_or_url, **options)
95
86
  end
96
87
  end
97
88
 
@@ -102,7 +93,7 @@ module Trestle
102
93
 
103
94
  def label
104
95
  safe_join([
105
- super, content_tag(:span, "", class: "caret")
96
+ super, tag.span("", class: "caret")
106
97
  ], " ")
107
98
  end
108
99
 
@@ -1,7 +1,7 @@
1
1
  module Trestle
2
2
  class Toolbar
3
3
  class Menu
4
- delegate :content_tag, :safe_join, to: :@template
4
+ delegate :tag, :safe_join, to: :@template
5
5
 
6
6
  attr_reader :items
7
7
 
@@ -18,17 +18,17 @@ module Trestle
18
18
  end
19
19
 
20
20
  def render_toggle(options={})
21
- content_tag(:button, type: "button", class: Array(options[:class]) + ["dropdown-toggle dropdown-toggle-split"], data: { bs_toggle: "dropdown" }, aria: { expanded: false }) do
22
- content_tag(:span, I18n.t("trestle.ui.toggle_dropdown", default: "Toggle dropdown"), class: "visually-hidden")
21
+ tag.button(type: "button", class: Array(options[:class]) + ["dropdown-toggle dropdown-toggle-split"], data: { bs_toggle: "dropdown" }, aria: { expanded: false }) do
22
+ tag.span(I18n.t("trestle.ui.toggle_dropdown", default: "Toggle dropdown"), class: "visually-hidden")
23
23
  end
24
24
  end
25
25
 
26
26
  def render_items
27
- content_tag(:ul, safe_join(items, "\n"), class: "dropdown-menu dropdown-menu-end", role: "menu")
27
+ tag.ul(safe_join(items, "\n"), class: "dropdown-menu dropdown-menu-end", role: "menu")
28
28
  end
29
29
 
30
30
  class Builder
31
- delegate :admin_link_to, :content_tag, :tag, to: :@template
31
+ delegate :admin_link_to, :tag, to: :@template
32
32
 
33
33
  def initialize(menu, template)
34
34
  @menu, @template = menu, template
@@ -42,19 +42,19 @@ module Trestle
42
42
  options[:class] = Array(options[:class])
43
43
  options[:class] << "dropdown-item"
44
44
 
45
- item { admin_link_to(content, instance_or_url, options, &block) }
45
+ item { admin_link_to(content, instance_or_url, **options, &block) }
46
46
  end
47
47
 
48
48
  def header(text)
49
- item { content_tag(:h6, text, class: "dropdown-header") }
49
+ item { tag.h6(text, class: "dropdown-header") }
50
50
  end
51
51
 
52
52
  def divider
53
- item { tag(:hr, class: "dropdown-divider") }
53
+ item { tag.hr(class: "dropdown-divider") }
54
54
  end
55
55
 
56
56
  def item(options={}, &block)
57
- item = block_given? ? content_tag(:li, options, &block) : content_tag(:li, "", options)
57
+ item = block_given? ? tag.li(**options, &block) : tag.li("", **options)
58
58
 
59
59
  @menu.items << item
60
60
 
@@ -1,3 +1,3 @@
1
1
  module Trestle
2
- VERSION = "0.10.0.pre2"
2
+ VERSION = "0.10.1"
3
3
  end
data/lib/trestle.rb CHANGED
@@ -44,8 +44,8 @@ module Trestle
44
44
  end
45
45
 
46
46
  # Builds and registers a new admin resource
47
- def self.resource(name, register_model: true, **options, &block)
48
- register(Resource::Builder.create(name, options, &block), register_model: register_model)
47
+ def self.resource(name, **options, &block)
48
+ register(Resource::Builder.create(name, options, &block))
49
49
  end
50
50
 
51
51
  # Configuration methods