Skip to content

Commit

Permalink
Remove a variety of deprecated code paths for v2
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Mar 29, 2024
1 parent 4989ba7 commit 5e70380
Show file tree
Hide file tree
Showing 26 changed files with 89 additions and 255 deletions.
34 changes: 13 additions & 21 deletions bridgetown-builder/lib/bridgetown-builder/dsl/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,22 @@ def helpers
@helpers # could be nil
end

def helper(helper_name, method_name = nil, helpers_scope: false, &block)
def helper(helper_name, method_name = nil, &block)
m = Module.new

if block && helpers_scope
Deprecator.deprecation_message(
"The `helpers_scope' functionality is deprecated. Use the `helpers' builder " \
"method to access the helpers scope in your plugin."
)
m.define_method helper_name, &block
else
builder_self = self
method_name ||= helper_name unless block
unless method_name
method_name = :"__helper_#{helper_name}"
builder_self.define_singleton_method(method_name) do |*args, **kwargs, &block2|
block.(*args, **kwargs, &block2)
end
builder_self = self
method_name ||= helper_name unless block
unless method_name
method_name = :"__helper_#{helper_name}"
builder_self.define_singleton_method(method_name) do |*args, **kwargs, &block2|
block.(*args, **kwargs, &block2)
end
m.define_method helper_name do |*args, **kwargs, &block2|
prev_var = builder_self.instance_variable_get(:@helpers)
builder_self.instance_variable_set(:@helpers, self)
builder_self.send(method_name, *args, **kwargs, &block2).tap do
builder_self.instance_variable_set(:@helpers, prev_var)
end
end
m.define_method helper_name do |*args, **kwargs, &block2|
prev_var = builder_self.instance_variable_get(:@helpers)
builder_self.instance_variable_set(:@helpers, self)
builder_self.send(method_name, *args, **kwargs, &block2).tap do
builder_self.instance_variable_set(:@helpers, prev_var)
end
end

Expand Down
17 changes: 1 addition & 16 deletions bridgetown-builder/lib/bridgetown-builder/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,7 @@ def initialize(name = nil, current_site = nil)
self.name = name || self.class.name
self.site = current_site || Bridgetown::Current.site

self.config = if defined?(self.class::CONFIG_DEFAULTS)
Deprecator.deprecation_message(
"Using `CONFIG_DEFAULTS' in your builder is deprecated. " \
"Switch to defining config data via an initializer instead."
)
Bridgetown::Utils.deep_merge_hashes(
self.class::CONFIG_DEFAULTS.with_dot_access, site.config
)
else
site.config
end
end

def doc(*)
raise Bridgetown::Errors::FatalException,
"The `doc' method has been removed. Please use the `new_resource' builder DSL instead"
self.config = site.config
end
end
end
Expand Down
34 changes: 0 additions & 34 deletions bridgetown-builder/test/test_config_defaults.rb

This file was deleted.

13 changes: 1 addition & 12 deletions bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def load_tasks
unless Bridgetown::Current.preloaded_configuration
Bridgetown::Current.preloaded_configuration = Bridgetown::Configuration::Preflight.new
end
Bridgetown::PluginManager.setup_bundler(skip_yarn: true)
Bridgetown::PluginManager.setup_bundler

if Bridgetown::Current.preloaded_configuration.is_a?(Bridgetown::Configuration::Preflight)
Bridgetown::Current.preloaded_configuration = Bridgetown.configuration
Expand Down Expand Up @@ -336,17 +336,6 @@ def logger=(writer)
@logger = LogAdapter.new(writer, (ENV["BRIDGETOWN_LOG_LEVEL"] || :info).to_sym)
end

# Deprecated. Now using the Current site.
#
# @return [Array<Bridgetown::Site>] the Bridgetown sites created.
def sites
Deprecator.deprecation_message(
"Bridgetown.sites will be removed in the next version. Use Bridgetown::Current.sites" \
"instead"
)
[Bridgetown::Current.site].compact
end

