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
@@ -4,54 +4,35 @@ require "fileutils"
4
4
 
5
5
  say "Installing Stimulus...", :green
6
6
 
7
- run("yarn add @hotwired/stimulus")
8
- if Bridgetown::Utils.frontend_bundler_type == :webpack
9
- run("yarn add @hotwired/stimulus-webpack-helpers")
10
- end
7
+ add_npm_package "@hotwired/stimulus"
11
8
 
12
9
  say 'Adding Stimulus to "frontend/javascript/index.js"...', :magenta
13
10
 
14
11
  javascript_import do
15
- if Bridgetown::Utils.frontend_bundler_type == :esbuild
16
- <<~JS
17
- import { Application } from "@hotwired/stimulus"
18
- JS
19
- else
20
- <<~JS
21
- import { Application } from "@hotwired/stimulus"
22
- import { definitionsFromContext } from "@hotwired/stimulus-webpack-helpers"
23
- JS
24
- end
12
+ <<~JS
13
+ import { Application } from "@hotwired/stimulus"
14
+ JS
25
15
  end
26
16
 
27
17
  javascript_dir = File.join("frontend", "javascript")
28
18
 
29
19
  append_to_file(File.join(javascript_dir, "index.js")) do
30
- if Bridgetown::Utils.frontend_bundler_type == :esbuild
31
- <<~JS
32
-
33
- window.Stimulus = Application.start()
20
+ <<~JS
34
21
 
