Skip to content

Commit

Permalink
Move HashWithDotAccess dep over to Foundation, remove more AS deps
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite committed Apr 21, 2024
1 parent aff09a1 commit af956e9
Show file tree
Hide file tree
Showing 19 changed files with 80 additions and 60 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ PATH
erubi (~> 1.9)
faraday (~> 2.0)
faraday-follow_redirects (~> 0.3)
hash_with_dot_access (~> 2.0)
i18n (~> 1.0)
kramdown (~> 2.1)
kramdown-parser-gfm (~> 1.0)
Expand All @@ -39,6 +38,7 @@ PATH
remote: bridgetown-foundation
specs:
bridgetown-foundation (1.3.4)
hash_with_dot_access (~> 2.0)
zeitwerk (~> 2.5)

PATH
Expand Down Expand Up @@ -97,7 +97,7 @@ GEM
faraday-net_http (3.1.0)
net-http
ffi (1.16.3)
hash_with_dot_access (2.0.0)
hash_with_dot_access (2.1.1)
i18n (1.14.4)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.6)
Expand All @@ -112,7 +112,7 @@ GEM
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
memory_profiler (1.0.1)
mini_portile2 (2.8.5)
mini_portile2 (2.8.6)
minitest (5.22.3)
minitest-profile (0.0.2)
minitest-reporters (1.6.1)
Expand Down Expand Up @@ -155,14 +155,14 @@ GEM
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.6)
roda (3.78.0)
roda (3.79.0)
rack
rouge (4.2.1)
rspec-mocks (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.1)
rubocop (1.63.1)
rubocop (1.63.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand Down
2 changes: 2 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ task default: %w(test_all)
desc "Test all Bridgetown gems in monorepo"
task :test_all do
sh "cd bridgetown-core && script/cibuild"
sh "cd bridgetown-foundation && script/cibuild"
sh "cd bridgetown-builder && script/cibuild"
sh "cd bridgetown-paginate && script/cibuild"
sh "cd bridgetown-routes && script/cibuild"
end

task :release_all_unsafe do
sh "cd bridgetown-core && bundle exec rake release"
sh "cd bridgetown-foundation && bundle exec rake release"
sh "cd bridgetown-builder && bundle exec rake release"
sh "cd bridgetown-paginate && bundle exec rake release"
sh "cd bridgetown-routes && bundle exec rake release"
Expand Down
1 change: 0 additions & 1 deletion bridgetown-core/bridgetown-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Gem::Specification.new do |s|
s.add_runtime_dependency("erubi", "~> 1.9")
s.add_runtime_dependency("faraday", "~> 2.0")
s.add_runtime_dependency("faraday-follow_redirects", "~> 0.3")
s.add_runtime_dependency("hash_with_dot_access", "~> 2.0")
s.add_runtime_dependency("i18n", "~> 1.0")
s.add_runtime_dependency("kramdown", "~> 2.1")
s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
Expand Down
3 changes: 0 additions & 3 deletions bridgetown-core/lib/bridgetown-core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ def require_all(path)
# 3rd party
require "active_support"
require "active_support/core_ext/class/attribute"
require "active_support/core_ext/hash/keys"
require "active_support/core_ext/module/delegation"
require "active_support/core_ext/object/blank"
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/string/output_safety"
require "active_support/current_attributes"
require "hash_with_dot_access"
require "addressable/uri"
require "liquid"
require "listen"
Expand Down
1 change: 0 additions & 1 deletion bridgetown-core/lib/bridgetown-core/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
module Bridgetown
class Collection
using Bridgetown::Refinements
using HashWithDotAccess::Refinements
include Enumerable

# @return [Bridgetown::Site]
Expand Down
7 changes: 4 additions & 3 deletions bridgetown-core/lib/bridgetown-core/concerns/site/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
class Bridgetown::Site
# Content is king!
module Content
using HashWithDotAccess::Refinements
using Bridgetown::Refinements

def resources_grouped_by_taxonomy(taxonomy)
data.site_taxonomies_hash ||= {}
data.site_taxonomies_hash[taxonomy.label] ||= taxonomy.terms.transform_values do |terms|
Expand Down Expand Up @@ -67,7 +68,7 @@ def collection_names

# @return [Array<Bridgetown::Resource::TaxonomyType>]
def taxonomy_types
@taxonomy_types ||= config.taxonomies.to_h do |label, key_or_metadata|
@taxonomy_types ||= config.taxonomies.to_dot_h do |label, key_or_metadata|
key = key_or_metadata
tax_metadata = if key_or_metadata.is_a? Hash
key = key_or_metadata["key"]
Expand All @@ -79,7 +80,7 @@ def taxonomy_types
[label, Bridgetown::Resource::TaxonomyType.new(
site: self, label:, key:, metadata: tax_metadata
),]
end.as_dots
end
end

# Get all loaded resources.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ def init(name, require_gem: true, require_initializer: true, **kwargs, &block) #
end

Bridgetown.logger.debug "Initializing:", name
@scope.initializers[name.to_sym].block.(self, **@scope.init_params[name].symbolize_keys)
@scope.initializers[name.to_sym].block.(
self, **@scope.init_params[name].transform_keys(&:to_sym)
)
initializer.completed = true
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def t(input, options = "")
private

def string_to_hash(options)
options.split(",").to_h { |e| e.split(":").map(&:strip) }.symbolize_keys
options.split(",").to_h { |e| e.split(":").map(&:strip) }.transform_keys(&:to_sym)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/layout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Bridgetown
class Layout
using HashWithDotAccess::Refinements
using Bridgetown::Refinements
include FrontMatter::Importer
include LiquidRenderable

Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Bridgetown
module Resource
class Base # rubocop:todo Metrics/ClassLength
using HashWithDotAccess::Refinements
using Bridgetown::Refinements
include Comparable
include Bridgetown::Publishable
include Bridgetown::LayoutPlaceable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Bridgetown
module Resource
class TaxonomyType
using HashWithDotAccess::Refinements
using Bridgetown::Refinements

# @return [Bridgetown::Site]
attr_reader :site
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/ruby_template_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def liquid_render(component, options = {}, &block)
Bridgetown.logger.warn "Liquid Warning:",
LiquidRenderer.format_error(e, path || document.relative_path)
end
template.render!(options.deep_stringify_keys, _liquid_context).html_safe
template.render!(options.as_dots, _liquid_context).html_safe
end

def helpers
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-core/lib/bridgetown-core/static_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Bridgetown
class StaticFile
using HashWithDotAccess::Refinements
using Bridgetown::Refinements
extend Forwardable

attr_reader :relative_path, :extname, :name, :data, :site, :collection
Expand Down
6 changes: 4 additions & 2 deletions bridgetown-core/test/features/feature_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require "open3"

class BridgetownFeatureTest < BridgetownUnitTest
using Bridgetown::Refinements

class Paths
SOURCE_DIR = Pathname.new(File.expand_path("../..", __dir__))

Expand Down Expand Up @@ -97,15 +99,15 @@ def create_page(file, text, **front_matter)
FileUtils.mkdir_p("src")

File.write(File.join("src", file), <<~DATA)
#{front_matter.deep_stringify_keys.to_yaml}
#{front_matter.as_dots.to_h.to_yaml}
---
#{text}
DATA
end

def create_configuration(**config)
File.write("bridgetown.config.yml", config.deep_stringify_keys.to_yaml.delete_prefix("---\n"))
File.write("bridgetown.config.yml", config.as_dots.to_h.to_yaml.delete_prefix("---\n"))
end

def seconds_agnostic_time(time)
Expand Down
1 change: 1 addition & 0 deletions bridgetown-foundation/bridgetown-foundation.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ Gem::Specification.new do |spec|
"rubygems_mfa_required" => "true",
}