# Ensures the questionable path is prefixed with the base directory
# and prepends the questionable path with the base directory if false.
#
Expand Down
5 changes: 0 additions & 5 deletions bridgetown-core/lib/bridgetown-core/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ def static_files
@static_files ||= []
end

def files
Bridgetown::Deprecator.deprecation_message "Collection#files is now Collection#static_files"
static_files
end

# Read the allowed resources into the collection's array of resources.
#
# @return [Bridgetown::Collection] self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,17 @@ def destination
end
alias_method :dest, :destination

def uses_resource?
Bridgetown::Deprecator.deprecation_message(
"The Site#uses_resource? method will be removed in the next version"
)
true
end

# Returns a base path from which the site is served (aka `/cool-site`) or
# `/` if served from root.
#
# @param strip_slash_only [Boolean] set to true if you wish "/" to be returned as ""
# @return [String]
def base_path(strip_slash_only: false)
(config[:base_path] || config[:baseurl]).then do |path|
config[:base_path].then do |path|
strip_slash_only ? path.to_s.sub(%r{^/$}, "") : path
end
end

def baseurl
Bridgetown::Deprecator.deprecation_message "Site#baseurl is now Site#base_path"
base_path(strip_slash_only: true).presence
end

def defaults_reader
@defaults_reader ||= Bridgetown::DefaultsReader.new(self)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CollectionDrop < Drop
mutable false

def_delegator :@obj, :write?, :output
def_delegators :@obj, :label, :files, :relative_path, :resources, :static_files
def_delegators :@obj, :label, :relative_path, :resources, :static_files

private def_delegator :@obj, :metadata, :fallback_data

Expand Down
5 changes: 0 additions & 5 deletions bridgetown-core/lib/bridgetown-core/drops/site_drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class SiteDrop < Drop
mutable false

def_delegators :@obj,
:baseurl, # deprecated
:base_path,
:data,
:locale,
Expand All @@ -24,10 +23,6 @@ class SiteDrop < Drop

attr_writer :current_document

def uses_resource
@obj.uses_resource?
end

def resources
@resources ||= @obj.resources
end
Expand Down
66 changes: 3 additions & 63 deletions bridgetown-core/lib/bridgetown-core/plugin_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,12 @@

module Bridgetown
class PluginManager
LEGACY_PLUGINS_GROUP = :bridgetown_plugins
YARN_DEPENDENCY_REGEXP = %r!(.+)@([^@]*)$!

attr_reader :site, :loaders_manager

@registered_plugins = Set.new

# @param source_manifest [Bridgetown::Configuration::SourceManifest]
def self.add_source_manifest(source_manifest)
unless source_manifest.is_a?(Bridgetown::Configuration::SourceManifest)
raise "You must add a SourceManifest instance"
end

unless Bridgetown::Current.preloaded_configuration
raise "A preloaded configuration must be present before adding source manifests"
end

Bridgetown::Deprecator.deprecation_message(
"The #{source_manifest.origin} plugin should switch from using `add_source_manifest' to " \
"the `source_manifest` initializer method"
)

Bridgetown::Current.preloaded_configuration.source_manifests << source_manifest
end

def self.new_source_manifest(*_args, **kwargs)
unless Bridgetown::Current.preloaded_configuration
raise "A preloaded configuration must be present before adding source manifests"
end

Bridgetown::Deprecator.deprecation_message(
"The #{kwargs[:origin]} plugin should switch from using `new_source_manifest' to the " \
"`source_manifest` initializer method"
)

add_source_manifest(Bridgetown::Configuration::SourceManifest.new(**kwargs))
end

def self.add_registered_plugin(gem_or_plugin_file)
@registered_plugins << gem_or_plugin_file
end
Expand All @@ -50,23 +18,15 @@ class << self
def bundler_specs
@bundler_specs ||= Bundler.load.requested_specs
end

def source_manifests
Bridgetown::Deprecator.deprecation_message(
"Use the configuration's `source_manifests` method instead of the plugin manager"
)

