bridgetown-core 1.3.4 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bridgetown +0 -6
  3. data/bin/bt +6 -0
  4. data/bridgetown-core.gemspec +9 -6
  5. data/lib/bridgetown-core/cleaner.rb +1 -1
  6. data/lib/bridgetown-core/collection.rb +30 -18
  7. data/lib/bridgetown-core/commands/build.rb +9 -22
  8. data/lib/bridgetown-core/commands/concerns/actions.rb +15 -8
  9. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +1 -1
  10. data/lib/bridgetown-core/commands/console.rb +3 -0
  11. data/lib/bridgetown-core/commands/doctor.rb +2 -4
  12. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +1 -1
  13. data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
  14. data/lib/bridgetown-core/commands/esbuild/update.rb +2 -2
  15. data/lib/bridgetown-core/commands/esbuild.rb +3 -3
  16. data/lib/bridgetown-core/commands/new.rb +32 -39
  17. data/lib/bridgetown-core/commands/start.rb +76 -60
  18. data/lib/bridgetown-core/component.rb +19 -13
  19. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  20. data/lib/bridgetown-core/concerns/prioritizable.rb +11 -1
  21. data/lib/bridgetown-core/concerns/site/configurable.rb +7 -18
  22. data/lib/bridgetown-core/concerns/site/content.rb +10 -9
  23. data/lib/bridgetown-core/concerns/site/extensible.rb +4 -6
  24. data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +161 -0
  25. data/lib/bridgetown-core/concerns/site/processable.rb +1 -0
  26. data/lib/bridgetown-core/concerns/site/renderable.rb +31 -7
  27. data/lib/bridgetown-core/concerns/site/ssr.rb +23 -9
  28. data/lib/bridgetown-core/concerns/site/writable.rb +1 -1
  29. data/lib/bridgetown-core/concerns/transformable.rb +3 -5
  30. data/lib/bridgetown-core/configuration/configuration_dsl.rb +23 -14
  31. data/lib/bridgetown-core/configuration.rb +67 -114
  32. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -2
  33. data/lib/bridgetown-core/configurations/cypress/cypress_tasks +2 -2
  34. data/lib/bridgetown-core/configurations/cypress.rb +1 -1
  35. data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +3 -3
  36. data/lib/bridgetown-core/configurations/is-land.rb +1 -1
  37. data/lib/bridgetown-core/configurations/lit.rb +1 -1
  38. data/lib/bridgetown-core/configurations/open-props.rb +1 -1
  39. data/lib/bridgetown-core/configurations/purgecss.rb +1 -1
  40. data/lib/bridgetown-core/configurations/ruby2js.rb +1 -1
  41. data/lib/bridgetown-core/configurations/shoelace.rb +8 -20
  42. data/lib/bridgetown-core/configurations/stimulus.rb +17 -36
  43. data/lib/bridgetown-core/configurations/turbo.rb +1 -2
  44. data/lib/bridgetown-core/converter.rb +38 -10
  45. data/lib/bridgetown-core/converters/erb_templates.rb +9 -26
  46. data/lib/bridgetown-core/converters/identity.rb +1 -1
  47. data/lib/bridgetown-core/converters/liquid_templates.rb +2 -20
  48. data/lib/bridgetown-core/converters/ruby_templates.rb +61 -3
  49. data/lib/bridgetown-core/converters/serbea_templates.rb +12 -24
  50. data/lib/bridgetown-core/current.rb +19 -17
  51. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  52. data/lib/bridgetown-core/drops/drop.rb +3 -3
  53. data/lib/bridgetown-core/drops/relations_drop.rb +3 -2
  54. data/lib/bridgetown-core/drops/site_drop.rb +0 -5
  55. data/lib/bridgetown-core/entry_filter.rb +4 -6
  56. data/lib/bridgetown-core/errors.rb +2 -2
  57. data/lib/bridgetown-core/filters/from_liquid.rb +6 -10
  58. data/lib/bridgetown-core/filters/localization_filters.rb +1 -1
  59. data/lib/bridgetown-core/filters/translation_filters.rb +2 -2
  60. data/lib/bridgetown-core/filters.rb +3 -3
  61. data/lib/bridgetown-core/front_matter/defaults.rb +225 -0
  62. data/lib/bridgetown-core/front_matter/importer.rb +34 -0
  63. data/lib/bridgetown-core/front_matter/loaders/base.rb +29 -0
  64. data/lib/bridgetown-core/front_matter/loaders/ruby.rb +113 -0
  65. data/lib/bridgetown-core/front_matter/loaders/yaml.rb +42 -0
  66. data/lib/bridgetown-core/front_matter/loaders.rb +44 -0
  67. data/lib/bridgetown-core/{utils/ruby_front_matter.rb → front_matter/ruby.rb} +5 -5
  68. data/lib/bridgetown-core/front_matter.rb +11 -0
  69. data/lib/bridgetown-core/generated_page.rb +71 -31
  70. data/lib/bridgetown-core/generators/prototype_generator.rb +30 -18
  71. data/lib/bridgetown-core/helpers.rb +36 -47
  72. data/lib/bridgetown-core/hooks.rb +5 -5
  73. data/lib/bridgetown-core/inflector.rb +40 -0
  74. data/lib/bridgetown-core/kramdown/parser/gfm.rb +2 -2
  75. data/lib/bridgetown-core/layout.rb +3 -3
  76. data/lib/bridgetown-core/log_adapter.rb +12 -13
  77. data/lib/bridgetown-core/log_writer.rb +4 -4
  78. data/lib/bridgetown-core/model/base.rb +17 -17
  79. data/lib/bridgetown-core/model/builder_origin.rb +5 -3
  80. data/lib/bridgetown-core/model/origin.rb +1 -3
  81. data/lib/bridgetown-core/model/repo_origin.rb +12 -14
  82. data/lib/bridgetown-core/plugin.rb +0 -1
  83. data/lib/bridgetown-core/plugin_manager.rb +27 -84
  84. data/lib/bridgetown-core/rack/boot.rb +0 -15
  85. data/lib/bridgetown-core/rack/routes.rb +30 -90
  86. data/lib/bridgetown-core/reader.rb +6 -4
  87. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  88. data/lib/bridgetown-core/readers/plugin_content_reader.rb +2 -2
  89. data/lib/bridgetown-core/resource/base.rb +112 -29
  90. data/lib/bridgetown-core/resource/destination.rb +1 -1
  91. data/lib/bridgetown-core/resource/relations.rb +11 -8
  92. data/lib/bridgetown-core/resource/taxonomy_type.rb +3 -1
  93. data/lib/bridgetown-core/resource/transformer.rb +4 -4
  94. data/lib/bridgetown-core/ruby_template_view.rb +44 -28
  95. data/lib/bridgetown-core/signals.rb +95 -0
  96. data/lib/bridgetown-core/site.rb +22 -4
  97. data/lib/bridgetown-core/slot.rb +5 -5
  98. data/lib/bridgetown-core/static_file.rb +5 -7
  99. data/lib/bridgetown-core/tags/asset_path.rb +11 -2
  100. data/lib/bridgetown-core/tags/find.rb +3 -5
  101. data/lib/bridgetown-core/tags/highlight.rb +3 -3
  102. data/lib/bridgetown-core/tags/post_url.rb +1 -1
  103. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +2 -2
  104. data/lib/bridgetown-core/utils/aux.rb +41 -41
  105. data/lib/bridgetown-core/utils/loaders_manager.rb +2 -21
  106. data/lib/bridgetown-core/utils/ruby_exec.rb +17 -0
  107. data/lib/bridgetown-core/utils.rb +46 -110
  108. data/lib/bridgetown-core/version.rb +2 -2
  109. data/lib/bridgetown-core/watcher.rb +21 -10
  110. data/lib/bridgetown-core.rb +35 -49
  111. data/lib/roda/plugins/bridgetown_server.rb +54 -12
  112. data/lib/roda/plugins/bridgetown_ssr.rb +13 -2
  113. data/lib/roda/plugins/ssg.rb +72 -0
  114. data/lib/site_template/.gitignore +9 -3
  115. data/lib/site_template/Gemfile.erb +3 -3
  116. data/lib/site_template/README.md +3 -4
  117. data/lib/site_template/Rakefile.erb +2 -15
  118. data/lib/site_template/TEMPLATES/erb/_partials/_head.erb +2 -2
  119. data/lib/site_template/TEMPLATES/serbea/_partials/_head.serb +2 -2
  120. data/lib/site_template/config/initializers.rb +60 -22
  121. data/lib/site_template/config/puma.rb +2 -0
  122. data/lib/site_template/package.json.erb +2 -27
  123. data/lib/site_template/src/index.md.erb +3 -3
  124. data/lib/site_template/tmp/pids/.keep +0 -0
  125. metadata +98 -63
  126. data/lib/bridgetown-core/commands/webpack/enable-postcss.rb +0 -12
  127. data/lib/bridgetown-core/commands/webpack/setup.rb +0 -4
  128. data/lib/bridgetown-core/commands/webpack/update.rb +0 -24
  129. data/lib/bridgetown-core/commands/webpack/webpack.config.js +0 -31
  130. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +0 -135
  131. data/lib/bridgetown-core/commands/webpack.rb +0 -82
  132. data/lib/bridgetown-core/concerns/front_matter_importer.rb +0 -52
  133. data/lib/bridgetown-core/concerns/liquid_renderable.rb +0 -30
  134. data/lib/bridgetown-core/core_ext/psych.rb +0 -15
  135. data/lib/bridgetown-core/drops/url_drop.rb +0 -152
  136. data/lib/bridgetown-core/frontmatter_defaults.rb +0 -223
  137. data/lib/bridgetown-core/rack/static_indexes.rb +0 -31
  138. data/lib/bridgetown-core/url.rb +0 -166
  139. data/lib/bridgetown-core/utils/ansi.rb +0 -57
  140. data/lib/site_template/bridgetown.config.yml +0 -33
