bridgetown-core 2.0.5 → 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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -2
  3. data/bin/bridgetown +19 -7
  4. data/bridgetown-core.gemspec +8 -6
  5. data/lib/bridgetown-core/collection.rb +4 -3
  6. data/lib/bridgetown-core/command.rb +97 -0
  7. data/lib/bridgetown-core/commands/application.rb +208 -0
  8. data/lib/bridgetown-core/commands/apply.rb +17 -29
  9. data/lib/bridgetown-core/commands/build.rb +9 -16
  10. data/lib/bridgetown-core/commands/clean.rb +7 -10
  11. data/lib/bridgetown-core/commands/concerns/{actions.rb → automations.rb} +103 -17
  12. data/lib/bridgetown-core/commands/concerns/build_options.rb +24 -60
  13. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +2 -4
  14. data/lib/bridgetown-core/commands/configure.rb +24 -24
  15. data/lib/bridgetown-core/commands/console.rb +38 -34
  16. data/lib/bridgetown-core/commands/esbuild.rb +14 -24
  17. data/lib/bridgetown-core/commands/help.rb +24 -0
  18. data/lib/bridgetown-core/commands/new.rb +38 -60
  19. data/lib/bridgetown-core/commands/plugins.rb +237 -211
  20. data/lib/bridgetown-core/commands/registrations.rb +10 -1
  21. data/lib/bridgetown-core/commands/start.rb +23 -31
  22. data/lib/bridgetown-core/commands/thor_shim.rb +94 -0
  23. data/lib/bridgetown-core/component.rb +3 -3
  24. data/lib/bridgetown-core/concerns/publishable.rb +1 -3
  25. data/lib/bridgetown-core/concerns/site/localizable.rb +2 -0
  26. data/lib/bridgetown-core/configuration/configuration_dsl.rb +2 -2
  27. data/lib/bridgetown-core/configuration.rb +27 -7
  28. data/lib/bridgetown-core/converters/erb_templates.rb +31 -21
  29. data/lib/bridgetown-core/converters/ruby_templates.rb +14 -13
  30. data/lib/bridgetown-core/converters/serbea_templates.rb +5 -2
  31. data/lib/bridgetown-core/entry_filter.rb +1 -4
  32. data/lib/bridgetown-core/front_matter/defaults.rb +1 -1
  33. data/lib/bridgetown-core/front_matter/importer.rb +7 -1
  34. data/lib/bridgetown-core/front_matter/loaders.rb +1 -1
  35. data/lib/bridgetown-core/front_matter/ruby.rb +3 -9
  36. data/lib/bridgetown-core/generated_page.rb +2 -2
  37. data/lib/bridgetown-core/generators/prototype_generator.rb +1 -1
  38. data/lib/bridgetown-core/helpers.rb +10 -11
  39. data/lib/bridgetown-core/hooks.rb +2 -3
  40. data/lib/bridgetown-core/locale/en.yml +30 -0
  41. data/lib/bridgetown-core/model/base.rb +5 -5
  42. data/lib/bridgetown-core/model/builder_origin.rb +1 -1
  43. data/lib/bridgetown-core/model/origin.rb +5 -1
  44. data/lib/bridgetown-core/model/plugin_origin.rb +3 -1
  45. data/lib/bridgetown-core/model/repo_origin.rb +3 -1
  46. data/lib/bridgetown-core/rack/routes.rb +1 -1
  47. data/lib/bridgetown-core/reader.rb +2 -2
  48. data/lib/bridgetown-core/readers/plugin_content_reader.rb +31 -7
  49. data/lib/bridgetown-core/resource/base.rb +16 -7
  50. data/lib/bridgetown-core/resource/destination.rb +1 -1
  51. data/lib/bridgetown-core/resource/permalink_processor.rb +4 -4
  52. data/lib/bridgetown-core/static_file.rb +1 -1
  53. data/lib/bridgetown-core/tags/class_map.rb +0 -2
  54. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +8 -11
  55. data/lib/bridgetown-core/{ruby_template_view.rb → template_view.rb} +108 -4
  56. data/lib/bridgetown-core/utils/initializers.rb +28 -1
  57. data/lib/bridgetown-core/utils/loaders_manager.rb +2 -1
  58. data/lib/bridgetown-core/utils.rb +19 -1
  59. data/lib/bridgetown-core/watcher.rb +16 -8
  60. data/lib/bridgetown-core.rb +5 -10
  61. data/lib/roda/plugins/bridgetown_server.rb +1 -1
  62. data/lib/site_template/README.md +10 -8
  63. metadata +84 -70
  64. data/lib/bridgetown-core/commands/base.rb +0 -123
  65. data/lib/bridgetown-core/commands/concerns/summarizable.rb +0 -13
  66. data/lib/bridgetown-core/configurations/.keep +0 -0
  67. data/lib/bridgetown-core/configurations/stimulus.rb +0 -59
  68. data/lib/bridgetown-core/configurations/turbo/turbo_transitions.js +0 -48
  69. data/lib/bridgetown-core/configurations/turbo.rb +0 -35
  70. data/lib/bridgetown-core/configurations/vercel/vercel.json +0 -45
  71. data/lib/bridgetown-core/configurations/vercel/vercel_url.rb +0 -12
  72. data/lib/bridgetown-core/configurations/vercel.rb +0 -4
  73. data/lib/bridgetown-core/inflector.rb +0 -40
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "samovar"
4
+ require "freyia"
5
+
6
+ unless defined?(Thor)
7
+ class ThorishCommand < Samovar::Command
8
+ Actions = Freyia::Setup
9
+
10
+ def self.inherited(klass)
11
+ super
12
+
13
+ klass.nested :command, {}
14
+
15
+ klass.define_method :call do
16
+ Bridgetown::Deprecator.deprecation_message(
17
+ "The #{self.class} command is using the Thor shim. Please migrate to using the " \
18
+ "Samovar-based command API in Bridgetown 2.1+. The Thor shim will be removed " \
19
+ "in a later Bridgetown release."
20
+ )
21
+
22
+ if @command
23
+ @command.()
24
+ else
25
+ print_usage
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.desc(name, description)
31
+ @next_cmd_name = name
32
+ @next_cmd_description = description
33
+ end
34
+
35
+ def self.option(name, desc: "...", **kwargs, &block)
36
+ @next_cmd_options ||= []
37
+ @next_cmd_options << { args: [name, desc], kwargs:, block: }
38
+ end
39
+
40
+ def self.method_added(meth) # rubocop:disable Metrics
41
+ super
42
+
43
+ return unless @next_cmd_name
44
+
45
+ next_cmd_name = @next_cmd_name
46
+ new_cmd = Class.new(Samovar::Command)
47
+ new_cmd.define_method(:call) do
48
+ parent.instance_variable_set(:@options, @options)
49
+ parent.send(next_cmd_name)
50
+ end
51
+ new_cmd.description = @next_cmd_description
52
+
53
+ if @next_cmd_options&.empty?&.!
54
+ next_cmd_options = @next_cmd_options
55
+ new_cmd.options do
56
+ next_cmd_options.each do |opt|
57
+ name = opt[:args].shift
58
+ name = "--#{name}"
59
+ extra_kwargs = {}
60
+ extra_block = nil
61
+ if !opt[:kwargs][:type] || opt[:kwargs][:type] != :boolean
62
+ name = case opt[:kwargs][:type] # rubocop:disable Metrics/BlockNesting
63
+ when :numeric
64
+ extra_kwargs[:type] = Integer
65
+ "#{name} <NUM>"
66
+ when :array
67
+ extra_block = proc do |value|
68
+ value.split(%r{\s*,\s*})
69
+ end
70
+ "#{name} <ARR1,ARR2>"
71
+ else
72
+ "#{name} <STR>"
73
+ end
74
+ end
75
+
76
+ name = "#{opt[:kwargs][:aliases]}/#{name}" if opt[:kwargs][:aliases]
77
+
78
+ option(name, opt[:args][1], required: opt[:kwargs][:required], **extra_kwargs,
79
+ &extra_block)
80
+ end
81
+ end
82
+ end
83
+
84
+ table[:command].commands[next_cmd_name] = new_cmd
85
+
86
+ @next_cmd_name = nil
87
+ @next_cmd_description = nil
88
+ end
89
+
90
+ attr_reader :options
91
+ end
92
+
93
+ Thor = ThorishCommand
94
+ end
@@ -11,7 +11,7 @@ module Bridgetown
11
11
  # @return [Bridgetown::Site]
