Skip to content

Commit

Permalink
Clean up some TODOs, weed out some Error classes
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Nov 3, 2024
1 parent d19c9e2 commit f39a4d7
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 40 deletions.
3 changes: 1 addition & 2 deletions bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def require_all(path)
require "bridgetown-foundation"

# 3rd party
require "active_support" # TODO: remove by the end of 2024
require "active_support" # TODO: remove by the end of 2025
require "active_support/core_ext/object/blank"
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/string/output_safety"
Expand Down Expand Up @@ -76,7 +76,6 @@ module Bridgetown
autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
autoload :Deprecator, "bridgetown-core/deprecator"
autoload :EntryFilter, "bridgetown-core/entry_filter"
# TODO: we have too many errors! This is silly
autoload :Errors, "bridgetown-core/errors"
autoload :FrontMatter, "bridgetown-core/front_matter"
autoload :GeneratedPage, "bridgetown-core/generated_page"
Expand Down
7 changes: 1 addition & 6 deletions bridgetown-core/lib/bridgetown-core/commands/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ def build
build_site(config_options)
end

# TODO: remove this logic…I can't find "detach" anywhere
if config_options.fetch("detach", false)
Bridgetown.logger.info "Auto-regeneration:",
"disabled when running server detached."
elsif config_options.fetch("watch", false)
if config_options.fetch("watch", false)
watch_site(config_options)
else
Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
Expand Down Expand Up @@ -111,7 +107,6 @@ def display_folder_paths(config_options)
Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
Bridgetown.logger.info "Source:", source
Bridgetown.logger.info "Destination:", destination
# TODO: work with arrays
return unless config_options["plugins_dir"].is_a?(String)

plugins_dir = File.expand_path(config_options["plugins_dir"])
Expand Down
1 change: 0 additions & 1 deletion bridgetown-core/lib/bridgetown-core/concerns/site/ssr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def ssr_setup(&block)
end

def ssr_first_read
# TODO: this shouldn't be running twice, right?!
Bridgetown::Hooks.trigger :site, :pre_read, self
defaults_reader.tap do |d|
d.path_defaults.clear
Expand Down
15 changes: 6 additions & 9 deletions bridgetown-core/lib/bridgetown-core/drops/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,22 @@ def [](key)
end
alias_method :invoke_drop, :[]

# Set a field in the Drop. If mutable, sets in the mutations and
# returns. If not mutable, checks first if it's trying to override a
# Drop method and raises a DropMutationException if so. If not
# mutable and the key is not a method on the Drop, then it sets the
# key to the value in the underlying hash (e.g. document front
# matter)
# Set a field in the Drop. If mutable, sets in the mutations and returns. If not mutable,
# checks first if it's trying to override a Drop method and raises an exception if so.
# If not mutable and the key is not a method on the Drop, then it sets the key to the value
# in the underlying hash (e.g. document front matter)
#
# @param key [String] key whose value to set
# @param val [Object] what to set the key's value to
# @return [Object] the value the key was set to unless the Drop is not mutable
# and the key matches a method in which case it raises a
# DropMutationException.
# and the key matches a method in which case it raises an exception
def []=(key, val)
setter = "#{key}="
if respond_to?(setter)
public_send(setter, val)
elsif respond_to?(key.to_s)
unless self.class.mutable?
raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
raise Errors::FatalException, "Key #{key} cannot be set in the drop."
end

mutations[key] = val
Expand Down
10 changes: 2 additions & 8 deletions bridgetown-core/lib/bridgetown-core/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@ module Bridgetown
module Errors
FatalException = Class.new(::RuntimeError)

DropMutationException = Class.new(FatalException)
InvalidPermalinkError = Class.new(FatalException)
InvalidYAMLFrontMatterError = Class.new(FatalException)
MissingDependencyException = Class.new(FatalException)

InvalidConfigurationError = Class.new(FatalException)
InvalidDateError = Class.new(FatalException)
InvalidPostNameError = Class.new(FatalException)
InvalidYAMLFrontMatterError = Class.new(FatalException)
PostURLError = Class.new(FatalException)
InvalidURLError = Class.new(FatalException)
InvalidConfigurationError = Class.new(FatalException)

def self.print_build_error(exc, trace: false, logger: Bridgetown.logger, server: false) # rubocop:todo Metrics
logger.error "Exception raised:", exc.class.to_s.bold
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/filters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def where(input, property, value) # rubocop:disable Metrics/CyclomaticComplexity
def where_exp(input, variable, expression)
return input unless input.respond_to?(:select)

input = input.values if input.is_a?(Hash) # FIXME
input = input.values if input.is_a?(Hash)

condition = parse_condition(expression)
@context.stack do
Expand Down
1 change: 0 additions & 1 deletion bridgetown-core/lib/bridgetown-core/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ def to_s

@registry = {}

NotAvailable = Class.new(RuntimeError)
Uncallable = Class.new(RuntimeError)

def self.priority_value(priority)
Expand Down
6 changes: 1 addition & 5 deletions bridgetown-core/lib/bridgetown-core/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,7 @@ def data
#
# @param new_data [HashWithDotAccess::Hash]
def data=(new_data)
if site.config.fast_refresh && write?
# TODO: investigate if this would be better:
# @data.value = front_matter_defaults
mark_for_fast_refresh!
end
mark_for_fast_refresh! if site.config.fast_refresh && write?

Signalize.batch do
@content_signal.value += 1
Expand Down
1 change: 0 additions & 1 deletion bridgetown-core/lib/bridgetown-core/ruby_template_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ def _liquid_context
def _partial_path(partial_name, ext)
partial_name = partial_name.split("/").tap { _1.last.prepend("_") }.join("/")

# TODO: see if there's a workaround for this to speed up performance
site.in_source_dir(site.config[:partials_dir], "#{partial_name}.#{ext}")
end
end
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/tags/post_url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(name)

all, @path, @date, @slug = *name.sub(%r!^/!, "").match(MATCHER)
unless all
raise Bridgetown::Errors::InvalidPostNameError,
raise Bridgetown::Errors::FatalException,
"'#{name}' does not contain valid date and/or title."
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def within?(other) # rubocop:disable Metrics
# NOTE: if you _really_ need to preserve Active Support's `in?` functionality, you can just
# require "active_support/core_ext/object/inclusion"
def in?(...) = Bridgetown::Foundation.deprecation_warning(
self, :in?, :within?, 2024, 12
self, :in?, :within?, 2025, 12
).then { within?(...) }
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def indent(indent_by, *args)
def questionable = Bridgetown::Foundation::QuestionableString.new(self)

def inquiry = Bridgetown::Foundation.deprecation_warning(
self, :inquiry, :questionable, 2024, 12
self, :inquiry, :questionable, 2025, 12
).then { questionable }
end
end
Expand Down
3 changes: 0 additions & 3 deletions bridgetown-website/README.md

This file was deleted.

0 comments on commit f39a4d7

Please sign in to comment.