@@ -3,13 +3,16 @@
3
3
  module Bridgetown
4
4
  class GeneratedPage
5
5
  include LayoutPlaceable
6
- include LiquidRenderable
7
6
  include Localizable
8
7
  include Publishable
9
8
  include Transformable
10
9
 
11
10
  attr_writer :dir
12
- attr_accessor :site, :paginator, :name, :ext, :basename, :data, :content, :output
11
+ attr_accessor :site, :paginator, :name, :ext, :basename,
12
+ :data, :content, :output, :original_resource
13
+
14
+ # @return [Boolean]
15
+ attr_reader :fast_refresh_order
13
16
 
14
17
  alias_method :extname, :ext
15
18
 
@@ -37,11 +40,7 @@ module Bridgetown
37
40
  @name = name
38
41
  @ext = File.extname(name)
39
42
  @basename = File.basename(name, ".*")
40
- @path = if from_plugin
41
- File.join(base, dir, name)
42
- else
43
- site.in_source_dir(base, dir, name)
44
- end
43
+ @path = from_plugin ? File.join(base, dir, name) : site.in_source_dir(base, dir, name)
45
44
 
46
45
  process
47
46
 
@@ -97,16 +96,30 @@ module Bridgetown
97
96
  data&.permalink
98
97
  end
