From 00b17fa0dcf52cb08c5141dcacecaa3ffb3691f3 Mon Sep 17 00:00:00 2001 From: Sergio Cambra Date: Sat, 14 Dec 2024 16:48:18 +0100 Subject: [PATCH] fix rubocop offenses --- .../data_structures/action_link_separator.rb | 2 +- .../data_structures/action_links.rb | 6 +++- .../helpers/action_link_helpers.rb | 29 +++++++++---------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/lib/active_scaffold/data_structures/action_link_separator.rb b/lib/active_scaffold/data_structures/action_link_separator.rb index 4cb0efff9..64db91726 100644 --- a/lib/active_scaffold/data_structures/action_link_separator.rb +++ b/lib/active_scaffold/data_structures/action_link_separator.rb @@ -10,4 +10,4 @@ def ==(other) end def name_to_cache; end # :nodoc: -end \ No newline at end of file +end diff --git a/lib/active_scaffold/data_structures/action_links.rb b/lib/active_scaffold/data_structures/action_links.rb index 94e56c2ac..0bbd74fd2 100644 --- a/lib/active_scaffold/data_structures/action_links.rb +++ b/lib/active_scaffold/data_structures/action_links.rb @@ -35,7 +35,8 @@ def add(action, options = {}) alias << add def add_separator(weight = 0) - raise "Call add_separator on a group" if name == :root + raise 'Call add_separator on a group' if name == :root + add_to_set ActionLinkSeparator.new(weight) end @@ -57,6 +58,7 @@ def [](val) links = [] @set.each do |item| next if item == :separator + if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) collected = item[val] links << collected unless collected.nil? @@ -71,6 +73,7 @@ def find_duplicate(link) links = [] @set.each do |item| next if item == :separator + if item.is_a?(ActiveScaffold::DataStructures::ActionLinks) collected = item.find_duplicate(link) links << collected unless collected.nil? @@ -84,6 +87,7 @@ def find_duplicate(link) def delete(val) each(include_set: true) do |link, set| next if link == :separator + if link.action.to_s == val.to_s set.delete link break diff --git a/lib/active_scaffold/helpers/action_link_helpers.rb b/lib/active_scaffold/helpers/action_link_helpers.rb index 7fd849b3f..12e93c070 100644 --- a/lib/active_scaffold/helpers/action_link_helpers.rb +++ b/lib/active_scaffold/helpers/action_link_helpers.rb @@ -44,15 +44,7 @@ def display_action_links(action_links, record, options, &block) end content = nil if link.is_a? ActiveScaffold::DataStructures::ActionLinks - unless link.empty? - options[:level] += 1 - content = display_action_links(link, record, options, &block) - options[:level] -= 1 - if content.present? - content = display_action_link(link, content, record, options) - options[:first_action] = false - end - end + content = display_action_link_group(link, record, options, &block) unless link.empty? elsif !skip_action_link?(link, *Array(options[:for])) authorized, reason = action_link_authorized?(link, *Array(options[:for])) next if !authorized && options[:skip_unauthorized] @@ -60,16 +52,23 @@ def display_action_links(action_links, record, options, &block) content = display_action_link(link, nil, record, options.merge(authorized: authorized, not_authorized_reason: reason)) options[:first_action] = false end - if content.present? - prev_link = true - output << display_action_link_separator(options) if separator - output << content - separator = false - end + next if content.blank? + + prev_link = true + output << display_action_link_separator(options) if separator + output << content + separator = false end output end + def display_action_link_group(link, record, options, &block) + options[:level] += 1 + content = display_action_links(link, record, options, &block) + options[:level] -= 1 + display_action_link(link, content, record, options).tap { options[:first_action] = false } if content.present? + end + def display_action_link_separator(options) tag = options[:level_0_tag] || :a if options[:level].zero? content_tag(tag || :li, ' '.html_safe, class: 'separator')