12
12
  attr_reader :site # will be nil unless you explicitly set a `@site` ivar
13
13
 
14
- # @return [Bridgetown::RubyTemplateView, Bridgetown::Component]
14
+ # @return [Bridgetown::TemplateView, Bridgetown::Component]
15
15
  attr_reader :view_context
16
16
 
17
17
  class << self
@@ -195,7 +195,7 @@ module Bridgetown
195
195
 
196
196
  # This is where the magic happens. Render the component within a view context.
197
197
  #
198
- # @param view_context [Bridgetown::RubyTemplateView]
198
+ # @param view_context [Bridgetown::TemplateView]
199
199
  def render_in(view_context, &block)
200
200
  @view_context = view_context
201
201
  @_content_block = block
@@ -249,7 +249,7 @@ module Bridgetown
249
249
  end
250
250
 
251
251
  def helpers
252
- @helpers ||= Bridgetown::RubyTemplateView::Helpers.new(self, view_context&.site)
252
+ @helpers ||= Bridgetown::TemplateView::Helpers.new(self, view_context&.site)
253
253
  end
254
254
 
255
255
  def method_missing(method, ...)
@@ -14,9 +14,7 @@ module Bridgetown
14
14
  return false unless published? || @site.config.unpublished
15
15
 
16
16
  future_allowed = collection.metadata.future || @site.config.future