Bridgetown::Current.preloaded_configuration.source_manifests
end
end

def self.setup_bundler(skip_yarn: false)
def self.setup_bundler
if !ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] &&
(Bundler::SharedHelpers.in_bundle? || Bridgetown.env.test?)
require "bundler"

require_relative "utils/initializers"
load_determined_bundler_environment(skip_yarn:)
load_determined_bundler_environment

ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] = "true"
true
Expand All @@ -78,7 +38,7 @@ class << self
alias_method :require_from_bundler, :setup_bundler
end

def self.load_determined_bundler_environment(skip_yarn: false)
def self.load_determined_bundler_environment
boot_file = File.join("config", "boot.rb")

if File.file?(boot_file)
Expand All @@ -89,9 +49,6 @@ def self.load_determined_bundler_environment(skip_yarn: false)
# Note: the default Bundler config will set up all gem groups,
# see: https://bundler.io/guides/groups.html
Bundler.setup(:default, Bridgetown.env)
else
# Only setup and require :bridgetown_plugins
legacy_yarn_and_register(legacy_require, skip_yarn:)
end
end

Expand All @@ -112,23 +69,6 @@ def self.require_gem(name)
"Registered #{plugin_to_register.name}")
end

def self.legacy_require
Bundler.require(LEGACY_PLUGINS_GROUP).select do |dep|
dep.groups.intersect?([LEGACY_PLUGINS_GROUP]) && dep.should_include?
end
end

def self.legacy_yarn_and_register(required_gems, skip_yarn: false)
install_yarn_dependencies(required_gems) unless skip_yarn

required_gems.each do |installed_gem|
add_registered_plugin installed_gem
end

Bridgetown.logger.debug("PluginManager:",
"Required #{required_gems.map(&:name).join(", ")}")
end

def self.package_manager
@package_manager ||= if File.exist?("yarn.lock")
"yarn"
Expand Down
11 changes: 0 additions & 11 deletions bridgetown-core/lib/bridgetown-core/rack/boot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,6 @@

module Bridgetown
module Rack
class Roda < ::Roda
def self.inherited(klass)
Bridgetown::Deprecator.deprecation_message(
"The `Bridgetown::Rack::Roda' class will be removed in favor of using the " \
"`bridgetown_server' plugin in a future version"
)
super
klass.plugin :bridgetown_server
end
end

class << self
# @return [Bridgetown::Utils::LoadersManager]
attr_accessor :loaders_manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace :roda do
task :routes do
require "bridgetown-core/rack/boot"

Bridgetown::Rack::Roda.print_routes
Bridgetown::Rack::Routes.print_routes
end
end

Expand Down
6 changes: 0 additions & 6 deletions bridgetown-core/lib/bridgetown-core/utils/aux.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,6 @@ def self.run_process(name, color, cmd, env: {})
end
end

def self.group(&)
Bridgetown::Deprecator.deprecation_message "Bridgetown::Aux.group method will be removed" \
"in a future version, use run_process"
instance_exec(&)
end

def self.kill_processes
Bridgetown.logger.info "Stopping auxiliary processes..."
running_pids.each do |pid|
Expand Down
4 changes: 3 additions & 1 deletion bridgetown-core/test/ssr/server/roda_app.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class RodaApp < Bridgetown::Rack::Roda
class RodaApp < Roda
plugin :bridgetown_server

# rubocop:disable Lint/EmptyBlock
plugin(:common_logger, StringIO.new.tap do |io| # swallow logs in tests
io.singleton_class.define_method(:level=) { |*| }
Expand Down
4 changes: 2 additions & 2 deletions bridgetown-core/test/test_collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class TestCollections < BridgetownUnitTest
assert_equal "methods", @collection.to_liquid["label"]
end

should "have a files attribute" do
assert_equal [], @collection.to_liquid["files"]
should "have a static_files attribute" do
assert_equal [], @collection.to_liquid["static_files"]
end

should "have a relative_path attribute" do
Expand Down
Loading

0 comments on commit 5e70380

Please sign in to comment.