module Para::SeoTools::Skeleton
Public Class Methods
build(load_skeleton: false)
click to toggle source
# File lib/para/seo_tools/skeleton.rb, line 34 def self.build(load_skeleton: false) return if migrating? return unless ActiveRecord::Base.connection.table_exists?(Para::SeoTools::Page.table_name) load if load_skeleton log " * Building app skeleton pages ..." site_options = options.merge(enable_logging: enable_logging) self.site = Skeleton::Site.new(site_options) # Evaluate the configuration block site.instance_exec(&config) # Save remaining pages and remove old pages ActiveRecord::Base.transaction do site.save # Delete pages not in skeleton destroy_deleted_pages! end end
destroy_deleted_pages!()
click to toggle source
# File lib/para/seo_tools/skeleton.rb, line 66 def self.destroy_deleted_pages! pages = Para::SeoTools::Page.where.not(id: site.saved_pages_ids) log " * Destroying old pages ..." pages.delete_all end
draw(lazy: false, **options, &block)
click to toggle source
# File lib/para/seo_tools/skeleton.rb, line 28 def self.draw(lazy: false, **options, &block) self.config = block self.options = options build unless lazy end
load()
click to toggle source
# File lib/para/seo_tools/skeleton.rb, line 19 def self.load # Ensure routes are loaded to allow skeleton to call routes name helpers Rails.application.reload_routes! # Skeleton file path skeleton_path = Rails.root.join('config', 'skeleton.rb') # Load the skeleton file require skeleton_path if File.exists?(skeleton_path) end
log(message)
click to toggle source
Log messages when you're not in rails
# File lib/para/seo_tools/skeleton.rb, line 74 def self.log(message) Rails.logger.info(message) if enable_logging || !$0.end_with?('rails') end
migrating?()
click to toggle source
Handle Rails 4 and 5
# File lib/para/seo_tools/skeleton.rb, line 58 def self.migrating? if ActiveRecord::Migrator.respond_to?(:needs_migration?) ActiveRecord::Migrator.needs_migration? else ActiveRecord::Base.connection.migration_context.needs_migration? end end
with_logging(&block)
click to toggle source
# File lib/para/seo_tools/skeleton.rb, line 12 def self.with_logging(&block) self.enable_logging = true block.call ensure self.enable_logging = false end