Skip to content

Commit

Permalink
Rubocop fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
sfnelson committed Dec 13, 2023
1 parent aa3ff4a commit 60cb9a3
Show file tree
Hide file tree
Showing 23 changed files with 64 additions and 64 deletions.
6 changes: 3 additions & 3 deletions app/controllers/katalyst/navigation/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions app/controllers/katalyst/navigation/menus_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,7 +29,7 @@ def new
def edit
menu = Menu.find(params[:id])

render locals: { menu: menu }
render locals: { menu: }
end

def create
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions app/helpers/katalyst/navigation/editor/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/katalyst/navigation/editor/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/katalyst/navigation/editor/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/katalyst/navigation/editor/new_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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

Expand Down
12 changes: 6 additions & 6 deletions app/helpers/katalyst/navigation/editor/status_bar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ 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)
concat actions
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
Expand All @@ -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

Expand Down
18 changes: 9 additions & 9 deletions app/helpers/katalyst/navigation/editor_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions app/helpers/katalyst/navigation/frontend_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand All @@ -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|
Expand Down
4 changes: 2 additions & 2 deletions app/models/katalyst/navigation/types/nodes_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/katalyst/navigation/items/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= turbo_frame_tag "navigation--editor--item-frame" do %>
<h3 class="heading-three">Edit <%= item.model_name.human.downcase %></h3>
<%= 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 %>
2 changes: 1 addition & 1 deletion app/views/katalyst/navigation/items/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= turbo_frame_tag "navigation--editor--item-frame" do %>
<h3 class="heading-three">New <%= item.model_name.human.downcase %></h3>
<%= 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 %>
2 changes: 1 addition & 1 deletion app/views/katalyst/navigation/menus/_item.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= navigation_editor_item item: item do |builder| %>
<%= navigation_editor_item item: do |builder| %>
<div class="tree" data-invisible="<%= !item.visible? %>">
<%= builder.accordion_actions %>

Expand Down
2 changes: 1 addition & 1 deletion app/views/katalyst/navigation/menus/_new_item.html.erb
Original file line number Diff line number Diff line change
@@ -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 %>
2 changes: 1 addition & 1 deletion app/views/katalyst/navigation/menus/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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?" } %>
</div>
<% end %>
2 changes: 1 addition & 1 deletion app/views/katalyst/navigation/menus/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<nav class="index-table-actions">
<div class="item-actions">
<%= link_to "Add", [:new, :menu], class: "button button--primary" %>
<%= link_to "Add", %i[new menu], class: "button button--primary" %>
</div>
</nav>

Expand Down
8 changes: 4 additions & 4 deletions app/views/katalyst/navigation/menus/show.html.erb
Original file line number Diff line number Diff line change
@@ -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| %>
<div role="rowheader">
<h4>Title</h4>
<h4>Url</h4>
<h4>Actions</h4>
</div>

<%= 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: %>
2 changes: 1 addition & 1 deletion spec/dummy/app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

<link rel="stylesheet" href="https://unpkg.com/modern-css-reset/dist/reset.min.css" />
<link rel="stylesheet" href="https://unpkg.com/modern-css-reset/dist/reset.min.css">
<%= stylesheet_link_tag "application" %>
<%= javascript_importmap_tags %>
</head>
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/katalyst/navigation/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions spec/models/katalyst/navigation/menu_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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") }
Expand Down Expand Up @@ -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

Expand All @@ -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" } }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 60cb9a3

Please sign in to comment.