Skip to content

Commit b9115b4

Browse files
committed
Rubocop fixes
1 parent 64c4db3 commit b9115b4

32 files changed

+134
-77
lines changed

app/builders/better_together/navigation_builder.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def build_better_together # rubocop:todo Metrics/MethodLength
6868
end
6969
end
7070

71-
def build_footer # rubocop:todo Metrics/MethodLength
71+
def build_footer # rubocop:todo Metrics/MethodLength, Metrics/AbcSize
7272
I18n.with_locale(:en) do # rubocop:todo Metrics/BlockLength
7373
# Create Platform Footer Pages
7474
footer_pages = ::BetterTogether::Page.create!(
@@ -176,7 +176,7 @@ def build_header # rubocop:todo Metrics/MethodLength
176176
end
177177

178178
# rubocop:todo Metrics/MethodLength
179-
def build_host # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
179+
def build_host # rubocop:todo Metrics/MethodLength
180180
I18n.with_locale(:en) do # rubocop:todo Metrics/BlockLength
181181
# Create Platform Header Host Navigation Area and its Navigation Items
182182
::BetterTogether::NavigationArea.create! do |area| # rubocop:todo Metrics/BlockLength

app/concerns/better_together/translatable.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ module Translatable
1818
}
1919

2020
def self.localized_attribute_list
21-
localized_attributes = self.mobility_attributes.map do |attribute|
21+
localized_attributes = mobility_attributes.map do |attribute|
2222
I18n.available_locales.map do |locale|
2323
:"#{attribute}_#{locale}"
2424
end
2525
end
26-
26+
2727
localized_attributes.flatten
2828
end
2929
end

app/controllers/better_together/content/blocks_controller.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
24
module Content
5+
# CRUD for content blocks independently of pages
36
class BlocksController < ApplicationController
47
before_action :authenticate_user!
58
before_action :set_block, only: %i[show edit update destroy]
@@ -28,7 +31,8 @@ def update
2831
redirect_to edit_content_block_path(@block), notice: 'Block was successfully updated.'
2932
else
3033
format.turbo_stream do
31-
render turbo_stream: turbo_stream.replace(helpers.dom_id(@block, 'form'), partial: 'form', locals: { block: @block } )
34+
render turbo_stream: turbo_stream.replace(helpers.dom_id(@block, 'form'), partial: 'form',
35+
locals: { block: @block })
3236
end
3337
end
3438
end
@@ -37,9 +41,7 @@ def update
3741
def new
3842
@block = BetterTogether::Content::Block.new(type: params[:block_type])
3943

40-
respond_to do |format|
41-
format.html
42-
end
44+
respond_to(&:html)
4345
end
4446

4547
def destroy

app/controllers/better_together/content/page_blocks_controller.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
24
module Content
5+
# CRUD for page blocks
36
class PageBlocksController < ApplicationController
47
before_action :authenticate_user!
58
before_action :set_page
69

710
def new
811
@page_block = @page.page_blocks.build
9-
12+
1013
@page_block.build_block(type: params[:block_type]) # Build the new PageBlock and associated Block
1114

1215
respond_to do |format|
1316
format.html
1417
format.turbo_stream do
15-
render turbo_stream: turbo_stream.append("blocks-list", partial: "better_together/content/page_blocks/form_fields", locals: { page_block: @page_block })
18+
render turbo_stream: turbo_stream.append('blocks-list',
19+
# rubocop:todo Layout/LineLength
20+
partial: 'better_together/content/page_blocks/form_fields', locals: { page_block: @page_block })
21+
# rubocop:enable Layout/LineLength
1622
end
1723
end
1824
end
1925

20-
def destroy
26+
def destroy # rubocop:todo Metrics/AbcSize
2127
@page_block = @page.page_blocks.find_by(id: params[:id]) || @page.page_blocks.build
2228
@page_block.destroy if @page_block.persisted?
2329

@@ -31,7 +37,8 @@ def destroy
3137
private
3238

3339
def form_for_page_block(page_block)
34-
view_context.form_with(model: [page_block.page, page_block], url: new_page_page_block_path(page_block.page), local: true)
40+
view_context.form_with(model: [page_block.page, page_block], url: new_page_page_block_path(page_block.page),
41+
local: true)
3542
end
3643

3744
def set_page

app/controllers/better_together/pages_controller.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@ def set_page
106106
handle404
107107
end
108108

109-
def page_params
109+
def page_params # rubocop:todo Metrics/MethodLength
110110
params.require(:page).permit(
111111
:meta_description, :keywords, :published_at,
112112
:privacy, :layout, :template, *Page.localized_attribute_list,
113113
page_blocks_attributes: [
114114
:id, :position, :_destroy,
115-
block_attributes: [
115+
{ block_attributes: [
116116
:id, :type, :media, :identifier, :_destroy,
117117
*BetterTogether::Content::Block.localized_block_attributes,
118118
*BetterTogether::Content::Block.storext_definitions.keys
119-
]
119+
] }
120120
]
121121
)
122122
end

app/helpers/better_together/content/blocks_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
# frozen_string_literal: true
2+
13
module BetterTogether
24
module Content
5+
# Helpers for Content Blocks
36
module BlocksHelper
47
# Returns an array of acceptable image file types
58
def acceptable_image_file_types