35
- import controllers from "./controllers/**/*.{js,js.rb}"
36
- Object.entries(controllers).forEach(([filename, controller]) => {
37
- if (filename.includes("_controller.") || filename.includes("-controller.")) {
38
- const identifier = filename.replace("./controllers/", "")
39
- .replace(/[_-]controller\\..*$/, "")
40
- .replace(/_/g, "-")
41
- .replace(/\\//g, "--")
22
+ window.Stimulus = Application.start()
42
23
 
43
- Stimulus.register(identifier, controller.default)
44
- }
45
- })
46
- JS
47
- else
48
- <<~JS
24
+ import controllers from "./controllers/**/*.{js,js.rb}"
25
+ Object.entries(controllers).forEach(([filename, controller]) => {
26
+ if (filename.includes("_controller.") || filename.includes("-controller.")) {
27
+ const identifier = filename.replace("./controllers/", "")
28
+ .replace(/[_-]controller\\..*$/, "")
29
+ .replace(/_/g, "-")
30
+ .replace(/\\//g, "--")
49
31
 
50
- window.Stimulus = Application.start()
51
- const context = require.context("./controllers", true, /\\.js$/)
52
- Stimulus.load(definitionsFromContext(context))
53
- JS
54
- end
32
+ Stimulus.register(identifier, controller.default)
33
+ }
34
+ })
35
+ JS
55
36
  end
56
37
 
57
38
  controller_dir = File.join(javascript_dir, "controllers")
@@ -2,8 +2,7 @@
2
2
 
3
3
  say_status :turbo, "Installing Turbo..."
4
4
 
5
- run("yarn add @hotwired/turbo")
6
- run("yarn add turbo-shadow")
5
+ add_npm_package "@hotwired/turbo turbo-shadow"
7
6
 
8
7
  say_status :turbo, 'Adding Turbo to "frontend/javascript/index.js"...', :magenta
9
8
 
@@ -15,13 +15,17 @@ module Bridgetown
15
15
  self.extname_list += extnames.map { |e| ".#{e.to_s.downcase}" }
16
16
  end
17
17
 
18
- def supports_slots?
19
- @support_slots == true
20
- end
18
+ def supports_slots? = @support_slots
21
19
 
22
20
  def support_slots(bool = true) # rubocop:disable Style/OptionalBooleanParameter
23
21
  @support_slots = bool == true
24
22
  end
23
+
24
+ def template_engine(name = nil)
25
+ return @template_engine unless name
26
+
27
+ @template_engine = name.to_s
28
+ end
25
29
  end
26
30
 
27
31
  # Initialize the converter.
@@ -35,7 +39,7 @@ module Bridgetown
35
39
  # Logic to do the content conversion.
36
40
  #
37
41
  # @param content [String] content of file (without front matter).
38
- # @param convertible [Bridgetown::Document, Bridgetown::Layout, Bridgetown::Resource::Base]
42
+ # @param convertible [Bridgetown::Layout, Bridgetown::Resource::Base]
39
43
  #
40
44
  # @return [String] the converted content.
41
45
  def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument
@@ -46,26 +50,50 @@ module Bridgetown
46
50
  #
47
51
  # @param [String] ext
48
52
  # The file's extension (including the dot)
53
+ # @param convertible [Bridgetown::Layout, Bridgetown::Resource::Base]
49
54
  #
50
55
  # @return [Boolean] Whether the extension matches one in the list
51
- def matches(ext)
56
+ def matches(ext, _convertible = nil)
52
57
  (self.class.extname_list || []).include?(ext.downcase)
53
58
  end
54
59
 
55
- # You can override this in Converter subclasses as needed. Default is ".html"
60
+ def determine_template_engine(convertible)
61
+ template_engine = self.class.template_engine
62
+ convertible_engine = convertible.data["template_engine"].to_s
63
+ convertible_engine == template_engine ||
64
+ (convertible_engine == "" && @config["template_engine"].to_s == template_engine)
65
+ end
66
+
67
+ # You can override this in Converter subclasses as needed. Default is ".html", unless the
68
+ # converter is a template engine and the input file doesn't match the normal template extension
56
69
  #
57
70
  # @param [String] ext
58
71
  # The extension of the original file
59
72
  #
60
73
  # @return [String] The output file extension (including the dot)
61
- def output_ext(_ext)
62
- ".html"
74
+ def output_ext(ext)
75
+ if self.class.template_engine
76
+ (self.class.extname_list || []).include?(ext.downcase) ? ".html" : ext
77
+ else
78
+ ".html"
79
+ end
63
80
  end
64
81
 
65
- def line_start(convertible)
82
+ def line_start(convertible) # rubocop:disable Metrics/PerceivedComplexity
66
83
  if convertible.is_a?(Bridgetown::Resource::Base) &&
67
84
  convertible.model.origin.respond_to?(:front_matter_line_count)
68
- convertible.model.origin.front_matter_line_count + 4
85
+ if convertible.model.origin.front_matter_line_count.nil?
86
+ 1
87
+ else
88
+ convertible.model.origin.front_matter_line_count + 4
89
+ end
90
+ elsif convertible.is_a?(Bridgetown::GeneratedPage) && convertible.original_resource
91
+ res = convertible.original_resource
92
+ if res.model.origin.respond_to?(:front_matter_line_count)
93
+ res.model.origin.front_matter_line_count + 4
94
+ else
95
+ 1
96
+ end
69
97
  else
70
98
  1
71
99
  end
@@ -43,7 +43,7 @@ module Bridgetown
43
43
  end
44
44
 
45
45
  # pulled from Rails' ActionView
46
- BLOCK_EXPR = %r!\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z!.freeze
46
+ BLOCK_EXPR = %r!\s*((\s+|\))do|\{)(\s*\|[^|]*\|)?\s*\Z!
47
47
 
48
48
  def add_expression(indicator, code)
49
49
  src << bufvar << if (indicator == "==") || @escape
@@ -73,8 +73,6 @@ module Bridgetown
73
73
  end
74
74
 
75
75
  class ERBView < RubyTemplateView
76
- include ERBCapture
77
-
78
76
  def h(input)
79
77
  Erubi.h(input)
80
78
  end
@@ -89,13 +87,18 @@ module Bridgetown
89
87
 
90
88
  def _render_partial(partial_name, options)
91
89
  partial_path = _partial_path(partial_name, "erb")
92
- tmpl = site.tmp_cache["partial-tmpl:#{partial_path}"] ||= Tilt::ErubiTemplate.new(
90
+ site.tmp_cache["partial-tmpl:#{partial_path}"] ||= {
91
+ signal: site.config.fast_refresh ? Signalize.signal(1) : nil,
92
+ }
93
+ tmpl = site.tmp_cache["partial-tmpl:#{partial_path}"]
94
+ tmpl.template ||= Tilt::ErubiTemplate.new(
93
95
  partial_path,
94
96
  outvar: "@_erbout",
95
97
  bufval: "Bridgetown::OutputBuffer.new",
96
98
  engine_class: ERBEngine
97
99
  )
98
- tmpl.render(self, options)
100
+ tmpl.signal&.value # subscribe so resources are attached to this partial within effect
101
+ tmpl.template.render(self, options)
99
102
  end
100
103
  end
101
104
 
@@ -103,6 +106,7 @@ module Bridgetown
103
106
  class ERBTemplates < Converter
104
107
  priority :highest
105
108
  input :erb
109
+ template_engine :erb
106
110
 
107
111
  # Logic to do the ERB content conversion.
108
112
  #
@@ -113,8 +117,6 @@ module Bridgetown
113
117
  #
114
118
  # @return [String] The converted content.
115
119
  def convert(content, convertible)
116
- return content if convertible.data[:template_engine].to_s != "erb"
117
-
118
120
  erb_view = Bridgetown::ERBView.new(convertible)
119
121
 
120
122
  erb_renderer = Tilt::ErubiTemplate.new(
@@ -133,25 +135,6 @@ module Bridgetown
133
135
  erb_renderer.render(erb_view)
134
136
  end
135
137
  end
136
-
137
- # @param ext [String]
138
- # @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage]
139
- def matches(ext, convertible)
140
- if convertible.data[:template_engine].to_s == "erb" ||
141
- (convertible.data[:template_engine].nil? &&
142
- @config[:template_engine].to_s == "erb")
143
- convertible.data[:template_engine] = "erb"
144
- return true
145
- end
146
-
147
- super(ext).tap do |ext_matches|
148
- convertible.data[:template_engine] = "erb" if ext_matches
149
- end
150
- end
151
-
152
- def output_ext(ext)
153
- ext == ".erb" ? ".html" : ext
154
- end
155
138
  end
156
139
  end
157
140
  end
@@ -15,7 +15,7 @@ module Bridgetown
15
15
  # _ext - The String extension to check (not relevant here)
16
16
  #
17
17
  # Returns true since it always matches.
18
- def matches(_ext)
18
+ def matches(*)
19
19
  true
20
20
  end
21
21
 
@@ -5,6 +5,7 @@ module Bridgetown
5
5
  class LiquidTemplates < Converter
6
6
  priority :highest
7
7
  input :liquid
8
+ template_engine :liquid
8
9
 
9
10
  attr_reader :site, :document, :layout
10
11
 
@@ -24,8 +25,6 @@ module Bridgetown
24
25
  #
25
26
  # @return [String] The converted content.
26
27
  def convert(content, convertible)
27
- return content if convertible.data[:template_engine] != "liquid"
28
-
29
28
  self.class.cached_partials ||= {}
30
29
  @payload = nil
31
30
 
@@ -56,23 +55,6 @@ module Bridgetown
56
55
  # rubocop: enable Metrics/MethodLength
57
56
  # rubocop: enable Metrics/AbcSize
58
57
 
59
- # @param ext [String]
60
- # @param convertible [Bridgetown::Resource::Base, Bridgetown::GeneratedPage]
61
- def matches(ext, convertible)
62
- if convertible.render_with_liquid?
63
- convertible.data[:template_engine] = "liquid"
64
- return true
65
- end
66
-
67
- super(ext).tap do |ext_matches|
68
- convertible.data[:template_engine] = "liquid" if ext_matches
69
- end
70
- end
71
-
72
- def output_ext(ext)
73
- ext == ".liquid" ? ".html" : ext
74
- end
75
-
76
58
  # Fetches the payload used in Liquid rendering.
77
59
  # Falls back to site.site_payload if no payload is set.
78
60
  #
@@ -95,7 +77,7 @@ module Bridgetown
95
77
  def liquid_context
96
78
  {
97
79
  registers: {
98
- site: site,
80
+ site:,
99
81
  page: payload["page"],
100
82
  cached_partials: self.class.cached_partials,
101
83
  },
@@ -1,16 +1,74 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "streamlined/renderable"
4
+
3
5
  module Bridgetown
6
+ class PureRubyView < ERBView
7
+ def render(item = nil, **options, &block) # rubocop:disable Metrics
8
+ return @_erbout if !block && options.empty? && item.nil?
9
+
10
+ if item.is_a?(Proc) || (block && item.nil?)
11
+ result = item.is_a?(Proc) ? item.() : yield
12
+ return result if result.is_a?(OutputBuffer)
13
+
14
+ @_erbout ||= OutputBuffer.new
15
+ @_erbout << result.to_s.html_safe
16
+
17
+ return @_erbout
18
+ end
19
+
20
+ if item.respond_to?(:render_in)
21
+ result = item.render_in(self, &block)
22
+ result&.to_s&.html_safe
23
+ else
24
+ partial(item, **options, &block)&.html_safe
25
+ end
26
+ end
27
+
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)
31
+
32
+ (@_locals_stack ||= []).push(options)
33
+ (@_buffer_stack ||= []).push(@_erbout)
34
+ @_erbout = OutputBuffer.new
35
+
36
+ site.tmp_cache["partial-tmpl:#{partial_path}"] ||= {
37
+ signal: site.config.fast_refresh ? Signalize.signal(1) : nil,
38
+ }
39
+ tmpl = site.tmp_cache["partial-tmpl:#{partial_path}"]
40
+ tmpl.template ||= options.keys.map do |k|
41
+ "#{k}=locals[:#{k}];"
42
+ end.push(File.read(partial_path)).join
43
+ tmpl.signal&.value # subscribe so resources are attached to this partial within effect
44
+
45
+ instance_eval(tmpl.template).to_s.tap do
46
+ @_locals_stack.pop
47
+ @_erbout = @_buffer_stack.pop
48
+ end
49
+ end
50
+
51
+ def _output_buffer
52
+ @_erbout # might be nil
53
+ end
54
+
55
+ def locals
56
+ @_locals_stack&.last || {}
57
+ end
58
+ end
59
+
4
60
  module Converters
5
61
  class RubyTemplates < Converter
6
62
  priority :highest
7
63
  input :rb
64
+ template_engine :ruby
8
65
 
9
66
  def convert(content, convertible)
10
- erb_view = Bridgetown::ERBView.new(convertible)
11
- erb_view.instance_eval(
67
+ rb_view = Bridgetown::PureRubyView.new(convertible)
68
+ results = rb_view.instance_eval(
12
69
  content, convertible.path.to_s, line_start(convertible)
13
- ).to_s
70
+ )
71
+ rb_view._output_buffer || results.to_s
14
72
  end
15
73
  end
16
74
  end
@@ -9,15 +9,20 @@ module Bridgetown
9
9
 
10
10
  def _render_partial(partial_name, options)
11
11
  partial_path = _partial_path(partial_name, "serb")
12
- tmpl = site.tmp_cache["partial-tmpl:#{partial_path}"] ||=
13
- Tilt::SerbeaTemplate.new(partial_path)
14
- tmpl.render(self, options)
12
+ site.tmp_cache["partial-tmpl:#{partial_path}"] ||= {
13
+ signal: site.config.fast_refresh ? Signalize.signal(1) : nil,
14
+ }
15
+ tmpl = site.tmp_cache["partial-tmpl:#{partial_path}"]
16
+ tmpl.template ||= Tilt::SerbeaTemplate.new(partial_path)
17
+ tmpl.signal&.value # subscribe so resources are attached to this partial within effect
18
+ tmpl.template.render(self, options)
15
19
  end
16
20
  end
17
21
 
18
22
  module Converters
19
23
  class SerbeaTemplates < Converter
20
24
  priority :highest
25
+ template_engine :serbea
21
26
  input :serb
22
27
 
23
28
  # Logic to do the Serbea content conversion.
@@ -29,11 +34,11 @@ module Bridgetown
29
34
  #
30
35
  # @return [String] The converted content.
31
36
  def convert(content, convertible)
32
- return content if convertible.data[:template_engine].to_s != "serbea"
33
-
34
37
  serb_view = Bridgetown::SerbeaView.new(convertible)
35
-
36
- serb_renderer = Tilt::SerbeaTemplate.new(convertible.path) { content }
38
+ serb_renderer = Tilt::SerbeaTemplate.new(
39
+ convertible.path,
40
+ line_start(convertible)
41
+ ) { content }
37
42
 
38
43
  if convertible.is_a?(Bridgetown::Layout)
39
44
  serb_renderer.render(serb_view) do
@@ -43,23 +48,6 @@ module Bridgetown
43
48
  serb_renderer.render(serb_view)
44
49
  end
45
50
  end
46
-
47
- def matches(ext, convertible)
48
- if convertible.data[:template_engine].to_s == "serbea" ||
49
- (convertible.data[:template_engine].nil? &&
50
- @config[:template_engine].to_s == "serbea")
51
- convertible.data[:template_engine] = "serbea"
52
- return true
53
- end
54
-
55
- super(ext).tap do |ext_matches|
56
- convertible.data[:template_engine] = "serbea" if ext_matches
57
- end
58
- end
59
-
60
- def output_ext(ext)
61
- ext == ".serb" ? ".html" : ext
62
- end
63
51
  end
64
52
  end
65
53
  end
@@ -1,28 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ Thread.attr_accessor :bridgetown_state
4
+
3
5
  module Bridgetown
4
- class Current < ActiveSupport::CurrentAttributes
5
- # @!method self.preloaded_configuration
6
- # @return [Bridgetown::Configuration]
7
- attribute :preloaded_configuration
6
+ class Current
7
+ class << self
8
+ def thread_state = Thread.current.bridgetown_state ||= {}
8
9
 
9
- # @return [Bridgetown::Site, nil]
10
- def self.site
11
- sites[:main]
12
- end
10
+ # @return [Bridgetown::Site, nil]
11
+ def site = sites[:main]
13
12
 
14
- def self.site=(new_site)
15
- sites[:main] = new_site
16
- end
13
+ def site=(new_site)
14
+ sites[:main] = new_site
15
+ end
17
16
 
18
- # @!method self.sites
19
- # @return [Hash<Symbol, Bridgetown::Site>]
17
+ # @return [Hash<Symbol, Bridgetown::Site>]
18
+ def sites
19
+ thread_state[:sites] ||= {}
20
+ end
20
21
 
21
- attribute :sites
22
+ # @return [Bridgetown::Configuration]
23
+ def preloaded_configuration = thread_state[:preloaded_configuration]
22
24
 
23
- def initialize
24
- super
25
- @attributes[:sites] = {}
25
+ def preloaded_configuration=(value)
26
+ thread_state[:preloaded_configuration] = value
27
+ end
26
28
  end
27
29
  end
28
30
  end
@@ -8,7 +8,7 @@ module Bridgetown
8
8
  mutable false
9
9
 
10
10
  def_delegator :@obj, :write?, :output
11
- def_delegators :@obj, :label, :files, :relative_path, :resources, :static_files
11
+ def_delegators :@obj, :label, :relative_path, :resources, :static_files
12
12
 
13
13
  private def_delegator :@obj, :metadata, :fallback_data
14
14
 
@@ -24,7 +24,7 @@ module Bridgetown
24
24
 
25
25
  # Create a new Drop
26
26
  #
27
- # obj - the Bridgetown Site, Collection, or Document required by the
27
+ # obj - the Bridgetown Site, Collection, or Resource required by the
28
28
  # drop.
29
29
  #
30
30
  # Returns nothing
@@ -159,8 +159,8 @@ module Bridgetown
159
159
  # block - a block which accepts one argument, the key
160
160
  #
161
161
  # Returns nothing.
162
- def each_key(&block)
163
- keys.each(&block)
162
+ def each_key(&)
163
+ keys.each(&)
164
164
  end
165
165
 
166
166
  def each
@@ -3,16 +3,17 @@
3
3
  module Bridgetown
4
4
  module Drops
5
5
  class RelationsDrop < Drop
6
+ using Bridgetown::Refinements
6
7
  mutable false
7
8
 
8
9
  def [](type)
9
- return nil unless type.to_s.in?(@obj.relation_types)
10
+ return nil unless type.to_s.within?(@obj.relation_types)
10
11
 
11
12
  @obj.resources_for_type(type)
12
13
  end
13
14
 
14
15
  def key?(type)
15
- type.to_s.in?(@obj.relation_types)
16
+ type.to_s.within?(@obj.relation_types)
16
17
  end
17
18
 
18
19
  def fallback_data
@@ -8,7 +8,6 @@ module Bridgetown
8
8
  mutable false
9
9
 
10
10
  def_delegators :@obj,
11
- :baseurl, # deprecated
12
11
  :base_path,
13
12
  :data,
14
13
  :locale,
@@ -24,10 +23,6 @@ module Bridgetown
24
23
 
25
24
  attr_writer :current_document
26
25
 
27
- def uses_resource
28
- @obj.uses_resource?
29
- end
30
-
31
26
  def resources
32
27
  @resources ||= @obj.resources
33
28
  end
@@ -4,8 +4,8 @@ module Bridgetown
4
4
  class EntryFilter
5
5
  attr_reader :site
6
6
 
7
- SPECIAL_LEADING_CHAR_REGEX = %r!\A#{Regexp.union([".", "_", "#", "~"])}!o.freeze
8
- SPECIAL_LEADING_CHAR_NO_UNDERSCORES_REGEX = %r!\A#{Regexp.union([".", "#", "~"])}!o.freeze
7
+ SPECIAL_LEADING_CHAR_REGEX = %r!\A#{Regexp.union([".", "_", "#", "~"])}!o
8
+ SPECIAL_LEADING_CHAR_NO_UNDERSCORES_REGEX = %r!\A#{Regexp.union([".", "#", "~"])}!o
9
9
 
10
10
  def initialize(site, base_directory: nil, include_underscores: false)
11
11
  @site = site
@@ -49,11 +49,9 @@ module Bridgetown
49
49
  end
50
50
 
51
51
  def special?(entry)
52
- use_regex = if @include_underscores
53
- SPECIAL_LEADING_CHAR_NO_UNDERSCORES_REGEX
54
- else
52
+ use_regex = @include_underscores ?
53
+ SPECIAL_LEADING_CHAR_NO_UNDERSCORES_REGEX :
55
54
  SPECIAL_LEADING_CHAR_REGEX
56
- end
57
55
 
58
56
  use_regex.match?(entry) || use_regex.match?(File.basename(entry))
59
57
  end
@@ -15,7 +15,7 @@ module Bridgetown
15
15
  InvalidURLError = Class.new(FatalException)
16
16
  InvalidConfigurationError = Class.new(FatalException)
17
17
 
18
- def self.print_build_error(exc, trace: false, logger: Bridgetown.logger, server: false) # rubocop:disable Metrics
18
+ def self.print_build_error(exc, trace: false, logger: Bridgetown.logger, server: false) # rubocop:todo Metrics
19
19
  logger.error "Exception raised:", exc.class.to_s.bold
20
20
  logger.error exc.message.reset_ansi
21
21
 
@@ -28,7 +28,7 @@ module Bridgetown
28
28
  print_trace_msg = false
29
29
  exc.backtrace
30
30
  else
31
- exc.backtrace[0..4]
31
+ exc.backtrace.grep_v(%r!bridgetown-core.+method_missing!)[0..4]
32
32
  end
33
33
  traces.each_with_index do |backtrace_line, index|
34
34
  logger.error "#{index + 1}:", backtrace_line.reset_ansi
@@ -5,19 +5,15 @@ module Bridgetown
5
5
  module FromLiquid
6
6
  extend Liquid::StandardFilters
7
7
 
8
- def strip_html(input)
9
- FromLiquid.strip_html(input)
10
- end
8
+ def strip_html(...) = FromLiquid.strip_html(...)
11
9
 
12
- def strip_newlines(input)
13
- FromLiquid.strip_newlines(input)
14
- end
10
+ def strip_newlines(...) = FromLiquid.strip_newlines(...)
15
11
 
16
- def newline_to_br(input)
17
- FromLiquid.newline_to_br(input)
18
- end
12
+ def newline_to_br(...) = FromLiquid.newline_to_br(...)
19
13
 
20
- # FYI, truncate and truncate words are already provided by ActiveSupport! =)
14
+ def truncate(...) = FromLiquid.truncate(...)
15
+
16
+ def truncate_words(...) = FromLiquid.truncatewords(...)
21
17
  end
22
18
  end
23
19
  end
@@ -11,7 +11,7 @@ module Bridgetown
11
11
  locale ||= maybe_locale(format)
12
12
  format = nil if locale == format
13
13
 
14
- I18n.l(date, format: format, locale: locale)
14
+ I18n.l(date, format:, locale:)
15
15
  end
16
16
 
17
17
  private
@@ -9,7 +9,7 @@ module Bridgetown
9
9
  count = options.delete(:count)
10
10
  options[:count] = count.to_i unless count.nil?
11
11
 
12
- I18n.t(input.to_s, locale: locale, **options)
12
+ I18n.t(input.to_s, locale:, **options)
13
13
  rescue ArgumentError
14
14
  input
15
15
  end
@@ -17,7 +17,7 @@ module Bridgetown
17
17
  private
18
18
 
19
19
  def string_to_hash(options)
20
- options.split(",").to_h { |e| e.split(":").map(&:strip) }.symbolize_keys
20
+ options.split(",").to_h { |e| e.split(":").map(&:strip) }.transform_keys(&:to_sym)
21
21
  end
22
22
  end
23
23
  end