bridgetown-foundation 2.0.5 → 2.1.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6e566bf2e34da6277513bdb3382d69886b52e7d353ae6c8e1ce2cbb5e98ed67
4
- data.tar.gz: a0576b83399d4010aaa6ee29dc579611b64e037e3a804559a0cd901ce840ef29
3
+ metadata.gz: 740d9ecbd96bb9c76c7e93c65f8583ea0dfd6a8ed8817e14ca48d01e6e10d6ab
4
+ data.tar.gz: 5e55c2e76d40c593959918cf96c35a9cccb2de8bdf6873dff542100fc3583196
5
5
  SHA512:
6
- metadata.gz: 877fb53ad6618f7573017d0647fd24c19196c52c5f994f72cd9917e8be08359ea3c0764599fdc8eed3f262f4ae5cf6514d8d67d6e134b4fc55e935af78620c88
7
- data.tar.gz: '0043379cd6a98491ba338d65250864079a13c505d8815f0d5063aea7fff48a41fbd4f60b24bdebd9a9a8d73db4dd1b039aeeed6fbd35ffb54897120811d87018'
6
+ metadata.gz: 43c4c78d633f836bcd78484be1530fb9bb685de6689d5931c1c40b8951b3e519fb1b63b662d8faa92e9925945bf611181595b4f1433a3115398fab0940a3e066
7
+ data.tar.gz: 9b4b78519885e12c5233641c0cc14ee78a747b99eb101bf17dbe650a9a59e9a4933f997fab247e7cfdeb57980e99592a82a02db13805341d6194975e4d09ca34
data/.rubocop.yml CHANGED
@@ -6,6 +6,10 @@ AllCops:
6
6
  - "*.gemspec"
7
7
  - "script/console"
8
8
 
9
+ Metrics/BlockLength:
10
+ Exclude:
11
+ - test/**/*.rb
12
+
9
13
  Lint/Void:
10
14
  Exclude:
11
- - test/**/*.rb
15
+ - test/**/*.rb
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.summary = "Ruby language extensions and other utilities useful for the Bridgetown ecosystem"
11
11
  spec.homepage = "https://github.com/bridgetownrb/bridgetown/tree/main/bridgetown-foundation"
12
12
  spec.license = "MIT"
13
- spec.required_ruby_version = ">= 3.1"
13
+ spec.required_ruby_version = ">= 3.2"
14
14
 
15
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r!^(test|script)/!) }
16
16
  spec.require_paths = ["lib"]
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  "rubygems_mfa_required" => "true",
24
24
  }
25
25
 
26
+ spec.add_dependency("dry-inflector", ">= 1.0")
26
27
  spec.add_dependency("hash_with_dot_access", "~> 2.0")
27
28
  spec.add_dependency("inclusive", "~> 1.0")