99
98
 
99
+ def add_permalink_suffix(template, permalink_style)
100
+ template = template.dup
101
+
102
+ case permalink_style
103
+ when :pretty, :simple
104
+ template << "/"
105
+ else
106
+ template << "/" if permalink_style.to_s.end_with?("/")
107
+ template << ":output_ext" if permalink_style.to_s.end_with?(".*")
108
+ end
109
+
110
+ template
111
+ end
112
+
100
113
  # The template of the permalink.
101
114
  #
102
115
  # @return [String]
103
116
  def template
104
117
  if !html?
105
- "/:path/:basename:output_ext"
118
+ "/:dir/:basename:output_ext"
106
119
  elsif index?
107
- "/:path/"
120
+ "/:dir/"
108
121
  else
109
- Utils.add_permalink_suffix("/:path/:basename", site.permalink_style)
122
+ add_permalink_suffix("/:dir/:basename", site.permalink_style)
110
123
  end
111
124
  end
112
125
 
@@ -114,23 +127,25 @@ module Bridgetown
114
127
  #
115
128
  # @return [String]
116
129
  def url
117
- @url ||= URL.new(
118
- template: template,
119
- placeholders: url_placeholders,
120
- permalink: permalink
121
- ).to_s
122
- end
123
- alias_method :relative_url, :url
130
+ return @url if @url
131
+
132
+ tmpl = permalink || template
133
+ placeholders = { dir: @dir, basename:, output_ext: }
134
+
135
+ results = placeholders.inject(tmpl) do |result, token|
136
+ break result if result.index(":").nil?
124
137
 
