Skip to content

Commit

Permalink
fix rubocop offenses
Browse files Browse the repository at this point in the history
  • Loading branch information
scambra committed Dec 11, 2024
1 parent 0d5e836 commit 1ca5ecd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ def ==(other)
end

def name_to_cache; end # :nodoc:
end
end
6 changes: 5 additions & 1 deletion lib/active_scaffold/data_structures/action_links.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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?
Expand All @@ -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?
Expand All @@ -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
Expand Down
29 changes: 14 additions & 15 deletions lib/active_scaffold/helpers/action_link_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,31 @@ 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]

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, '&nbsp;'.html_safe, class: 'separator')
Expand Down
22 changes: 11 additions & 11 deletions lib/generators/active_scaffold/install_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,37 +54,37 @@ def add_to_stylesheet_manifest

def add_to_importmap
original_js = File.binread(IMPORTMAP)
if original_js.match? /^pin +['"]active_scaffold['"](?=,|$)/
if original_js.match?(/^pin +['"]active_scaffold['"](?=,|$)/)
say_status('skipped', "append active_scaffold to #{IMPORTMAP}", :yellow)
else
append_to_file IMPORTMAP do
"pin 'active_scaffold'\n"
end
end
if Object.const_defined?(:Jquery)
if original_js.match? /^pin +['"]jquery['"](?=,|$)/
if original_js.match?(/^pin +['"]jquery['"](?=,|$)/)
say_status('skipped', "append jquery to #{IMPORTMAP}", :yellow)
else
append_to_file IMPORTMAP do
"pin 'jquery'\n"
end
end
if original_js.match? /^pin +['"](jquery_ujs|@rails\/ujs)['"](?=,|$)/
if original_js.match?(%r{^pin +['"](jquery_ujs|@rails/ujs)['"](?=,|$)})
say_status('skipped', "append jquery_ujs to #{IMPORTMAP}", :yellow)
else
append_to_file IMPORTMAP do
"pin 'jquery_ujs'\n"
end
end
else
say_status('missing', "no jquery-rails gem, load jquery, and jquery_ujs or @rails/ujs, in your layout, or add jquery-rails " \
"to Gemfile and add pin \"jquery\" and pin \"jquery_ujs\" or pin \"@rails/ujs\", to #{IMPORTMAP}", :red)
say_status('missing', 'no jquery-rails gem, load jquery, and jquery_ujs or @rails/ujs, in your layout, or add jquery-rails ' \
"to Gemfile and add pin \"jquery\" and pin \"jquery_ujs\" or pin \"@rails/ujs\", to #{IMPORTMAP}", :red)
end
end

def add_to_js_app
original_js = File.binread(JS_APP)
if original_js.match? /^import +['"]active_scaffold['"]/
if original_js.match?(/^import +['"]active_scaffold['"]/)
say_status('skipped', "append active_scaffold to #{JS_APP}", :yellow)
else
append_to_file JS_APP do
Expand All @@ -93,24 +93,24 @@ def add_to_js_app
end
manifest = ['active_scaffold/manifest.js']
if Object.const_defined?(:Jquery)
if original_js.match? /^import +['"]jquery['"]/
if original_js.match?(/^import +['"]jquery['"]/)
say_status('skipped', "append jquery to #{JS_APP}", :yellow)
else
manifest << 'jquery.js'
insert_into_file JS_APP, before: %r{import +['"]active_scaffold['"]\n} do
insert_into_file JS_APP, before: /import +['"]active_scaffold['"]\n/ do
"import 'jquery'\n"
end
end
if original_js.match? /^import +(['"]jquery_ujs['"]|Rails from ['"]@rails\/ujs['"])/
if original_js.match?(%r{^import +(['"]jquery_ujs['"]|Rails from ['"]@rails/ujs['"])})
say_status('skipped', "append jquery_ujs to #{JS_APP}", :yellow)
else
manifest << 'jquery_ujs.js'
insert_into_file JS_APP, before: %r{import +['"]active_scaffold['"]\n} do
insert_into_file JS_APP, before: /import +['"]active_scaffold['"]\n/ do
"import 'jquery_ujs'\n"
end
end
end
add_to_manifest *manifest
add_to_manifest(*manifest)
end

def create_javascript_manifest(file)
Expand Down

0 comments on commit 1ca5ecd

Please sign in to comment.