Skip to content

Commit

Permalink
Get rid of top-level method definitions, to appease new rubocop warning
Browse files Browse the repository at this point in the history
  • Loading branch information
denny committed Jun 2, 2021
1 parent cfe66bc commit 327f92e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
46 changes: 24 additions & 22 deletions plugins/ShinyCMS/config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,36 @@
Rails.application.config.assets.paths << ShinyCMS::Engine.root.join( 'app/assets/javascript' )

# Add theme images and stylesheets to the asset load path
def add_all_themes_to_asset_load_path
available_themes.each do |theme_name|
add_theme_to_asset_load_path( theme_name )
class ShinyCMS::ThemeAssetsSetup
def add_all_themes_to_asset_load_path
available_themes.each do |theme_name|
add_theme_to_asset_load_path( theme_name )
end
end
end

def available_themes
Dir[ 'themes/*' ].collect { |name| name.sub( 'themes/', '' ) }
end
def available_themes
Dir[ 'themes/*' ].collect { |name| name.sub( 'themes/', '' ) }
end

def add_theme_to_asset_load_path( theme_name )
add_theme_images_to_asset_load_path( theme_name )
add_theme_styles_to_asset_load_path( theme_name )
end
def add_theme_to_asset_load_path( theme_name )
add_theme_images_to_asset_load_path( theme_name )
add_theme_styles_to_asset_load_path( theme_name )
end

def add_theme_images_to_asset_load_path( theme_name )
images_dir = Rails.root.join "themes/#{theme_name}/images"
return unless Dir.exist? images_dir
def add_theme_images_to_asset_load_path( theme_name )
images_dir = Rails.root.join "themes/#{theme_name}/images"
return unless Dir.exist? images_dir

Rails.application.config.assets.paths << images_dir
end
Rails.application.config.assets.paths << images_dir
end

def add_theme_styles_to_asset_load_path( theme_name )
stylesheets_dir = Rails.root.join "themes/#{theme_name}/stylesheets"
return unless Dir.exist? stylesheets_dir
def add_theme_styles_to_asset_load_path( theme_name )
stylesheets_dir = Rails.root.join "themes/#{theme_name}/stylesheets"
return unless Dir.exist? stylesheets_dir

Rails.application.config.assets.paths << stylesheets_dir
Rails.application.config.assets.precompile += %W[ #{theme_name}.css ]
Rails.application.config.assets.paths << stylesheets_dir
Rails.application.config.assets.precompile += %W[ #{theme_name}.css ]
end
end

add_all_themes_to_asset_load_path
ShinyCMS::ThemeAssetsSetup.new.add_all_themes_to_asset_load_path
12 changes: 4 additions & 8 deletions plugins/ShinyCMS/config/routes/tools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
mount LetterOpenerWeb::Engine, at: '/dev/tools/outbox' if Rails.env.development?

# Sidekiq Web provides a web dashboard for Sidekiq jobs and queues
def sidekiq_web_enabled?
ENV['DISABLE_SIDEKIQ_WEB']&.downcase != 'true'
end
sidekiq_web_enabled = ( ENV['DISABLE_SIDEKIQ_WEB']&.downcase != 'true' )

if sidekiq_web_enabled?
if sidekiq_web_enabled
require 'sidekiq/web'
require 'sidekiq-status/web'

Expand All @@ -35,11 +33,9 @@ def sidekiq_web_enabled?
end

# Coverband provides a web UI for viewing code usage information
def coverband_web_ui_enabled?
ENV['DISABLE_COVERBAND_WEB_UI']&.downcase != 'true'
end
coverband_web_ui_enabled = ( ENV['DISABLE_COVERBAND_WEB_UI']&.downcase != 'true' )

if coverband_web_ui_enabled?
if coverband_web_ui_enabled
authenticate :user, ->( user ) { user.can? :use_coverband, :tools } do
mount Coverband::Reporters::Web.new, at: '/admin/tools/coverband', as: :coverband unless Rails.env.test?
end
Expand Down
17 changes: 9 additions & 8 deletions plugins/ShinyCMS/db/seeds/capabilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
seeder.seed_standard_admin_capabilities( category: :admin_users )

# Most of the capabilities to be set here are not the standard four, so ...

def add_capabilities( capability_data )
capability_data.each_key do |category_name|
category = ShinyCMS::CapabilityCategory.find_or_create_by!( name: category_name )

capability_data[ category_name ].each do |capability_name|
category.capabilities.find_or_create_by( name: capability_name )
class ShinyCMS::CapabilitySetup
def add( capability_data )
capability_data.each_key do |category_name|
category = ShinyCMS::CapabilityCategory.find_or_create_by!( name: category_name )

capability_data[ category_name ].each do |capability_name|
category.capabilities.find_or_create_by( name: capability_name )
end
end
end
end

add_capabilities(
ShinyCMS::CapabilitySetup.new.add(
{
general: %w[ view_admin_area view_admin_toolbar ],
tools: %w[ use_blazer use_coverband use_letter_opener_web use_rails_email_preview use_sidekiq_web ],
Expand Down

0 comments on commit 327f92e

Please sign in to comment.