125
- # Returns a hash of URL placeholder names (as symbols) mapping to the
126
- # desired placeholder replacements. For details see "url.rb"
127
- def url_placeholders
128
- {
129
- path: @dir,
130
- basename: @basename,
131
- output_ext: output_ext,
132
- }
138
+ if token.last.nil?
139
+ # Remove leading "/" to avoid generating urls with `//`
140
+ result.gsub("/:#{token.first}", "")
141
+ else
142
+ result.gsub(":#{token.first}", token.last)
143
+ end
144
+ end.then { Addressable::URI.normalize_component _1 }
145
+
146
+ @url = "/#{results.sub("#", "%23")}".gsub("..", "/").gsub("./", "").squeeze("/")
133
147
  end
148
+ alias_method :relative_url, :url
134
149
 
135
150
  # Layout associated with this resource
136
151
  # This will output a warning if the layout can't be found.
@@ -199,13 +214,27 @@ module Bridgetown
199
214
  @converters ||= site.matched_converters_for_convertible(self)
200
215
  end
201
216
 
202
- def transform!
217
+ def transform! # rubocop:todo Metrics
203
218
  Bridgetown.logger.debug "Transforming:", relative_path
204
219
 
205
- trigger_hooks :pre_render
206
- self.content = transform_content(self)
207
- place_in_layout? ? place_into_layouts : self.output = content.dup
208
- trigger_hooks :post_render
220
+ internal_error = nil
221
+ Signalize.effect do
222
+ if !@fast_refresh_order && @previously_transformed_content
223
+ self.content = @previously_transformed_content
224
+ mark_for_fast_refresh! if site.config.fast_refresh && write?
225
+ next
226
+ end
227
+
228
+ trigger_hooks :pre_render
229
+ @previously_transformed_content ||= content
230
+ self.content = transform_content(self)
231
+ place_in_layout? ? place_into_layouts : self.output = content.dup
232
+ trigger_hooks :post_render
233
+ rescue StandardError, SyntaxError => e
234
+ internal_error = e
235
+ end
236
+
237
+ raise internal_error if internal_error
209
238
 
210
239
  self
211
240
  end
@@ -227,7 +256,7 @@ module Bridgetown
227
256
  #
228
257
  # @return [String]
229
258
  def destination(dest)
230
- path = site.in_dest_dir(dest, URL.unescape_path(url))
259
+ path = site.in_dest_dir(dest, Utils.unencode_uri(url))
231
260
  path = File.join(path, "index") if url.end_with?("/")
232
261
  path << output_ext unless path.end_with? output_ext
233
262
  path
@@ -241,6 +270,7 @@ module Bridgetown
241
270
  FileUtils.mkdir_p(File.dirname(path))
242
271
  Bridgetown.logger.debug "Writing:", path
243
272
  File.write(path, output, mode: "wb")
273
+ unmark_for_fast_refresh!
244
274
  Bridgetown::Hooks.trigger :generated_pages, :post_write, self
245
275
  end
246
276
 
@@ -270,5 +300,15 @@ module Bridgetown
270
300
  def write?
271
301
  true
272
302
  end
303
+
304
+ def mark_for_fast_refresh!
305
+ @fast_refresh_order = site.fast_refresh_ordering
306
+ site.fast_refresh_ordering += 1
307
+ end
308
+
309
+ def unmark_for_fast_refresh!
310
+ @fast_refresh_order = nil
311
+ original_resource&.unmark_for_fast_refresh!
312
+ end
273
313
  end
274
314
  end
@@ -1,12 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # Handles Generated Pages
4
- Bridgetown::Hooks.register_one :generated_pages, :post_init, reloadable: false do |page|
5
- if page.class != Bridgetown::PrototypePage && page.data["prototype"].is_a?(Hash)
6
- Bridgetown::PrototypeGenerator.add_matching_template(page)
7
- end
8
- end
9
-
10
3
  # Handles Resources
11
4
  Bridgetown::Hooks.register_one :resources, :post_read, reloadable: false do |resource|
12
5
  if resource.data["prototype"].is_a?(Hash)
@@ -14,6 +7,13 @@ Bridgetown::Hooks.register_one :resources, :post_read, reloadable: false do |res
14
7
  end
15
8
  end
16
9
 