28
29
  spec.add_dependency("zeitwerk", "~> 2.5")
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "date"
4
+
5
+ module Bridgetown::Foundation
6
+ module CoreExt
7
+ module Date
8
+ module DateAndTimeComparison
9
+ def <=>(other)
10
+ return super unless other.is_a?(Time)
11
+
12
+ to_time <=> other
13
+ end
14
+ end
15
+
16
+ #::Date.prepend DateAndTimeComparison
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown::Foundation
4
+ module CoreExt
5
+ module OutputSafety
6
+ module ObjectSafety
7
+ def html_safe?
8
+ false
9
+ end
10
+ end
11
+
12
+ ::Object.include ObjectSafety
13
+
14
+ module NumericSafety
15
+ def html_safe?
16
+ true
17
+ end
18
+ end
19
+
20
+ ::Numeric.include NumericSafety
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/inflector"
4
+
5
+ module Bridgetown::Foundation
6
+ class Inflector < Dry::Inflector
7
+ def initialize(&) # rubocop:disable Lint/MissingSuper
8
+ @inflections = Dry::Inflector::Inflections.build do |inflections|
9
+ inflections.acronym "HTML"
10
+ inflections.acronym "CSS"
11
+ inflections.acronym "JS"
12
+ end
13
+ configure(&) if block_given?
14
+ end
15
+
16
+ def configure
17
+ yield inflections
18
+ end
19
+
20
+ # for compatibility with Zeitwerk
21
+ def camelize(basename, *)
22
+ super(basename)
23
+ end
24
+
25
+ def to_s
26
+ "#<Bridgetown::Foundation::Inflector>"
27
+ end
28
+ alias_method :inspect, :to_s
29
+
30
+ def ==(other)
31
+ return super unless other.is_a?(Bridgetown::Foundation::Inflector)
32
+
33
+ # NOTE: strictly speaking, this might be wrong if two inflector instances have different
34
+ # rule sets…but as this equality check is mainly done within the automated test suite, we
35
+ # just assume two instances are equal. No production apps will need multiple,
36
+ # differently-configured inflectors running at once ;)
37
+ true
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown::Foundation
4
+ module RefineExt
5
+ module Hash
6
+ refine ::Hash do
7
+ def deep_merge(other, &block)
8
+ dup.deep_merge!(other, &block)
9
+ end
10
+
11
+ # Same as #deep_merge, but modifies +self+.
12
+ def deep_merge!(other, &block)
13
+ merge!(other) do |key, this_val, other_val|
14
+ if this_val.respond_to?(:deep_merge) && this_val.deep_merge?(other_val)
15
+ this_val.deep_merge(other_val, &block)
16
+ elsif block_given?
17
+ yield(key, this_val, other_val)
18
+ else
19
+ other_val
20
+ end
21
+ end
22
+ end
23
+
24
+ # Returns true if +other+ can be deep merged into +self+. Classes may
25
+ # override this method to restrict or expand the domain of deep mergeable
26
+ # values. Defaults to checking that +other+ is of type +self.class+.
27
+ def deep_merge?(other)
28
+ other.is_a?(self.class)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ module Bridgetown
36
+ module Refinements
37
+ include Foundation::RefineExt::Hash
38
+ end
39
+ end
@@ -3,7 +3,31 @@
3
3
  module Bridgetown::Foundation
4
4
  module RefineExt
5
5
  module String
6
+ # Support string convenience methods for Dry::Inflector methods
7
+ def self.string_inflector
8
+ # Always use the current configured site inflector, if available
9
+ if defined?(Bridgetown::Current) &&
10
+ Bridgetown::Current.preloaded_configuration.is_a?(Bridgetown::Configuration)
11
+ return Bridgetown::Current.preloaded_configuration.inflector
12
+ end
13
+
14
+ @string_inflector ||= Bridgetown::Foundation::Inflector.new
15
+ end
16
+
6
17
  refine ::String do
18
+ def camelize_upper = RefineExt::String.string_inflector.camelize(self)
19
+ alias_method :camelize, :camelize_upper
20
+
21
+ def camelize_lower = RefineExt::String.string_inflector.camelize_lower(self)
22
+ def classify = RefineExt::String.string_inflector.classify(self)
23
+ def constantize = RefineExt::String.string_inflector.constantize(self)
24
+ def dasherize = RefineExt::String.string_inflector.dasherize(self)
25
+ def humanize = RefineExt::String.string_inflector.humanize(self)
26
+ def pluralize = RefineExt::String.string_inflector.pluralize(self)
27
+ def singularize = RefineExt::String.string_inflector.singularize(self)
28
+ def underscore = RefineExt::String.string_inflector.underscore(self)
29
+
30
+ # Indent the string by n spaces
7
31
  def indent!(indent_by, *args)
8
32
  if args.length.positive?
9
33
  Kernel.warn "multiple arguments aren't supported by `indent!' in Bridgetown", uplevel: 1
@@ -15,6 +39,7 @@ module Bridgetown::Foundation
15
39
  gsub!(%r!^(?\!$)!, " " * indent_by) || self
