Class: RubyCms::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- RubyCms::Engine
- Defined in:
- lib/ruby_cms/engine.rb
Class Method Summary collapse
- .analytics_icon_path ⇒ Object
- .compile_admin_css(dest_path) ⇒ Object
- .content_blocks_icon_path ⇒ Object
- .dashboard_icon_path ⇒ Object
- .display_export_results(export_data) ⇒ Object
- .display_export_summary(summary) ⇒ Object
- .display_import_results(import_data, import_after) ⇒ Object
- .display_import_summary(summary) ⇒ Object
- .display_sync_summary(result, import_after) ⇒ Object
- .extract_email_from_args(args) ⇒ Object
- .find_user_by_email(email) ⇒ Object
- .find_user_by_email_address(user_class, email) ⇒ Object
- .find_user_by_email_column(user_class, email) ⇒ Object
- .grant_admin_permissions_to_admin_users ⇒ Object
- .grant_manage_admin_permission(user, email) ⇒ Object
- .parse_import_options ⇒ Object
- .parse_locales_dir(locales_dir_arg) ⇒ Object
- .permissions_icon_path ⇒ Object
- .register_main_nav_items ⇒ Object
- .register_settings_nav_items ⇒ Object
- .settings_icon_path ⇒ Object
- .users_icon_path ⇒ Object
- .validate_email_present(email) ⇒ Object
- .validate_user_found(user, email) ⇒ Object
- .visitor_errors_icon_path ⇒ Object
- .visual_editor_icon_path ⇒ Object
Class Method Details
.analytics_icon_path ⇒ Object
248 249 250 251 252 253 |
# File 'lib/ruby_cms/engine.rb', line 248 def self.analytics_icon_path '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M3 3v18h18"></path>' \ '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M7 13l3-3 3 2 4-5"></path>' end |
.compile_admin_css(dest_path) ⇒ Object
255 256 257 258 259 260 261 262 |
# File 'lib/ruby_cms/engine.rb', line 255 def self.compile_admin_css(dest_path) gem_root = begin root rescue StandardError Pathname.new(File.("../..", __dir__)) end RubyCms::CssCompiler.compile(gem_root, dest_path) end |
.content_blocks_icon_path ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/ruby_cms/engine.rb', line 148 def self.content_blocks_icon_path # Heroicons DocumentDuplicateIcon (outline) '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M8 7v8a2 2 0 002 2h6M8 7V5a2 2 0 012-2h4.586a1 1 0 01.707.293l4.414 4.414' \ 'a1 1 0 01.293.707V15a2 2 0 01-2 2h-2M8 7H6a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 ' \ '0 002-2v-2"></path>' end |
.dashboard_icon_path ⇒ Object
141 142 143 144 145 146 |
# File 'lib/ruby_cms/engine.rb', line 141 def self.dashboard_icon_path # Heroicons HomeIcon (outline) '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3' \ 'm-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"></path>' end |
.display_export_results(export_data) ⇒ Object
483 484 485 486 487 488 489 |
# File 'lib/ruby_cms/engine.rb', line 483 def self.display_export_results(export_data) $stdout.puts "Sync complete!" $stdout.puts "\nExport summary:" export_data.each do |locale, count| $stdout.puts " #{locale}: #{count} block(s) updated" end end |
.display_export_summary(summary) ⇒ Object
453 454 455 456 457 458 459 460 461 462 463 464 465 |
# File 'lib/ruby_cms/engine.rb', line 453 def self.display_export_summary(summary) if summary.empty? puts "No content blocks found to export." # rubocop:disable Rails/Output else puts "Exported content blocks to locale files:" # rubocop:disable Rails/Output summary.each do |locale, count| # rubocop:disable Rails/Output puts " #{locale}: #{count} block(s) updated " \ "in config/locales/#{locale}.yml" # rubocop:enable Rails/Output end end end |
.display_import_results(import_data, import_after) ⇒ Object
491 492 493 494 495 496 497 498 |
# File 'lib/ruby_cms/engine.rb', line 491 def self.display_import_results(import_data, import_after) return unless import_after && import_data.any? $stdout.puts "\nImport summary:" $stdout.puts " Created: #{import_data[:created]}" $stdout.puts " Updated: #{import_data[:updated]}" $stdout.puts " Skipped: #{import_data[:skipped]}" end |
.display_import_summary(summary) ⇒ Object
467 468 469 470 471 472 473 474 475 476 |
# File 'lib/ruby_cms/engine.rb', line 467 def self.display_import_summary(summary) $stdout.puts "Import summary:" $stdout.puts " Created: #{summary[:created]}" $stdout.puts " Updated: #{summary[:updated]}" $stdout.puts " Skipped: #{summary[:skipped]}" return unless summary[:errors].any? $stdout.puts " Errors:" summary[:errors].each {|e| $stdout.puts " - #{e}" } end |
.display_sync_summary(result, import_after) ⇒ Object
478 479 480 481 |
# File 'lib/ruby_cms/engine.rb', line 478 def self.display_sync_summary(result, import_after) display_export_results(result[:export]) display_import_results(result[:import], import_after) if import_after end |
.extract_email_from_args(args) ⇒ Object
390 391 392 |
# File 'lib/ruby_cms/engine.rb', line 390 def self.extract_email_from_args(args) args[:email] || ENV["email"] || ENV.fetch("EMAIL", nil) end |
.find_user_by_email(email) ⇒ Object
402 403 404 405 406 407 |
# File 'lib/ruby_cms/engine.rb', line 402 def self.find_user_by_email(email) user_class = Rails.application.config.ruby_cms.user_class_name .constantize find_user_by_email_address(user_class, email) || find_user_by_email_column(user_class, email) end |
.find_user_by_email_address(user_class, email) ⇒ Object
409 410 411 412 413 |
# File 'lib/ruby_cms/engine.rb', line 409 def self.find_user_by_email_address(user_class, email) return unless user_class.column_names.include?("email_address") user_class.find_by(email_address: email) end |
.find_user_by_email_column(user_class, email) ⇒ Object
415 416 417 418 419 |
# File 'lib/ruby_cms/engine.rb', line 415 def self.find_user_by_email_column(user_class, email) return unless user_class.column_names.include?("email") user_class.find_by(email:) end |
.grant_admin_permissions_to_admin_users ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/ruby_cms/engine.rb', line 375 def self. return unless defined?(::User) && User.column_names.include?("admin") = RubyCms::Permission.all_keys = RubyCms::Permission.where(key: ).index_by(&:key) User.where(admin: true).find_each do |u| .each do |key| perm = [key] next if perm.nil? RubyCms::UserPermission.find_or_create_by!(user: u, permission: perm) end end end |
.grant_manage_admin_permission(user, email) ⇒ Object
428 429 430 431 432 433 434 435 436 437 |
# File 'lib/ruby_cms/engine.rb', line 428 def self.(user, email) RubyCms::Permission.ensure_defaults! RubyCms::Permission.all_keys.each do |key| perm = RubyCms::Permission.find_by(key:) next unless perm RubyCms::UserPermission.find_or_create_by!(user: user, permission: perm) end puts "Granted full admin permissions to #{email}" # rubocop:disable Rails/Output end |
.parse_import_options ⇒ Object
445 446 447 448 449 450 451 |
# File 'lib/ruby_cms/engine.rb', line 445 def self. { create_missing: ENV["create_missing"] != "false", update_existing: ENV["update_existing"] != "false", published: ENV["published"] == "true" } end |
.parse_locales_dir(locales_dir_arg) ⇒ Object
439 440 441 442 443 |
# File 'lib/ruby_cms/engine.rb', line 439 def self.parse_locales_dir(locales_dir_arg) return nil unless locales_dir_arg.presence Pathname.new(locales_dir_arg) end |
.permissions_icon_path ⇒ Object
233 234 235 236 237 238 239 |
# File 'lib/ruby_cms/engine.rb', line 233 def self. # Heroicons ShieldCheckIcon (outline) '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M9 12l2 2 4-4m5.618-4.016A11.955 11.955 0 0112 2.944a11.955 11.955 0 01' \ '-8.618 3.04A12.02 12.02 0 003 9c0 5.591 3.824 10.29 9 11.622 5.176-1.332 ' \ '9-6.03 9-11.622 0-1.042-.133-2.052-.382-3.016z"></path>' end |
.register_main_nav_items ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ruby_cms/engine.rb', line 111 def self.register_main_nav_items RubyCms.nav_register( key: :dashboard, label: "Dashboard", path: lambda(&:ruby_cms_admin_root_path), icon: dashboard_icon_path, section: RubyCms::NAV_SECTION_MAIN, permission: :manage_admin, order: 1 ) RubyCms.nav_register( key: :visual_editor, label: "Visual editor", path: lambda(&:ruby_cms_admin_visual_editor_path), icon: visual_editor_icon_path, section: RubyCms::NAV_SECTION_MAIN, permission: :manage_content_blocks, order: 2 ) RubyCms.nav_register( key: :content_blocks, label: "Content blocks", path: lambda(&:ruby_cms_admin_content_blocks_path), icon: content_blocks_icon_path, section: RubyCms::NAV_SECTION_MAIN, permission: :manage_content_blocks, order: 3 ) end |
.register_settings_nav_items ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ruby_cms/engine.rb', line 163 def self.register_settings_nav_items RubyCms.nav_register( key: :analytics, label: "Analytics", path: lambda(&:ruby_cms_admin_analytics_path), section: RubyCms::NAV_SECTION_BOTTOM, icon: analytics_icon_path, permission: :manage_analytics, order: 1 ) RubyCms.nav_register( key: :permissions, label: "Permissions", path: lambda(&:ruby_cms_admin_permissions_path), section: RubyCms::NAV_SECTION_BOTTOM, icon: , permission: :manage_permissions, order: 2 ) RubyCms.nav_register( key: :visitor_errors, label: "Visitor errors", path: lambda(&:ruby_cms_admin_visitor_errors_path), section: RubyCms::NAV_SECTION_BOTTOM, icon: visitor_errors_icon_path, permission: :manage_visitor_errors, order: 3 ) RubyCms.nav_register( key: :users, label: "Users", path: lambda(&:ruby_cms_admin_users_path), section: RubyCms::NAV_SECTION_BOTTOM, icon: users_icon_path, permission: :manage_permissions, order: 4 ) RubyCms.nav_register( key: :settings, label: "Settings", path: lambda(&:ruby_cms_admin_settings_path), section: RubyCms::NAV_SECTION_BOTTOM, icon: settings_icon_path, permission: :manage_admin, order: 5 ) end |
.settings_icon_path ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/ruby_cms/engine.rb', line 211 def self.settings_icon_path # Heroicons Cog6ToothIcon (outline) '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M9.594 3.94c.09-.542.56-.94 1.11-.94h2.593c.55 0 1.02.398 1.11.94l.213 ' \ '1.281c.063.374.313.686.645.87.074.04.147.083.22.127.324.196.72.257 1.075.124l1.217-.456a1.125 ' \ '1.125 0 011.37.49l1.296 2.247a1.125 1.125 0 01-.26 1.431l-1.003.827c-.293.24-.438.613-.431.992a6.759 ' \ '6.759 0 010 .255c-.007.378.138.75.43.99l1.005.828c.424.35.534.954.26 1.43l-1.298 2.247a1.125 1.125 ' \ '0 01-1.369.491l-1.217-.456c-.355-.133-.75-.072-1.076.124a6.57 6.57 0 01-.22.128c-.331.183-.581.495-.644.869l-.213 ' \ '1.28c-.09.543-.56.941-1.11.941h-2.594c-.55 0-1.02-.398-1.11-.94l-.213-1.281c-.062-.374-.312-.686-.644-.87a6.52 ' \ '6.52 0 01-.22-.127c-.325-.196-.72-.257-1.076-.124l-1.217.456a1.125 1.125 0 01-1.369-.49l-1.297-2.247a1.125 ' \ '1.125 0 01.26-1.431l1.004-.827c.292-.24.437-.613.43-.992a6.932 6.932 0 010-.255c.007-.378-.138-.75-.43-.99l-1.004-.828a1.125 ' \ '1.125 0 01-.26-1.43l1.297-2.247a1.125 1.125 0 011.37-.491l1.216.456c.356.133.751.072 1.076-.124.072-.044.146-.087.22-.128.332-.183.582-.495.644-.869l.214-1.281z"></path>' \ '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>' end |
.users_icon_path ⇒ Object
241 242 243 244 245 246 |
# File 'lib/ruby_cms/engine.rb', line 241 def self.users_icon_path # Heroicons UserGroupIcon (outline) '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 ' \ '00-9-5.197M13 7a4 4 0 11-8 0 4 4 0 018 0z"></path>' end |
.validate_email_present(email) ⇒ Object
394 395 396 397 398 399 400 |
# File 'lib/ruby_cms/engine.rb', line 394 def self.validate_email_present(email) return if email.present? warn "Usage: rails ruby_cms:grant_manage_admin " \ "[email protected]" raise "Email is required" end |
.validate_user_found(user, email) ⇒ Object
421 422 423 424 425 426 |
# File 'lib/ruby_cms/engine.rb', line 421 def self.validate_user_found(user, email) return if user warn "User not found: #{email}" raise "User not found: #{email}" end |
.visitor_errors_icon_path ⇒ Object
226 227 228 229 230 231 |
# File 'lib/ruby_cms/engine.rb', line 226 def self.visitor_errors_icon_path # Heroicons ExclamationTriangleIcon (outline) '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 ' \ '4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path>' end |
.visual_editor_icon_path ⇒ Object
156 157 158 159 160 161 |
# File 'lib/ruby_cms/engine.rb', line 156 def self.visual_editor_icon_path # Heroicons PencilSquareIcon (outline) '<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" ' \ 'd="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 ' \ '0 012.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path>' end |