10
+ # For data file updates, establish subscription for fast refresh
11
+ Bridgetown::Hooks.register_one :generated_pages, :pre_render, reloadable: false do |page|
12
+ if page.class != Bridgetown::PrototypePage && page.data["prototype"].is_a?(Hash)
13
+ page.data.data_signal&.value
14
+ end
15
+ end
16
+
17
17
  # Ensure sites clear out templates before rebuild
18
18
  Bridgetown::Hooks.register_one :site, :after_reset, reloadable: false do |_site|
19
19
  Bridgetown::PrototypeGenerator.matching_templates.clear
@@ -36,7 +36,7 @@ module Bridgetown
36
36
  end
37
37
 
38
38
  # @param site [Bridgetown::Site]
39
- def generate(site)
39
+ def generate(site) # rubocop:todo Metrics/CyclomaticComplexity
40
40
  @site = site
41
41
  page_list = site.collections.pages.resources
42
42
 
@@ -49,7 +49,9 @@ module Bridgetown
49
49
  ensure_pagination_enabled
50
50
 
51
51
  page_list.reject! do |page|
52
- prototype_pages.include? page
52
+ prototype_pages.include?(page).tap do |answer|
53
+ page.unmark_for_fast_refresh! if answer
54
+ end
53
55
  end
54
56
 
55
57
  prototype_pages.each do |prototype_page|
@@ -118,15 +120,14 @@ module Bridgetown
118
120
  end
119
121
 
120
122
  class PrototypePage < GeneratedPage
121
- # @return [Bridgetown::GeneratedPage, Bridgetown::Resource::Base]
122
- attr_reader :prototyped_page
123
+ alias_method :prototyped_page, :original_resource
123
124
 
124
125
  # @param prototyped_page [Bridgetown::Page, Bridgetown::Resource::Base]
125
126
  # @param collection [Bridgetown::Collection]
126
127
  # @param search_term [String]
127
128
  # @param term [String]
128
129
  def initialize(prototyped_page, collection, search_term, term) # rubocop:disable Lint/MissingSuper
129
- @prototyped_page = prototyped_page
130
+ self.original_resource = prototyped_page
130
131
  @site = prototyped_page.site
131
132
  @url = ""
132
133
  @name = "index.html"
@@ -134,15 +135,22 @@ module Bridgetown
134
135
  @basename = "index"
135
136
  @dir = Pathname.new(prototyped_page.relative_path).dirname.to_s.sub(%r{^_pages}, "")
136
137
  @path = site.in_source_dir(@dir, @name)
138
+ @collection = collection
139
+ @search_term = search_term
140
+ @term = term
137
141
 
138
- self.data = Bridgetown::Utils.deep_merge_hashes prototyped_page.data, {}
139
- self.content = prototyped_page.content
140
-
141
- process_prototype_page_data(collection, search_term, term)
142
+ fast_refresh!
142
143
 
143
144
  Bridgetown::Hooks.trigger :generated_pages, :post_init, self
144
145
  end
145
146
 
147
+ def fast_refresh!
148
+ self.data = Bridgetown::Utils.deep_merge_hashes prototyped_page.data, {}
149
+ self.content = prototyped_page.content
150
+ @original_title = data["title"]
151
+ process_prototype_page_data(@collection, @search_term, @term)
152
+ end
153
+
146
154
  def process_prototype_page_data(collection, search_term, term)
147
155
  pagination_key = prototyped_page.data.key?("paginate") ? "paginate" : "pagination"
148
156
  # Fill in pagination details to be handled later by Bridgetown::Paginate
@@ -163,16 +171,20 @@ module Bridgetown
163
171
 
164
172
  def process_title_data_placeholder(search_term, term) # rubocop:todo Metrics/AbcSize
165
173
  unless prototyped_page.data["prototype"]["data"] &&
166
- data["title"]&.include?(":prototype-data-label")
174
+ @original_title&.include?(":prototype-data-label")
167
175
  return
168
176
  end
169
177
 
170
178
  related_data = site.data[prototyped_page.data["prototype"]["data"]][term]
171
179
  return unless related_data
172
180
 
181
+ data["data_signal"] = site.signals.send(
182
+ :"#{prototyped_page.data["prototype"]["data"]}_signal"
183
+ )
184
+ data["#{search_term}_term"] = term
173
185
  data["#{search_term}_data"] = related_data