17
- this_time = date.is_a?(Date) ? date.to_time.to_i : date.to_i
18
-
19
- future_allowed || this_time <= @site.time.to_i
17
+ future_allowed || date <= @site.time
20
18
  end
21
19
  end
22
20
  end
@@ -8,6 +8,8 @@ class Bridgetown::Site
8
8
  def locale
9
9
  @locale ||= begin
10
10
  locale = ENV.fetch("BRIDGETOWN_LOCALE", config[:default_locale]).to_sym
11
+ I18n.load_path += Gem.find_files_from_load_path("bridgetown-core/locale/en.*")
12
+ I18n.load_path.uniq!
11
13
  I18n.load_path += Dir["#{in_source_dir("_locales")}/**/*.{json,rb,yml}"]
12
14
  I18n.available_locales = config[:available_locales]
13
15
  I18n.default_locale = locale
@@ -56,8 +56,8 @@ module Bridgetown
56
56
  Bridgetown::Hooks.register_one(owner, event, priority:, reloadable: false, &)
57
57
  end
58
58
 
59
- def source_manifest(**kwargs)
60
- @scope.source_manifests << SourceManifest.new(**kwargs)
59
+ def source_manifest(**)
60
+ @scope.source_manifests << SourceManifest.new(**)
61
61
  end
62
62
 
63
63
  def builder(klass = nil, &)
@@ -5,17 +5,37 @@ module Bridgetown
5
5
  class Configuration < HashWithDotAccess::Hash
6
6
  using Bridgetown::Refinements
7
7
 
8
- REQUIRE_DENYLIST = %i(parse_routes ssr) # rubocop:disable Style/MutableConstant
8
+ # Built-in initializer list which isn't Gem-backed:
9
+ REQUIRE_DENYLIST = %i(external_sources parse_routes ssr) # rubocop:disable Style/MutableConstant
9
10
 
10
- Initializer = Struct.new(:name, :block, :completed, keyword_init: true) do
11
+ Initializer = Struct.new(:name, :block, :completed) do
11
12
  def to_s
12
13
  "#{name} (Initializer)"
13
14
  end
14
15
  end