16
40
  end
17
41
 
42
+ # Return a duplicated string indented by n spaces
18
43
  def indent(indent_by, *args)
19
44
  if args.length.positive?
20
45
  Kernel.warn "multiple arguments aren't supported by `indent' in Bridgetown", uplevel: 1
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "2.0.5"
5
- CODE_NAME = "River City"
4
+ VERSION = "2.1.0.beta2"
5
+ CODE_NAME = "Festive River City"
6
6
  end
@@ -50,6 +50,8 @@ Zeitwerk.with_loader do |l|
50
50
  end
51
51
 
52
52
  module Bridgetown
53
+ Inflector = Foundation::Inflector # compatibility alias
54
+
53
55
  # Any method call sent will be passed along to the wrapped object with refinements activated
54
56
  class WrappedObjectWithRefinements < SimpleDelegator
55
57
  using Bridgetown::Refinements
metadata CHANGED
@@ -1,15 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bridgetown-foundation
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.5
4
+ version: 2.1.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-11-16 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: dry-inflector
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '1.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '1.0'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: hash_with_dot_access
15
28
  requirement: !ruby/object:Gem::Requirement
@@ -52,7 +65,6 @@ dependencies:
52
65
  - - "~>"
53
66
  - !ruby/object:Gem::Version
54
67
  version: '2.5'
55
- description:
56
68
  email: maintainers@bridgetownrb.com
57
69
  executables: []
58
70
  extensions: []
@@ -64,13 +76,17 @@ files:
64
76
  - bridgetown-foundation.gemspec
65
77
  - lib/bridgetown-foundation.rb
66
78
  - lib/bridgetown/foundation/core_ext/class.rb
79
+ - lib/bridgetown/foundation/core_ext/date.rb
80
+ - lib/bridgetown/foundation/core_ext/output_safety.rb
67
81
  - lib/bridgetown/foundation/core_ext/string.rb
82
+ - lib/bridgetown/foundation/inflector.rb
68
83
  - lib/bridgetown/foundation/intuitive_expectations.rb
69
84
  - lib/bridgetown/foundation/packages/ansi.rb
70
85
  - lib/bridgetown/foundation/packages/pid_tracker.rb
71
86
  - lib/bridgetown/foundation/packages/safe_translations.rb
72
87
  - lib/bridgetown/foundation/questionable_string.rb
73
88
  - lib/bridgetown/foundation/refine_ext/deep_duplicatable.rb
89
+ - lib/bridgetown/foundation/refine_ext/hash.rb
74
90
  - lib/bridgetown/foundation/refine_ext/module.rb
75
91
  - lib/bridgetown/foundation/refine_ext/object.rb
76
92
  - lib/bridgetown/foundation/refine_ext/string.rb
@@ -84,7 +100,6 @@ metadata:
84
100
  changelog_uri: https://github.com/bridgetownrb/bridgetown/releases
85
101
  homepage_uri: https://github.com/bridgetownrb/bridgetown/tree/main/bridgetown-foundation
86
102
  rubygems_mfa_required: 'true'
87
- post_install_message:
88
103
  rdoc_options: []
89
104
  require_paths:
90
105
  - lib
@@ -92,15 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
92
107
  requirements:
93
108
  - - ">="
94
109
  - !ruby/object:Gem::Version
95
- version: '3.1'
110
+ version: '3.2'
96
111
  required_rubygems_version: !ruby/object:Gem::Requirement
97
112
  requirements:
98
113
  - - ">="
99
114
  - !ruby/object:Gem::Version
100
115
  version: '0'
101
116
  requirements: []
102
- rubygems_version: 3.3.26
103
- signing_key:
117
+ rubygems_version: 3.7.2
104
118
  specification_version: 4
105
119
  summary: Ruby language extensions and other utilities useful for the Bridgetown ecosystem
106
120
  test_files: []