174
186
  data_label = related_data[prototyped_page.data["prototype"]["data_label"]]
175
- data["title"] = data["title"].gsub(
187
+ data["title"] = @original_title.gsub(
176
188
  ":prototype-data-label", data_label
177
189
  )
178
190
  end
@@ -1,12 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "active_support/html_safe_translation"
3
+ require "streamlined/helpers"
4
4
 
5
5
  module Bridgetown
6
6
  class RubyTemplateView
7
7
  class Helpers
8
+ using Bridgetown::Refinements
8
9
  include Bridgetown::Filters
9
10
  include Bridgetown::Filters::FromLiquid
11
+ include ::Streamlined::Helpers
12
+ include Inclusive
10
13
 
11
14
  # @return [Bridgetown::RubyTemplateView]
12
15
  attr_reader :view
@@ -16,20 +19,30 @@ module Bridgetown
16
19
 
17
20
  Context = Struct.new(:registers)
18
21
 
22
+ # @return [Bridgetown::Foundation::SafeTranslations]
23
+ packages def translate_package = [Bridgetown::Foundation::Packages::SafeTranslations]
24
+
19
25
  # @param view [Bridgetown::RubyTemplateView]
20
26
  # @param site [Bridgetown::Site]
21
- def initialize(view, site)
27
+ def initialize(view = nil, site = nil)
22
28
  @view = view
23
- @site = site
29
+ @site = site || Bridgetown::Current.site
24
30
 
25
31
  # duck typing for Liquid context
26
- @context = Context.new({ site: site })
32
+ @context = Context.new({ site: })
27
33
  end
28
34
 
29
35
  def asset_path(asset_type)
30
36
  Bridgetown::Utils.parse_frontend_manifest_file(site, asset_type.to_s)
31
37
  end
32
- alias_method :webpack_path, :asset_path
38
+
39
+ def webpack_path(*)
40
+ source_file = caller_locations.find { _1.path.start_with?(site.source) }.path
41
+ raise(
42
+ Bridgetown::Errors::FatalException,
43
+ "🚨 Oops, you'll need to change `webpack_path' to `asset_path' in:\n#{source_file}\n"
44
+ )
45
+ end
33
46
 
34
47
  def live_reload_dev_js
35
48
  Bridgetown::Utils.live_reload_js(site)
@@ -107,28 +120,13 @@ module Bridgetown
107
120
  elsif relative_path.nil?
108
121
  raise ArgumentError, "You must provide a relative path"
109
122
  end
110
- segments = attributes_from_options({ href: url_for(relative_path) }.merge(options))
123
+ segments = html_attributes({ href: url_for(relative_path) }.merge(options))
111
124
 
112
125
  safe("<a #{segments}>#{text}</a>")
113
126
  end
114
127
 
115
- # Create a set of attributes from a hash.
116
- #
117
- # @param options [Hash] key-value pairs of HTML attributes
118
- # @return [String]
119
- def attributes_from_options(options)
120
- segments = []
121
- options.each do |attr, option|
122
- attr = dashed(attr)
123
- if option.is_a?(Hash)
124
- option = option.transform_keys { |key| "#{attr}-#{dashed(key)}" }
125
- segments << attributes_from_options(option)
126
- else
127
- segments << attribute_segment(attr, option)
128
- end
129
- end
130
- safe(segments.join(" "))
131
- end
128
+ # Provide backwards compatibility via Streamlined helper
129
+ alias_method :attributes_from_options, :html_attributes
132
130
 
133
131
  # Delegates to <tt>I18n#translate</tt> but also performs two additional
134
132
  # functions.
@@ -161,10 +159,17 @@ module Bridgetown
161
159
  key = "#{view_path.tr("/", ".")}#{key}" if view_path.present?
162
160
  end
163
161
 
164
- ActiveSupport::HtmlSafeTranslation.translate(key, **options)
162
+ return I18n.translate(key, **options) unless %r{(?:_|\b)html\z}.match?(key)
163
+
164
+ translate_with_html(key, **options)
165
165
  end
166
166
  alias_method :t, :translate
167
167
 
168
+ def translate_with_html(key, **options)
169
+ escaper = ->(input) { input.to_s.encode(xml: :attr).gsub(%r{\A"|"\Z}, "") }
170
+ translate_package.translate(key, escaper, **options)
171
+ end
172
+
168
173
  # Delegates to <tt>I18n.localize</tt> with no additional functionality.
169
174
  #
170
175
  # @return [String] the localized string
@@ -209,10 +214,10 @@ module Bridgetown
209
214
  name = name.to_s
210
215
  resource.slots.reject! { _1.name == name } if replace
211
216
  resource.slots << Slot.new(
212
- name: name,
213
- content: content,
217
+ name:,
218
+ content:,
214
219
  context: resource,
215
- transform: transform
220
+ transform:
216
221
  )
217
222
 
218
223
  nil
@@ -260,12 +265,14 @@ module Bridgetown
260
265
  end
261
266
  end
262
267
 
268
+ # TODO: docu
263
269
  def dsd(input = nil, &block)
264
270
  tmpl_content = block.nil? ? input.to_s : view.capture(&block)
265
271
 
266
272
  Bridgetown::Utils.dsd_tag(tmpl_content)
267
273
  end
268
274
 
275
+ # TODO: docu
269
276
  def dsd_style
270
277
  tmpl_path = caller_locations(1, 2).find do |loc|
271
278
  loc.label.include?("method_missing").!
@@ -286,26 +293,8 @@ module Bridgetown
286
293
  style_tag.html_safe
287
294
  end
288
295
 
289
- private
290
-
291
- # Covert an underscored value into a dashed string.
292
- #
293
- # @example "foo_bar_baz" => "foo-bar-baz"
294
- #
295
- # @param value [String|Symbol]
296
- # @return [String]
297
- def dashed(value)
298
- value.to_s.tr("_", "-")
299
- end
300
-
301
- # Create an attribute segment for a tag.
302
- #
303
- # @param attr [String] the HTML attribute name
304
- # @param value [String] the attribute value
305
- # @return [String]
306
- def attribute_segment(attr, value)
307
- "#{attr}=\"#{Utils.xml_escape(value)}\""
308
- end
296
+ # TODO: docu
297
+ def bypass_tracking(...) = Signalize.untracked(...)
309
298
  end
310
299
  end
311
300
  end
@@ -55,7 +55,7 @@ module Bridgetown
55
55
  # @yieldparam obj the object which triggered the event hook
56
56
  def self.register(owners, event, priority: DEFAULT_PRIORITY, reloadable: true, &block)
57
57
  Array(owners).each do |owner|
58
- register_one(owner, event, priority: priority, reloadable: reloadable, &block)
58
+ register_one(owner, event, priority:, reloadable:, &block)
59
59
  end
60
60
  end
61
61
 
@@ -77,11 +77,11 @@ module Bridgetown
77
77
  raise Uncallable, "Hooks must respond to :call" unless block.respond_to? :call
78
78
 
79
79
  @registry[owner] << HookRegistration.new(
80
- owner: owner,
81
- event: event,
80
+ owner:,
81
+ event:,
82
82
  priority: priority_value(priority),
83
- reloadable: reloadable,
84
- block: block
83
+ reloadable:,
84
+ block:
85
85
  )
86
86
  if ENV["BRIDGETOWN_LOG_LEVEL"] == "debug"
87
87
  if Bridgetown.respond_to?(:logger)
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/inflector"
4
+
5
+ module Bridgetown
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::Inflector>"
27
+ end
28
+ alias_method :inspect, :to_s
29
+
30
+ def ==(other)
31
+ return super unless other.is_a?(Bridgetown::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
@@ -5,8 +5,8 @@ require "kramdown-parser-gfm"
5
5
  module Kramdown
6
6
  module Parser
7
7
  class GFM
8
- MARK_DELIMITER = %r{(==|::)+}.freeze
9
- MARK_MATCH = %r{#{MARK_DELIMITER}(?!\s|=|:).*?[^\s=:]#{MARK_DELIMITER}}m.freeze
8
+ MARK_DELIMITER = %r{(==|::)+}
9
+ MARK_MATCH = %r{#{MARK_DELIMITER}(?!\s|=|:).*?[^\s=:]#{MARK_DELIMITER}}m
10
10
 
11
11
  # Monkey-patch GFM initializer to add our new mark parser
12
12
  alias_method :_old_initialize, :initialize
@@ -2,8 +2,8 @@
2
2
 
3
3
  module Bridgetown
4
4
  class Layout
5
- include FrontMatterImporter
6
- include LiquidRenderable
5
+ using Bridgetown::Refinements
6
+ include FrontMatter::Importer
7
7
 
8
8
  # Gets the Site object.
9
9
  attr_reader :site
@@ -67,7 +67,7 @@ module Bridgetown
67
67
  @relative_path = @path.sub(@base_dir, "")
68
68
  @ext = File.extname(name)
69
69
 
70
- @data = read_front_matter(@path)&.with_dot_access
70
+ @data = read_front_matter(@path)&.as_dots
71
71
  rescue SyntaxError => e
72
72
  Bridgetown.logger.error "Error:",
73
73
  "Ruby Exception in #{e.message}"
@@ -43,7 +43,6 @@ module Bridgetown
43
43
  self.log_level = :debug
44
44
  end
45
45
  debug "Logging at level:", LOG_LEVELS.key(writer.level).to_s
46
- debug "Bridgetown Version:", Bridgetown::VERSION
47
46
  end
48
47
 
49
48
  # Public: Print a debug message
@@ -52,8 +51,8 @@ module Bridgetown
52
51
  # message - the message detail
53
52
  #
54
53
  # Returns nothing
55
- def debug(topic, message = nil, &block)
56
- write(:debug, topic, message, &block)
54
+ def debug(topic, message = nil, &)
55
+ write(:debug, topic, message, &)
57
56
  end
58
57
 
59
58
  # Public: Print a message
@@ -62,8 +61,8 @@ module Bridgetown
62
61
  # message - the message detail
63
62
  #
64
63
  # Returns nothing
65
- def info(topic, message = nil, &block)
66
- write(:info, topic, message, &block)
64
+ def info(topic, message = nil, &)
65
+ write(:info, topic, message, &)
67
66
  end
68
67
 
69
68
  # Public: Print a message
@@ -72,8 +71,8 @@ module Bridgetown
72
71
  # message - the message detail
73
72
  #
74
73
  # Returns nothing
75
- def warn(topic, message = nil, &block)
76
- write(:warn, topic, message, &block)
74
+ def warn(topic, message = nil, &)
75
+ write(:warn, topic, message, &)
77
76
  end
78
77
 
79
78
  # Public: Print an error message
@@ -82,8 +81,8 @@ module Bridgetown
82
81
  # message - the message detail
83
82
  #
84
83
  # Returns nothing
85
- def error(topic, message = nil, &block)
86
- write(:error, topic, message, &block)
84
+ def error(topic, message = nil, &)
85
+ write(:error, topic, message, &)
87
86
  end
88
87
 
89
88
  # Public: Print an error message and immediately abort the process
@@ -92,8 +91,8 @@ module Bridgetown
92
91
  # message - the message detail (can be omitted)
93
92
  #
94
93
  # Returns nothing
95
- def abort_with(topic, message = nil, &block)
96
- error(topic, message, &block)
94
+ def abort_with(topic, message = nil, &)
95
+ error(topic, message, &)
97
96
  abort
98
97
  end
99
98
 
@@ -142,10 +141,10 @@ module Bridgetown
142
141
  #
143
142
  # Returns false if the message was not written, otherwise returns the value of calling
144
143
  # the appropriate writer method, e.g. writer.info.
145
- def write(level_of_message, topic, message = nil, &block)
144
+ def write(level_of_message, topic, message = nil, &)
146
145
  return false unless write_message?(level_of_message)
147
146
 
148
- writer.public_send(level_of_message, message(topic, message, &block))
147
+ writer.public_send(level_of_message, message(topic, message, &))
149
148
  end
150
149
  end
151
150
  end
@@ -34,13 +34,13 @@ module Bridgetown
34
34
  end
35
35
 
36
36
  # Log a `WARN` message
37
- def warn(progname = nil, &block)
38
- add(WARN, nil, progname.yellow, &block)
37
+ def warn(progname = nil, &)
38
+ add(WARN, nil, progname.yellow, &)
39
39
  end
40
40
 
41
41
  # Log an `ERROR` message
42
- def error(progname = nil, &block)
43
- add(ERROR, nil, progname.red, &block)
42
+ def error(progname = nil, &)
43
+ add(ERROR, nil, progname.red, &)
44
44
  end
45
45
 
46
46
  def close