15
16
 
16
- SourceManifest = Struct.new(:origin, :components, :content, :layouts, keyword_init: true)
17
+ SourceManifest = Struct.new(:origin, :components, :contents, :layouts, :bare_text) do
18
+ def initialize(**kwargs)
19
+ # for backwards compatibility, we need to support plugin code which sets `content`
20
+ # directly, rather than uses the new multi-collections `contents` hash
21
+ if kwargs[:content]
22
+ kwargs[:contents] = { pages: kwargs[:content] }
23
+ kwargs.delete :content
24
+ end
25
+
26
+ super
27
+ end
28
+
29
+ def content
30
+ Bridgetown::Deprecator.deprecation_message(
31
+ "source_manifest.content is deprecated, use " \
32
+ "source_manifest.contents instead"
33
+ )
34
+ contents.values.first
35
+ end
36
+ end
17
37
 
18
- Preflight = Struct.new(:source_manifests, :initializers, keyword_init: true) do
38
+ Preflight = Struct.new(:source_manifests, :initializers) do
19
39
  def initialize(*)
20
40
  super
21
41
  self.source_manifests ||= Set.new
@@ -44,7 +64,7 @@ module Bridgetown
44
64
  category: { key: "categories", title: "Category" }, tag: { key: "tags", title: "Tag" },
45
65
  },
46
66
  "autoload_paths" => [],
47
- "inflector" => Bridgetown::Inflector.new,
67
+ "inflector" => Bridgetown::Foundation::Inflector.new,
48
68
  "eager_load_paths" => [],
49
69
  "autoloader_collapsed_paths" => [],
50
70
  "additional_watch_paths" => [],
@@ -359,9 +379,9 @@ module Bridgetown
359
379
  end
360
380
 
361
381
  DEFAULT_EXCLUDES = %w(
362
- .sass-cache .bridgetown-cache
382
+ .sass-cache/ .bridgetown-cache/ tmp/
363
383
  gemfiles Gemfile Gemfile.lock gems.rb gems.locked
364
- node_modules
384
+ node_modules/ config/
365
385
  vendor/bundle/ vendor/cache/ vendor/gems/ vendor/ruby/
366
386
  ).freeze
367
387
 
@@ -56,9 +56,7 @@ module Bridgetown
56
56
  @buffer == other.to_str
57
57
  end
58
58
 
59
- def html_safe?
60
- true
61
- end
59
+ def html_safe? = true
62
60
 
63
61
  def html_safe = to_s
64
62
 
@@ -74,13 +72,9 @@ module Bridgetown
74
72
  safe_concat val.to_s
75
73
  end
76
74
 
77
- def to_s
78
- @buffer.html_safe
79
- end
75
+ def to_s = @buffer.html_safe
80
76
 
81
- def to_str
82
- @buffer.dup
83
- end
77
+ def to_str = @buffer.dup
84
78
  end
85
79
 
86
80
  class ERBEngine < Erubi::CaptureBlockEngine
@@ -96,34 +90,50 @@ module Bridgetown
96
90
  end
97
91
 
98
92
  module ERBCapture
99
- def capture(*args)
93
+ def capture(*)
100
94
  previous_buffer_state = @_erbout
101
95
  @_erbout = OutputBuffer.new
102
- result = yield(*args)
103
- result = @_erbout.presence || result
96
+ result = yield(*)
97
+ result = @_erbout unless @_erbout.empty?
104
98
  @_erbout = previous_buffer_state
105
99
  return result.to_s if result.is_a?(OutputBuffer)
106
100
 
107
- # TODO: resolve below logic once Active Support patch to `ERB::Util.h` is removed
108
- result.is_a?(String) ? ERB::Util.h(result) : result
101
+ result.is_a?(String) && !result.html_safe? ? Erubi.h(result) : result
109
102
  end
110
103
  end
111
104
 
112
- class ERBView < RubyTemplateView
113
- def h(input)
114
- Erubi.h(input)
115
- end
105
+ class ERBView < TemplateView
106
+ input :erb
107
+
108
+ def h(input) = Erubi.h(input)
116
109
 
