bridgetown-foundation 2.0.4 → 2.1.0.beta1
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 +4 -4
- data/.rubocop.yml +5 -1
- data/bridgetown-foundation.gemspec +2 -1
- data/lib/bridgetown/foundation/core_ext/date.rb +19 -0
- data/lib/bridgetown/foundation/core_ext/output_safety.rb +23 -0
- data/lib/bridgetown/foundation/inflector.rb +40 -0
- data/lib/bridgetown/foundation/refine_ext/hash.rb +39 -0
- data/lib/bridgetown/foundation/refine_ext/string.rb +25 -0
- data/lib/bridgetown/version.rb +2 -2
- data/lib/bridgetown-foundation.rb +2 -0
- metadata +22 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e8d6b224f5b4b26d43839fa298659ec8abc096bedac312df94e82027af4a7491
|
|
4
|
+
data.tar.gz: bdb41a9c2362c32a80e47da72b3f5629b20afa3fc1eee223c211a7583f058d35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fdee73300ffebfd5135929d0944e063ef36b00b63ee340e8805549d03da860fa31138f2aa721b706f41ce7a8b9f1fe6711fc12bea922c0693f665a776b2472dc
|
|
7
|
+
data.tar.gz: 31b1eb5b0eb0fefebc0948230aa670a07320e5eded1ebe7117f5ec67575e3d8ca462a022c323ec8a78e1bddec959e520a647c169d0cebf9748ef6b3eec1bdb7f
|
data/.rubocop.yml
CHANGED
|
@@ -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.
|
|
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
|
data/lib/bridgetown/version.rb
CHANGED
|
@@ -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.
|
|
4
|
+
version: 2.1.0.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Bridgetown Team
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
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.
|
|
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.
|
|
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: []
|