spec.add_dependency("hash_with_dot_access", "~> 2.0")
spec.add_dependency("zeitwerk", "~> 2.5")
end
2 changes: 2 additions & 0 deletions bridgetown-foundation/lib/bridgetown-foundation.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "bridgetown/foundation/version"
require "hash_with_dot_access"
require "zeitwerk"

module Bridgetown::Foundation
Expand Down Expand Up @@ -28,6 +29,7 @@ def self.deprecation_warning(target, name, repl, year, month) # rubocop:disable
# of the refinements available in Foundation. Or you can add a using statement for a particular
# refinement which lives inside `Bridgetown::Foundation::RefineExt`.
module Bridgetown::Refinements
include HashWithDotAccess::Refinements
end

Zeitwerk.with_loader do |l|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ def deep_dup
hash = dup
each do |key, value|
hash.delete(key)
if ::String === key || ::Symbol === key
if key.is_a?(::String) || key.is_a?(::Symbol)
hash[key] = value.dup
else
hash[key.dup] = (value.is_a?(Array) || value.is_a?(Hash)) ? value.deep_dup : value.dup
hash[key.dup] = if value.is_a?(Array) || value.is_a?(Hash)
value.deep_dup
else
value.dup
end
end
end
hash
Expand Down
2 changes: 1 addition & 1 deletion bridgetown-foundation/test/test_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_starts_ends_with

# TODO: more testing of other data types
def test_within
assert "abc".within? ["def", "abc"]
assert "abc".within? %w[def abc]
refute "abc".within? ["def"]
end
end
Loading

0 comments on commit af956e9

Please sign in to comment.