117
110
  def partial(partial_name = nil, **options, &block)
118
111
  partial_name = options[:template] if partial_name.nil? && options[:template]
112
+ partial_path = _partial_path(partial_name, self.class.extname_list.first.delete_prefix("."))
113
+ unless _partial_path_exist?(partial_path)
114
+ @_call_super_method = true
115
+ return super
116
+ end
117
+
119
118
  options.merge!(options[:locals]) if options[:locals]
120
119
  options[:content] = capture(&block) if block
121
120
 
122
- _render_partial partial_name, options
121
+ # The reason we have to do this funky rigamarole is because if a view superclass ends up
122
+ # needing to render the the partial, we want to call the superclass' `_render_partial`
123
+ # method, not the subclass'. Like, if `partial` is called for `SerbeaView`, and a `.serb`
124
+ # partial can't be found, we'll kick up to `ERBView`. Then if an `.erb` partial is found,
125
+ # we want `_render_partial` to be called via the `ERBView` definition, not `SerbeaView`!
126
+ if @_call_super_method
127
+ @_call_super_method = false
128
+ method(:_render_partial).super_method.call partial_path, options
129
+ else
130
+ _render_partial partial_path, options
131
+ end
123
132
  end
124
133
 
125
- def _render_partial(partial_name, options)
126
- partial_path = _partial_path(partial_name, "erb")
134
+ protected
135
+
136
+ def _render_partial(partial_path, options)
127
137
  site.tmp_cache["partial-tmpl:#{partial_path}"] ||= {
128
138
  signal: site.config.fast_refresh ? Signalize.signal(1) : nil,
129
139
  }
@@ -3,7 +3,9 @@
3
3
  require "streamlined/renderable"
4
4
 
5
5
  module Bridgetown
6
- class PureRubyView < ERBView
6
+ class RubyView < ERBView
7
+ input :rb
8
+
7
9
  def render(item = nil, **options, &block) # rubocop:disable Metrics
8
10
  return @_erbout if !block && options.empty? && item.nil?
9
11
 
@@ -25,10 +27,12 @@ module Bridgetown
25
27
  end
26
28
  end
27
29
 
28
- def _render_partial(partial_name, options) # rubocop:todo Metrics
29
- partial_path = _partial_path(partial_name, "rb")
30
- return super unless File.exist?(partial_path)
30
+ # @return [OutputBuffer, nil]
31
+ def output_buffer = @_erbout
32
+
33
+ protected
31
34
 
35
+ def _render_partial(partial_path, options) # rubocop:todo Metrics
32
36
  (@_locals_stack ||= []).push(options)
33
37
  (@_buffer_stack ||= []).push(@_erbout)
34
38
  @_erbout = OutputBuffer.new
@@ -48,15 +52,12 @@ module Bridgetown
48
52
  end
49
53
  end
50
54
 
51
- def _output_buffer
52
- @_erbout # might be nil
53
- end
54
-
55
- def locals
56
- @_locals_stack&.last || {}
57
- end
55
+ def locals = @_locals_stack&.last || {}
58
56
  end
59
57
 
58
+ # TODO: this class alias is deprecated and will be removed in the next major Bridgetown release
59
+ PureRubyView = RubyView
60
+
60
61
  module Converters
61
62
  class RubyTemplates < Converter
62
63
  priority :highest
@@ -65,7 +66,7 @@ module Bridgetown
65
66
 
66
67
  # rubocop:disable Style/DocumentDynamicEvalDefinition, Style/EvalWithLocation
67
68
  def convert(content, convertible)
68
- rb_view = Bridgetown::PureRubyView.new(convertible)
69
+ rb_view = Bridgetown::RubyView.new(convertible)
69
70
 