app/helpers/better_together/navigation_items_helper.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ def nav_link_classes(navigation_item)
3737
def platform_host_nav_items
3838
# Preload navigation items and their translations in a single query
3939
Mobility.with_locale(current_locale) do
40-
# rubocop:todo Layout/LineLength
4140
@platform_host_nav_area ||= ::BetterTogether::NavigationArea.find_by(identifier: 'platform-host')
42-
# rubocop:enable Layout/LineLength
4341
@platform_host_nav_items ||= @platform_host_nav_area.top_level_nav_items_includes_children || []
4442
end
4543
end

app/helpers/better_together/translatable_fields_helper.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1+
# frozen_string_literal: true
12

23
module BetterTogether
4+
# Helps with rendering content for translatable fields
35
module TranslatableFieldsHelper
46
# Helper to render a translation tab button
5-
def translation_tab_button(attribute:, locale:, temp_id:, model:)
7+
def translation_tab_button(attribute:, locale:, temp_id:, model:) # rubocop:todo Metrics/MethodLength
68
locale_attribute = "#{attribute}_#{locale}"
79
unique_locale_attribute = "#{locale_attribute}_#{temp_id}"
810
translation_present = model.public_send(locale_attribute).present?
9-
11+
1012
content_tag(:li, class: 'nav-item', role: 'presentation',
11-
data: { attribute: attribute, translation_target: 'tab', locale: locale }) do
13+
data: { attribute:, translation_target: 'tab', locale: }) do
1214
content_tag(:button,
1315
id: "#{unique_locale_attribute}-tab",
14-
class: ['nav-link', ('active' if locale.to_s == I18n.locale.to_s),
16+
class: ['nav-link', ('active' if locale.to_s == I18n.locale.to_s),
1517
('text-success' if translation_present)],
1618
data: { bs_toggle: 'tab',
1719
bs_target: "##{unique_locale_attribute}-field",
1820
action: 'click->translation#syncLocaleAcrossFields',
19-
locale: locale,
21+
locale:,
2022
translation_target: 'tabButton' },
2123
role: 'tab',
2224
type: 'button',
@@ -33,9 +35,10 @@ def translation_indicator(translation_present)
3335
tag.i(class: 'fas fa-check-circle ms-2', aria_hidden: 'true', title: 'Translation available') +
3436
content_tag(:span, 'Translation available', class: 'visually-hidden')
3537
else
36-
tag.i(class: 'fas fa-exclamation-circle text-muted ms-2', aria_hidden: 'true', title: 'No translation available') +
38+
tag.i(class: 'fas fa-exclamation-circle text-muted ms-2', aria_hidden: 'true',
39+
title: 'No translation available') +
3740
content_tag(:span, 'No translation available', class: 'visually-hidden')
3841
end
3942
end
4043
end
41-
end
44+
end
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
12

23
module BetterTogether
4+
# Robust content editing for the Community Engine
35
module Content
46
def self.table_name_prefix
57
'better_together_content_'
68
end
79
end
8-
end
10+
end

app/models/better_together/content/block.rb

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# frozen_string_literal: true
2+
23
require 'storext'
34

45
module BetterTogether
56
module Content
7+
# Base class from which all other content blocks types inherit
68
class Block < ApplicationRecord
79
include ::Storext.model
810

@@ -13,7 +15,7 @@ class Block < ApplicationRecord
1315
aria_label String, default: ''
1416
aria_hidden Boolean, default: false
1517
aria_describedby String, default: ''
16-
aria_live String, default: 'polite' # 'polite' or 'assertive'
18+
aria_live String, default: 'polite' # 'polite' or 'assertive'
1719
aria_role String, default: ''
1820
aria_controls String, default: ''
1921
aria_expanded Boolean, default: false
@@ -52,27 +54,30 @@ class Block < ApplicationRecord
5254
length: { maximum: 100 },
5355
allow_blank: true
5456

55-
def identifier= arg
56-
super arg.parameterize
57+
def identifier=(arg)
58+
super(arg.parameterize)
5759
end
5860

5961
def to_partial_path
6062
"better_together/content/blocks/#{block_name}"
6163
end
6264

6365
def self.block_name
64-
self.name.demodulize.underscore
66+
name.demodulize.underscore
6567
end
6668

6769
def self.load_all_subclasses
70+
# rubocop:todo Layout/LineLength
6871
[::BetterTogether::Content::RichText, ::BetterTogether::Content::Image].each(&:connection) # Add all known subclasses here
72+
# rubocop:enable Layout/LineLength
6973
end
7074

7175
def self.localized_block_attributes
7276
list = []
7377

7478
descendants.each do |descendant|
7579
next unless descendant.respond_to? :localized_attribute_list
80+
7681
list += descendant.localized_attribute_list
7782
end
7883

@@ -84,9 +89,12 @@ def block_name
8489
end
8590

8691
def to_s
87-
"#{block_name} - #{persisted? ? (identifier.present? ? identifier : id.split('-').first) : 'new'}"
92+
"#{block_name} - #{if persisted?
93+
identifier.present? ? identifier : id.split('-').first
94+
else
95+
'new'
96+
end}"
8897
end
89-
9098
end
9199
end
92100
end

0 commit comments

Comments
 (0)