From 60cb9a37c90b8e681c390712b285f87f4b484752 Mon Sep 17 00:00:00 2001 From: Stephen Nelson Date: Mon, 11 Dec 2023 15:13:16 +1030 Subject: [PATCH] Rubocop fixups --- .../katalyst/navigation/items_controller.rb | 6 +++--- .../katalyst/navigation/menus_controller.rb | 10 +++++----- .../katalyst/navigation/editor/errors.rb | 4 ++-- app/helpers/katalyst/navigation/editor/item.rb | 4 ++-- app/helpers/katalyst/navigation/editor/list.rb | 2 +- .../katalyst/navigation/editor/new_item.rb | 8 ++++---- .../katalyst/navigation/editor/status_bar.rb | 12 ++++++------ .../katalyst/navigation/editor_helper.rb | 18 +++++++++--------- .../katalyst/navigation/frontend_helper.rb | 8 ++++---- .../katalyst/navigation/types/nodes_type.rb | 4 ++-- .../katalyst/navigation/items/edit.html.erb | 2 +- .../katalyst/navigation/items/new.html.erb | 2 +- .../katalyst/navigation/menus/_item.html.erb | 2 +- .../navigation/menus/_new_item.html.erb | 2 +- .../katalyst/navigation/menus/edit.html.erb | 2 +- .../katalyst/navigation/menus/index.html.erb | 2 +- .../katalyst/navigation/menus/show.html.erb | 8 ++++---- .../app/views/layouts/application.html.erb | 2 +- spec/factories/katalyst/navigation/menus.rb | 2 +- spec/models/katalyst/navigation/menu_spec.rb | 14 +++++++------- spec/rails_helper.rb | 2 +- .../navigation/items_controller_spec.rb | 4 ++-- .../navigation/menus_controller_spec.rb | 8 ++++---- 23 files changed, 64 insertions(+), 64 deletions(-) diff --git a/app/controllers/katalyst/navigation/items_controller.rb b/app/controllers/katalyst/navigation/items_controller.rb index 30c9a2d..b6a16c8 100644 --- a/app/controllers/katalyst/navigation/items_controller.rb +++ b/app/controllers/katalyst/navigation/items_controller.rb @@ -17,9 +17,9 @@ def edit def create item = @menu.items.build(item_params) if item.save - render :update, locals: { item: item, previous: @menu.items.build(type: item.type) } + render :update, locals: { item:, previous: @menu.items.build(type: item.type) } else - render :new, status: :unprocessable_entity, locals: { item: item } + render :new, status: :unprocessable_entity, locals: { item: } end end @@ -29,7 +29,7 @@ def update if @item.valid? previous = @item @item = @item.dup.tap(&:save!) - render locals: { item: @item, previous: previous } + render locals: { item: @item, previous: } else render :edit, status: :unprocessable_entity, locals: { item: @item } end diff --git a/app/controllers/katalyst/navigation/menus_controller.rb b/app/controllers/katalyst/navigation/menus_controller.rb index aac777e..9f472bb 100644 --- a/app/controllers/katalyst/navigation/menus_controller.rb +++ b/app/controllers/katalyst/navigation/menus_controller.rb @@ -5,21 +5,21 @@ module Navigation class MenusController < BaseController def index collection = Katalyst::Tables::Collection::Base.new(sorting: :title).with_params(params).apply(Menu.all) - table = Katalyst::Turbo::TableComponent.new(collection: collection, + table = Katalyst::Turbo::TableComponent.new(collection:, id: "index-table", class: "index-table", caption: true) respond_to do |format| format.turbo_stream { render(table) } if self_referred? - format.html { render :index, locals: { table: table } } + format.html { render :index, locals: { table: } } end end def show menu = Menu.find(params[:id]) - render locals: { menu: menu } + render locals: { menu: } end def new @@ -29,7 +29,7 @@ def new def edit menu = Menu.find(params[:id]) - render locals: { menu: menu } + render locals: { menu: } end def create @@ -49,7 +49,7 @@ def update menu.attributes = menu_params unless menu.valid? - return render turbo_stream: helpers.navigation_editor_errors(menu: menu), + return render turbo_stream: helpers.navigation_editor_errors(menu:), status: :unprocessable_entity end diff --git a/app/helpers/katalyst/navigation/editor/errors.rb b/app/helpers/katalyst/navigation/editor/errors.rb index c1b6f78..25dfbc2 100644 --- a/app/helpers/katalyst/navigation/editor/errors.rb +++ b/app/helpers/katalyst/navigation/editor/errors.rb @@ -4,11 +4,11 @@ module Katalyst module Navigation module Editor class Errors < Base - def build(**options) + def build(**) turbo_frame_tag dom_id(menu, :errors) do next unless menu.errors.any? - tag.div(class: "navigation-errors", **options) do + tag.div(class: "navigation-errors", **) do tag.h2("Errors in navigation") + tag.ul(class: "errors") do menu.errors.each do |error| diff --git a/app/helpers/katalyst/navigation/editor/item.rb b/app/helpers/katalyst/navigation/editor/item.rb index 72dff8a..fa03670 100644 --- a/app/helpers/katalyst/navigation/editor/item.rb +++ b/app/helpers/katalyst/navigation/editor/item.rb @@ -6,9 +6,9 @@ module Editor class Item < Base attr_accessor :item - def build(item, **options, &block) + def build(item, **, &block) self.item = item - tag.div **default_options(id: dom_id(item), **options) do + tag.div **default_options(id: dom_id(item), **) do concat(capture { yield self }) if block concat fields(item) end diff --git a/app/helpers/katalyst/navigation/editor/list.rb b/app/helpers/katalyst/navigation/editor/list.rb index c50d381..d38033c 100644 --- a/app/helpers/katalyst/navigation/editor/list.rb +++ b/app/helpers/katalyst/navigation/editor/list.rb @@ -13,7 +13,7 @@ class List < Base dragend->#{LIST_CONTROLLER}#dragend ACTIONS - def build(options, &_block) + def build(options, &) tag.ol **default_options(id: menu_form_id, **options) do yield self end diff --git a/app/helpers/katalyst/navigation/editor/new_item.rb b/app/helpers/katalyst/navigation/editor/new_item.rb index f65492a..ffc9685 100644 --- a/app/helpers/katalyst/navigation/editor/new_item.rb +++ b/app/helpers/katalyst/navigation/editor/new_item.rb @@ -8,10 +8,10 @@ class NewItem < Base dragstart->#{NEW_ITEM_CONTROLLER}#dragstart ACTIONS - def build(item, **options, &block) + def build(item, **options, &) capture do concat(tag.div(**default_options(options)) do - concat capture(&block) + concat capture(&) concat item_template(item) end) concat turbo_replace_placeholder(item) @@ -23,7 +23,7 @@ def build(item, **options, &block) # cancels adding a new item by pressing 'discard' in the new item form. def turbo_replace_placeholder(item) turbo_stream.replace dom_id(item) do - navigation_editor_item(item: item, data: { delete: "" }) + navigation_editor_item(item:, data: { delete: "" }) end end @@ -32,7 +32,7 @@ def turbo_replace_placeholder(item) # editor list on drop. def item_template(item) tag.template data: { "#{NEW_ITEM_CONTROLLER}-target" => "template" } do - navigation_editor_items(item: item) + navigation_editor_items(item:) end end diff --git a/app/helpers/katalyst/navigation/editor/status_bar.rb b/app/helpers/katalyst/navigation/editor/status_bar.rb index 47a924f..467ba4c 100644 --- a/app/helpers/katalyst/navigation/editor/status_bar.rb +++ b/app/helpers/katalyst/navigation/editor/status_bar.rb @@ -8,8 +8,8 @@ class StatusBar < Base navigation:change@document->#{STATUS_BAR_CONTROLLER}#change ACTIONS - def build(**options) - tag.div **default_options(**options) do + def build(**) + tag.div **default_options(**) do concat status(:published, last_update: l(menu.updated_at, format: :short)) concat status(:draft) concat status(:dirty) @@ -17,8 +17,8 @@ def build(**options) end end - def status(state, **options) - tag.span(t("views.katalyst.navigation.editor.#{state}_html", **options), + def status(state, **) + tag.span(t("views.katalyst.navigation.editor.#{state}_html", **), class: "status-text", data: { state => "" }) end @@ -32,13 +32,13 @@ def actions end end - def action(action, **options) + def action(action, **) tag.li do button_tag(t("views.katalyst.navigation.editor.#{action}"), name: "commit", value: action, form: menu_form_id, - **options) + **) end end diff --git a/app/helpers/katalyst/navigation/editor_helper.rb b/app/helpers/katalyst/navigation/editor_helper.rb index b85c576..40c26e5 100644 --- a/app/helpers/katalyst/navigation/editor_helper.rb +++ b/app/helpers/katalyst/navigation/editor_helper.rb @@ -6,7 +6,7 @@ module EditorHelper def navigation_editor_new_items(menu) Katalyst::Navigation.config.items.map do |item_class| item_class = item_class.safe_constantize if item_class.is_a?(String) - item_class.new(menu: menu) + item_class.new(menu:) end end @@ -26,26 +26,26 @@ def navigation_editor_items(item:, menu: item.menu) end # Generate a turbo stream fragment that will show structural errors to the user. - def navigation_editor_errors(menu:, **options) + def navigation_editor_errors(menu:, **) turbo_stream.replace(dom_id(menu, :errors), - Editor::Errors.new(self, menu).build(**options)) + Editor::Errors.new(self, menu).build(**)) end # Generate a new item template. - def navigation_editor_new_item(item:, menu: item.menu, **options, &block) - Editor::NewItem.new(self, menu).build(item, **options, &block) + def navigation_editor_new_item(item:, menu: item.menu, **, &block) + Editor::NewItem.new(self, menu).build(item, **, &block) end - def navigation_editor_item(item:, menu: item.menu, **options, &block) - Editor::Item.new(self, menu).build(item, **options, &block) + def navigation_editor_item(item:, menu: item.menu, **, &block) + Editor::Item.new(self, menu).build(item, **, &block) end def navigation_editor_item_fields(item:, menu: item.menu) Editor::Item.new(self, menu).fields(item) end - def navigation_editor_status_bar(menu:, **options) - Editor::StatusBar.new(self, menu).build(**options) + def navigation_editor_status_bar(menu:, **) + Editor::StatusBar.new(self, menu).build(**) end end end diff --git a/app/helpers/katalyst/navigation/frontend_helper.rb b/app/helpers/katalyst/navigation/frontend_helper.rb index e82c129..30cf87c 100644 --- a/app/helpers/katalyst/navigation/frontend_helper.rb +++ b/app/helpers/katalyst/navigation/frontend_helper.rb @@ -11,8 +11,8 @@ module FrontendHelper # # @param(menu: Katalyst::Navigation::Menu) # @return Structured HTML containing top level + nested navigation links - def navigation_menu_with(menu:, **options) - builder = navigation_builder(**options) + def navigation_menu_with(menu:, **) + builder = navigation_builder(**) menu = navigation_menu_for(menu) if menu.is_a?(Symbol) return if menu&.published_version_id.blank? @@ -26,8 +26,8 @@ def navigation_menu_with(menu:, **options) # # @param(items: [Katalyst::Navigation::Item]) # @return Structured HTML containing top level + nested navigation links - def navigation_items_with(items:, **options) - builder = navigation_builder(**options) + def navigation_items_with(items:, **) + builder = navigation_builder(**) capture do items.each do |item| diff --git a/app/models/katalyst/navigation/types/nodes_type.rb b/app/models/katalyst/navigation/types/nodes_type.rb index 2084758..18db88c 100644 --- a/app/models/katalyst/navigation/types/nodes_type.rb +++ b/app/models/katalyst/navigation/types/nodes_type.rb @@ -27,13 +27,13 @@ def deserialize(value) # Deserialize a params-style array, e.g. "0" => { ... } def deserialize_params(value) value.map do |index, attributes| - Node.new(index: index, **attributes) + Node.new(index:, **attributes) end.select(&:id).sort_by(&:index) end def deserialize_array(value) value.map.with_index do |attributes, index| - Node.new(index: index, **attributes) + Node.new(index:, **attributes) end.select(&:id).sort_by(&:index) end end diff --git a/app/views/katalyst/navigation/items/edit.html.erb b/app/views/katalyst/navigation/items/edit.html.erb index 8c4c204..cc00979 100644 --- a/app/views/katalyst/navigation/items/edit.html.erb +++ b/app/views/katalyst/navigation/items/edit.html.erb @@ -1,4 +1,4 @@ <%= turbo_frame_tag "navigation--editor--item-frame" do %>

Edit <%= item.model_name.human.downcase %>

- <%= render item.model_name.param_key, item: item, path: menu_item_path(item.menu, item) %> + <%= render item.model_name.param_key, item:, path: menu_item_path(item.menu, item) %> <% end %> diff --git a/app/views/katalyst/navigation/items/new.html.erb b/app/views/katalyst/navigation/items/new.html.erb index f500fa9..fc892b3 100644 --- a/app/views/katalyst/navigation/items/new.html.erb +++ b/app/views/katalyst/navigation/items/new.html.erb @@ -1,4 +1,4 @@ <%= turbo_frame_tag "navigation--editor--item-frame" do %>

New <%= item.model_name.human.downcase %>

- <%= render item.model_name.param_key, item: item, path: menu_items_path(item.menu) %> + <%= render item.model_name.param_key, item:, path: menu_items_path(item.menu) %> <% end %> diff --git a/app/views/katalyst/navigation/menus/_item.html.erb b/app/views/katalyst/navigation/menus/_item.html.erb index 6b74628..ee3ab44 100644 --- a/app/views/katalyst/navigation/menus/_item.html.erb +++ b/app/views/katalyst/navigation/menus/_item.html.erb @@ -1,4 +1,4 @@ -<%= navigation_editor_item item: item do |builder| %> +<%= navigation_editor_item item: do |builder| %>
<%= builder.accordion_actions %> diff --git a/app/views/katalyst/navigation/menus/_new_item.html.erb b/app/views/katalyst/navigation/menus/_new_item.html.erb index 2aa68ea..3e448f8 100644 --- a/app/views/katalyst/navigation/menus/_new_item.html.erb +++ b/app/views/katalyst/navigation/menus/_new_item.html.erb @@ -1,3 +1,3 @@ -<%= navigation_editor_new_item item: item, data: { item_type: item.model_name.param_key } do %> +<%= navigation_editor_new_item item:, data: { item_type: item.model_name.param_key } do %> <%= item.model_name.human %> <% end %> diff --git a/app/views/katalyst/navigation/menus/edit.html.erb b/app/views/katalyst/navigation/menus/edit.html.erb index 3d68c4a..a151dbf 100644 --- a/app/views/katalyst/navigation/menus/edit.html.erb +++ b/app/views/katalyst/navigation/menus/edit.html.erb @@ -20,6 +20,6 @@ <%= form.submit :save %> <%= link_to "Delete", url_for(action: :show), class: "button button-secondary", - data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %> + data: { turbo_method: :delete, turbo_confirm: "Are you sure?" } %>
<% end %> diff --git a/app/views/katalyst/navigation/menus/index.html.erb b/app/views/katalyst/navigation/menus/index.html.erb index c505852..ff4ac54 100644 --- a/app/views/katalyst/navigation/menus/index.html.erb +++ b/app/views/katalyst/navigation/menus/index.html.erb @@ -2,7 +2,7 @@ diff --git a/app/views/katalyst/navigation/menus/show.html.erb b/app/views/katalyst/navigation/menus/show.html.erb index 4a04853..85ed06e 100644 --- a/app/views/katalyst/navigation/menus/show.html.erb +++ b/app/views/katalyst/navigation/menus/show.html.erb @@ -1,15 +1,15 @@ <% content_for :title, menu.title %> -<%= navigation_editor_status_bar menu: menu %> +<%= navigation_editor_status_bar menu: %> -<%= navigation_editor_menu menu: menu do |form| %> +<%= navigation_editor_menu menu: do |form| %>

Title

Url

Actions

- <%= navigation_editor_list menu: menu %> + <%= navigation_editor_list menu: %> <% end %> -<%= render "katalyst/navigation/menus/new_items", menu: menu %> +<%= render "katalyst/navigation/menus/new_items", menu: %> diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb index 8dcb46a..69c67b4 100644 --- a/spec/dummy/app/views/layouts/application.html.erb +++ b/spec/dummy/app/views/layouts/application.html.erb @@ -6,7 +6,7 @@ <%= csrf_meta_tags %> <%= csp_meta_tag %> - + <%= stylesheet_link_tag "application" %> <%= javascript_importmap_tags %> diff --git a/spec/factories/katalyst/navigation/menus.rb b/spec/factories/katalyst/navigation/menus.rb index 21c8864..87dc352 100644 --- a/spec/factories/katalyst/navigation/menus.rb +++ b/spec/factories/katalyst/navigation/menus.rb @@ -10,7 +10,7 @@ end after(:create) do |menu, _context| - menu.items_attributes = menu.items.map.with_index { |item, index| { id: item.id, index: index, depth: 0 } } + menu.items_attributes = menu.items.map.with_index { |item, index| { id: item.id, index:, depth: 0 } } menu.publish! end end diff --git a/spec/models/katalyst/navigation/menu_spec.rb b/spec/models/katalyst/navigation/menu_spec.rb index 0e88a15..53c6316 100644 --- a/spec/models/katalyst/navigation/menu_spec.rb +++ b/spec/models/katalyst/navigation/menu_spec.rb @@ -2,17 +2,17 @@ require "rails_helper" -def transform_tree(nodes, &block) +def transform_tree(nodes, &) output = [] nodes.each do |node| output << yield(node) - output << transform_tree(node.children, &block) if node.children.any? + output << transform_tree(node.children, &) if node.children.any? end output end RSpec.describe Katalyst::Navigation::Menu do - subject(:menu) { create(:katalyst_navigation_menu, items: items) } + subject(:menu) { create(:katalyst_navigation_menu, items:) } let(:first) { build(:katalyst_navigation_link, title: "First", url: "/first") } let(:last) { build(:katalyst_navigation_link, title: "Last", url: "/last") } @@ -112,7 +112,7 @@ def transform_tree(nodes, &block) describe "add link" do let(:update) do - update = create(:katalyst_navigation_link, menu: menu, title: "Update", url: "/update") + update = create(:katalyst_navigation_link, menu:, title: "Update", url: "/update") menu.update(items_attributes: menu.draft_nodes + [{ id: update.id }]) end @@ -126,7 +126,7 @@ def transform_tree(nodes, &block) context "with controller formatted attributes" do let(:update) do - update = create(:katalyst_navigation_link, menu: menu, title: "Update", url: "/update") + update = create(:katalyst_navigation_link, menu:, title: "Update", url: "/update") attributes = { "0" => { id: first.id.to_s, index: "0", depth: "0" }, "1" => { id: update.id.to_s, index: "2", depth: "0" }, "2" => { id: last.id.to_s, index: "1", depth: "0" } } @@ -157,7 +157,7 @@ def transform_tree(nodes, &block) describe "swap two items" do let(:update) do - update = create(:katalyst_navigation_link, menu: menu, title: "Update", url: "/update") + update = create(:katalyst_navigation_link, menu:, title: "Update", url: "/update") menu.update(items_attributes: [{ id: first.id }, { id: update.id }]) end @@ -276,7 +276,7 @@ def transform_tree(nodes, &block) end context "with multiple link changes" do - let(:multiple_links) { create_list(:katalyst_navigation_link, 2, menu: menu) } + let(:multiple_links) { create_list(:katalyst_navigation_link, 2, menu:) } let(:item_attributes) { [{ id: multiple_links.first.id, depth: 0 }, { id: multiple_links.last.id, depth: 1 }] } include_context "when in the future" diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 734dde5..af83092 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -6,7 +6,7 @@ require File.expand_path("dummy/config/environment", __dir__) require "rspec/rails" -Dir[Katalyst::Navigation::Engine.root.join("spec", "support", "**", "*.rb")].sort.each { |f| require f } +Dir[Katalyst::Navigation::Engine.root.join("spec", "support", "**", "*.rb")].each { |f| require f } RSpec.configure do |config| config.use_transactional_fixtures = true diff --git a/spec/requests/katalyst/navigation/items_controller_spec.rb b/spec/requests/katalyst/navigation/items_controller_spec.rb index bc95e5c..289e7d7 100644 --- a/spec/requests/katalyst/navigation/items_controller_spec.rb +++ b/spec/requests/katalyst/navigation/items_controller_spec.rb @@ -35,7 +35,7 @@ describe "GET /admin/navigations/:slug/links/:id/edit" do let(:action) { get katalyst_navigation.edit_menu_item_path(menu, link) } - let(:link) { create(:katalyst_navigation_link, menu: menu) } + let(:link) { create(:katalyst_navigation_link, menu:) } it { is_expected.to be_successful } end @@ -47,7 +47,7 @@ as: :turbo_stream end let(:title) { Faker::Beer.name } - let!(:link) { create(:katalyst_navigation_link, menu: menu, title: title) } + let!(:link) { create(:katalyst_navigation_link, menu:, title:) } let(:link_params) { { title: "A new level" } } it { is_expected.to be_successful } diff --git a/spec/requests/katalyst/navigation/menus_controller_spec.rb b/spec/requests/katalyst/navigation/menus_controller_spec.rb index bb420a6..997310e 100644 --- a/spec/requests/katalyst/navigation/menus_controller_spec.rb +++ b/spec/requests/katalyst/navigation/menus_controller_spec.rb @@ -7,7 +7,7 @@ shared_context "with draft" do before do - link = create(:navigation_link, menu: menu) + link = create(:navigation_link, menu:) menu.update!(items_attributes: [{ id: link.id, depth: 0, index: 0 }]) end end @@ -60,13 +60,13 @@ end describe "PATCH /navigation/menus/:id" do - let(:action) { patch katalyst_navigation.menu_path(menu), params: { menu: menu_params, commit: commit } } + let(:action) { patch katalyst_navigation.menu_path(menu), params: { menu: menu_params, commit: } } let(:menu) { create(:katalyst_navigation_menu) } let(:menu_params) do { items_attributes: [ - { id: create(:navigation_link, menu: menu).id, depth: 0, index: 0 }, - { id: create(:navigation_link, menu: menu).id, depth: 1, index: 1 }, + { id: create(:navigation_link, menu:).id, depth: 0, index: 0 }, + { id: create(:navigation_link, menu:).id, depth: 1, index: 1 }, ], } end