70
71
  rb_view.instance_eval(
71
72
  "def __ruby_template;#{content};end", convertible.path.to_s, line_start(convertible)
@@ -76,7 +77,7 @@ module Bridgetown
76
77
  else
77
78
  rb_view.__ruby_template
78
79
  end
79
- (rb_view._output_buffer || results).to_s
80
+ (rb_view.output_buffer || results).to_s
80
81
  end
81
82
  # rubocop:enable Style/DocumentDynamicEvalDefinition, Style/EvalWithLocation
82
83
  end
@@ -7,8 +7,11 @@ module Bridgetown
7
7
  class SerbeaView < ERBView
8
8
  include Serbea::Helpers
9
9
 
10
- def _render_partial(partial_name, options)
11
- partial_path = _partial_path(partial_name, "serb")
10
+ input :serb
11
+
12
+ protected
13
+
14
+ def _render_partial(partial_path, options)
12
15
  site.tmp_cache["partial-tmpl:#{partial_path}"] ||= {
13
16
  signal: site.config.fast_refresh ? Signalize.signal(1) : nil,
14
17
  }
@@ -19,10 +19,7 @@ module Bridgetown
19
19
  @base_directory.to_s
20
20
  end
21
21
 
22
- def derive_base_directory(site, base_dir)
23
- base_dir[site.source] = "" if base_dir.start_with?(site.source)
24
- base_dir
25
- end
22
+ def derive_base_directory(site, base_dir) = base_dir.delete_prefix!(site.source)
26
23
 
27
24
  def relative_to_source(entry)
28
25
  File.join(
@@ -134,7 +134,7 @@ module Bridgetown
134
134
  # @param collection [Symbol] the collection of the resource being processed
135
135
  # @return [Boolean] whether either of the above conditions are satisfied
136
136
  def applies_collection?(scope, collection)
137
- !scope.key?("collection") || scope["collection"].eql?(collection.to_s)
137
+ !scope.key?("collection") || scope["collection"].to_s.eql?(collection.to_s)
138
138
  end
139
139
 
140
140
  # Checks if a given set of default values is valid
@@ -8,10 +8,16 @@ module Bridgetown
8
8
  klass.include Bridgetown::FrontMatter::RubyDSL
9
9
  end
10
10
 
11
- def read_front_matter(file_path)
11
+ def read_front_matter(file_path, bare_text: false) # rubocop:todo Metrics/MethodLength
12
12
  file_contents = File.read(
13
13
  file_path, **Bridgetown::Utils.merged_file_read_opts(Bridgetown::Current.site, {})
14
14
  )
15
+
16
+ if bare_text
17
+ self.content = file_contents
18
+ return {}
19
+ end
20
+
15
21
  fm_result = nil
16
22
  Loaders.for(self).each do |loader|
17
23
  fm_result = loader.read(file_contents, file_path:) and break
@@ -7,7 +7,7 @@ module Bridgetown
7
7
  autoload :Ruby, "bridgetown-core/front_matter/loaders/ruby"
8
8
  autoload :YAML, "bridgetown-core/front_matter/loaders/yaml"
9
9
 
10
- Result = Struct.new(:content, :front_matter, :line_count, keyword_init: true)
10
+ Result = Struct.new(:content, :front_matter, :line_count)
11
11
 
12
12
  # Constructs a list of possible loaders for a {Model::RepoOrigin} or {Layout}
13
13
  #
@@ -21,13 +21,9 @@ module Bridgetown
21
21
  set(key, value[0], &block)
22
22
  end
23
23
 
24
- def each(&)
25
- @data.each(&)
26
- end
24
+ def each(&) = @data.each(&)
27
25
 
28
- def get(key)
29
- @data[key]
30
- end
26
+ def get(key) = @data[key]
31
27
 
32
28
  def set(key, value = nil, &block)
33
29
  # Handle nested data within a block
@@ -45,9 +41,7 @@ module Bridgetown
45
41
  @data[key] = value
46
42
  end
47
43
 
48
- def to_h
49
- @data
50
- end
44
+ def to_h = @data
51
45
  end
52
46
  end
53
47
  end
@@ -289,8 +289,8 @@ module Bridgetown
289
289
  basename == "index"
290
290
  end
291
291
 
292
- def trigger_hooks(hook_name, *args)
293
- Bridgetown::Hooks.trigger :generated_pages, hook_name, self, *args
292
+ def trigger_hooks(hook_name, *)
293
+ Bridgetown::Hooks.trigger(:generated_pages, hook_name, self, *)
294
294
  end
295
295
 
296
296
  def type
@@ -80,7 +80,7 @@ module Bridgetown
80
80
  def validate_search_term(prototype_page)
81
81
  # @type [String]
82
82
  search_term = prototype_page.data["prototype"]["term"].to_s
83
- return nil unless search_term.present?
83
+ return nil if search_term.empty?
84
84
 
85
85
  if prototype_page.data["prototype"]["collection"]
86
86
  @configured_collection = prototype_page.data["prototype"]["collection"].to_s
@@ -3,7 +3,7 @@
3
3
  require "streamlined/helpers"
4
4
 
5
5
  module Bridgetown
6
- class RubyTemplateView
6
+ class TemplateView
7
7
  class Helpers
8
8
  using Bridgetown::Refinements
9
9
  include Bridgetown::Refinements::Helper
@@ -12,18 +12,18 @@ module Bridgetown
12
12
  include ::Streamlined::Helpers
13
13
  include Inclusive
14
14
 
15
- # @return [Bridgetown::RubyTemplateView, Bridgetown::Component]
15
+ # @return [Bridgetown::TemplateView, Bridgetown::Component]
16
16
  attr_reader :view
17
17
 
18
18
  # @return [Bridgetown::Site]
19
19
  attr_reader :site
20
20
 
21
- Context = Struct.new(:registers)
21
+ Context = Data.define(:registers)
22
22
 
23
23
  # @return [Bridgetown::Foundation::SafeTranslations]
24
24
  packages def translate_package = [Bridgetown::Foundation::Packages::SafeTranslations]
25
25
 
26
- # @param view [Bridgetown::RubyTemplateView, Bridgetown::Component]
26
+ # @param view [Bridgetown::TemplateView, Bridgetown::Component]
27
27
  # @param site [Bridgetown::Site]
28
28
  def initialize(view = nil, site = nil)
29
29
  @view = view
@@ -112,10 +112,10 @@ module Bridgetown
112
112
  # @param options [Hash] pass keyword arguments to add HTML attributes
113
113
  # @return [String] the anchor tag HTML
114
114
  # @raise [ArgumentError] if the file cannot be found
115
- def link_to(text, relative_path = nil, **options, &block)
116
- if block.present?
115
+ def link_to(text, relative_path = nil, **options, &)
116
+ if block_given?
117
117
  relative_path = text
118
- text = view.respond_to?(:capture) ? view.capture(&block) : yield
118
+ text = view.respond_to?(:capture) ? view.capture(&) : yield
119
119
  elsif relative_path.nil?
120
120
  raise ArgumentError, "You must provide a relative path"
121
121
  end
@@ -162,9 +162,9 @@ module Bridgetown
162
162
  end
163
163
  alias_method :t, :translate
164
164
 
165
- def translate_with_html(key, **options)
165
+ def translate_with_html(key, **)
166
166
  escaper = ->(input) { input.to_s.encode(xml: :attr).gsub(%r{\A"|"\Z}, "") }
167
- translate_package.translate(key, escaper, **options)
167
+ translate_package.translate(key, escaper, **)
168
168
  end
169
169
 
170
170
  # Delegates to <tt>I18n.localize</tt> with no additional functionality.
@@ -176,8 +176,7 @@ module Bridgetown
176
176
  end
177
177
  alias_method :l, :localize
178
178
 
179
- # For template contexts where ActiveSupport's output safety is loaded, we
180
- # can ensure a string has been marked safe
179
+ # In template contexts with output safety, we can ensure a string has been marked safe
181
180
  #
182
181
  # @param input [Object]
183
182
  # @return [String]
@@ -2,13 +2,12 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Hooks
5
- HookRegistration = Struct.new(
5
+ HookRegistration = Data.define(
6
6
  :owner,
7
7
  :event,
8
8
  :priority,
9
9
  :reloadable,
10
- :block,
11
- keyword_init: true
10
+ :block
12
11
  ) do
13
12
  def to_s
14
13
  "#{owner}:#{event} for #{block}"
@@ -0,0 +1,30 @@
1
+ # based on source material in the Active Support gem
2
+ en:
3
+ date:
4
+ formats:
5
+ # Use the strftime parameters for formats.
6
+ # When no format has been given, it uses default.
7
+ # You can provide other formats here if you like!
8
+ default: "%Y-%m-%d"
9
+ short: "%b %d"
10
+ long: "%B %d, %Y"
11
+
12
+ day_names: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]
13
+ abbr_day_names: [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
14
+
15
+ # Don't forget the nil at the beginning; there's no such thing as a 0th month
16
+ month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December]
17
+ abbr_month_names: [~, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec]
18
+ # Used in date_select and datetime_select.
19
+ order:
20
+ - year
21
+ - month
22
+ - day
23
+
24
+ time:
25
+ formats:
26
+ default: "%a, %d %b %Y %H:%M:%S %z"
27
+ short: "%d %b %H:%M"
28
+ long: "%B %d, %Y %H:%M"
29
+ am: "am"
30
+ pm: "pm"
@@ -6,14 +6,14 @@ module Bridgetown
6
6
  include Bridgetown::RodaCallable
7
7
 
8
8
  class << self
9
- def find(id, site: Bridgetown::Current.site)
9
+ def find(id, site: Bridgetown::Current.site, bare_text: false)
10
10
  raise "A Bridgetown site must be initialized and added to Current" unless site
11
11
 
12
- origin = origin_for_id(id, site:)
12
+ origin = origin_for_id(id, site:, bare_text:)
13
13
  klass_for_id(id, origin:).new(origin.read)
14
14
  end
15
15
 
16
- def origin_for_id(id, site: Bridgetown::Current.site)
16
+ def origin_for_id(id, site: Bridgetown::Current.site, bare_text: false)
17
17
  scheme = URI.parse(id).scheme
18
18
  origin_klass = Origin.descendants.find do |klass|
19
19
  klass.handle_scheme?(scheme)
@@ -21,7 +21,7 @@ module Bridgetown
21
21
 
22
22
  raise "No origin could be found for #{id}" unless origin_klass
23
23
 
24
- origin_klass.new(id, site:)
24
+ origin_klass.new(id, site:, bare_text:)
25
25
  end
26
26
 
27
27
  def klass_for_id(id, origin: nil)
@@ -148,7 +148,7 @@ module Bridgetown
148
148
  return attributes[key.chop] = args.first if key.end_with?("=")
149
149
 
150
150
  Bridgetown.logger.warn "key `#{method_name}' not found in attributes for " \
151
- "#{attributes[:id].presence || "new #{self.class}"}"
151
+ "#{attributes[:id] || "new #{self.class}"}"
152
152
  nil
153
153
  end
154
154
 
@@ -16,7 +16,7 @@ module Bridgetown
16
16
  end
17
17
  end
18
18
 
19
- def initialize(id, site: Bridgetown::Current.site)
19
+ def initialize(id, site: Bridgetown::Current.site, bare_text: false)
20
20
  super
21
21
  @relative_path = Pathname.new(url.path.delete_prefix("/"))
22
22
  end
@@ -12,14 +12,18 @@ module Bridgetown
12
12
  # @return [Bridgetown::Site]
13
13
  attr_accessor :site
14
14
 
15
+ # @return [Boolean]
16
+ attr_accessor :bare_text
17
+
15
18
  # You must implement in subclasses
16
19
  def self.handle_scheme?(_scheme)
17
20
  false
18
21
  end
19
22
 
20
- def initialize(id, site: Bridgetown::Current.site)
23
+ def initialize(id, site: Bridgetown::Current.site, bare_text: false)
21
24
  self.id = id
22
25
  self.site = site
26
+ self.bare_text = bare_text
23
27
  end
24
28
 
25
29
  # You can override in subclass