bridgetown-core 1.0.0.alpha6 → 1.0.0.alpha7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/bridgetown-core.gemspec +1 -2
  3. data/lib/bridgetown-core/cache.rb +1 -1
  4. data/lib/bridgetown-core/collection.rb +1 -1
  5. data/lib/bridgetown-core/commands/configure.rb +7 -0
  6. data/lib/bridgetown-core/commands/new.rb +1 -0
  7. data/lib/bridgetown-core/component.rb +2 -2
  8. data/lib/bridgetown-core/concerns/front_matter_importer.rb +1 -1
  9. data/lib/bridgetown-core/concerns/site/configurable.rb +6 -3
  10. data/lib/bridgetown-core/concerns/site/extensible.rb +2 -1
  11. data/lib/bridgetown-core/concerns/site/ssr.rb +38 -16
  12. data/lib/bridgetown-core/configuration.rb +77 -46
  13. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
  14. data/lib/bridgetown-core/configurations/cypress/cypress.json +4 -0
  15. data/lib/bridgetown-core/configurations/cypress/cypress_dir/fixtures/example.json +5 -0
  16. data/lib/bridgetown-core/configurations/cypress/cypress_dir/integration/navbar.spec.js +17 -0
  17. data/lib/bridgetown-core/configurations/cypress/cypress_dir/plugins/index.js +21 -0
  18. data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/commands.js +25 -0
  19. data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/index.js +20 -0
  20. data/lib/bridgetown-core/configurations/cypress/cypress_tasks +33 -0
  21. data/lib/bridgetown-core/configurations/cypress.rb +13 -0
  22. data/lib/bridgetown-core/configurations/minitesting.rb +19 -15
  23. data/lib/bridgetown-core/configurations/netlify.rb +2 -4
  24. data/lib/bridgetown-core/configurations/purgecss.rb +2 -2
  25. data/lib/bridgetown-core/configurations/render/render.yaml.erb +26 -0
  26. data/lib/bridgetown-core/configurations/render.rb +6 -0
  27. data/lib/bridgetown-core/configurations/tailwindcss.rb +3 -5
  28. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  29. data/lib/bridgetown-core/core_ext/psych.rb +1 -5
  30. data/lib/bridgetown-core/frontmatter_defaults.rb +2 -2
  31. data/lib/bridgetown-core/liquid_renderer.rb +1 -1
  32. data/lib/bridgetown-core/model/base.rb +23 -26
  33. data/lib/bridgetown-core/model/builder_origin.rb +8 -6
  34. data/lib/bridgetown-core/model/origin.rb +10 -1
  35. data/lib/bridgetown-core/model/plugin_origin.rb +1 -1
  36. data/lib/bridgetown-core/plugin_manager.rb +7 -34
  37. data/lib/bridgetown-core/rack/boot.rb +46 -23
  38. data/lib/bridgetown-core/rack/roda.rb +2 -1
  39. data/lib/bridgetown-core/rack/routes.rb +2 -2
  40. data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
  41. data/lib/bridgetown-core/readers/plugin_content_reader.rb +1 -1
  42. data/lib/bridgetown-core/renderer.rb +2 -2
  43. data/lib/bridgetown-core/resource/base.rb +3 -3
  44. data/lib/bridgetown-core/resource/relations.rb +1 -1
  45. data/lib/bridgetown-core/resource/taxonomy_term.rb +2 -2
  46. data/lib/bridgetown-core/resource/taxonomy_type.rb +2 -2
  47. data/lib/bridgetown-core/ruby_template_view.rb +2 -2
  48. data/lib/bridgetown-core/site.rb +15 -5
  49. data/lib/bridgetown-core/utils/loaders_manager.rb +72 -0
  50. data/lib/bridgetown-core/utils.rb +13 -14
  51. data/lib/bridgetown-core/version.rb +1 -1
  52. data/lib/bridgetown-core/watcher.rb +16 -7
  53. data/lib/bridgetown-core/yaml_parser.rb +1 -5
  54. data/lib/site_template/README.md +1 -1
  55. data/lib/site_template/Rakefile +3 -3
  56. metadata +16 -5
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- TEMPLATE_PATH = File.expand_path("./netlify", __dir__)
4
-
5
- copy_file "#{TEMPLATE_PATH}/netlify.toml", "netlify.toml"
6
- copy_file "#{TEMPLATE_PATH}/netlify.sh", "bin/netlify.sh"
3
+ copy_file in_templates_dir("netlify.toml"), "netlify.toml"
4
+ copy_file in_templates_dir("netlify.sh"), "bin/netlify.sh"
7
5
  `chmod a+x ./bin/netlify.sh`
@@ -6,9 +6,9 @@ say_status :purgecss, "Installing PurgeCSS"
6
6
 
7
7
  run "yarn add -D purgecss"
8
8
 
9
- create_builder "purgecss_builder.rb" do
9
+ create_builder "purgecss.rb" do
10
10
  <<~RUBY
11
- class PurgeCSS < SiteBuilder
11
+ class Builders::Purgecss < SiteBuilder
12
12
  def build
13
13
  unless config[:watch] # don't run in "watch mode"
14
14
  hook :site, :post_write do
@@ -0,0 +1,26 @@
1
+ services:
2
+ - type: web
3
+ name: <%= @render_service_name %>
4
+ env: static
5
+ buildCommand: bin/bridgetown deploy
6
+ staticPublishPath: ./output
7
+ pullRequestPreviewsEnabled: true
8
+ headers:
9
+ - path: /*
10
+ name: X-Frame-Options
11
+ value: DENY
12
+ - path: /*
13
+ name: X-XSS-Protection
14
+ value: "1; mode=block"
15
+ - path: /*
16
+ name: X-Content-Type-Options
17
+ value: "nosniff"
18
+ - path: /*
19
+ name: Strict-Transport-Security
20
+ value: "max-age=15552000; includeSubDomains"
21
+ - path: /*
22
+ name: Referrer-Policy
23
+ value: "no-referrer-when-downgrade"
24
+ - path: /*
25
+ name: Cache-Control
26
+ value: "public, max-age=86400, s-max-age=86400"
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ @render_service_name = ask "What would like to call your Render service?"
4
+ template in_templates_dir("render.yaml.erb"), "render.yaml"
5
+
6
+ say "All done. Just create a new blueprint from the Render dashboard and connect this repo."
@@ -2,8 +2,6 @@
2
2
 
3
3
  # rubocop:disable all
4
4
 
5
- TEMPLATE_PATH = File.expand_path("./tailwindcss", __dir__)
6
-
7
5
  unless File.exist?("postcss.config.js")
8
6
  error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
9
7
 
@@ -19,16 +17,16 @@ return unless confirm.casecmp?("Y")
19
17
  run "yarn add -D tailwindcss"
20
18
  run "npx tailwindcss init"
21
19
 
22
- copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
20
+ copy_file in_templates_dir("postcss.config.js"), "postcss.config.js", force: true
23
21
 
24
22
  run "bundle exec bridgetown configure purgecss"
25
23
 
26
24
  if File.exist?("frontend/styles/index.css")
27
25
  prepend_to_file "frontend/styles/index.css",
28
- File.read("#{TEMPLATE_PATH}/css_imports.css")
26
+ File.read(in_templates_dir("css_imports.css"))
29
27
  else
30
28
  say "\nPlease add the following lines to your CSS index file:"
31
- say File.read("#{TEMPLATE_PATH}/css_imports.css")
29
+ say File.read(in_templates_dir("/css_imports.css"))
32
30
  end
33
31
 
34
32
  # rubocop:enable all
@@ -23,7 +23,7 @@ module Kramdown
23
23
  @options ||= Options.merge(options).freeze
24
24
  @parser ||= begin
25
25
  parser_name = (@options[:input] || "kramdown").to_s
26
- parser_name = parser_name[0..0].upcase + parser_name[1..-1]
26
+ parser_name = parser_name[0..0].upcase + parser_name[1..]
27
27
  try_require("parser", parser_name)
28
28
 
29
29
  if Parser.const_defined?(parser_name)
@@ -6,11 +6,7 @@ module Bridgetown
6
6
  module SafeLoadFile
7
7
  def safe_load_file(filename, **kwargs)
8
8
  File.open(filename, "r:bom|utf-8") do |f|
9
- if RUBY_VERSION.start_with?("2.5")
10
- safe_load f, kwargs[:permitted_classes], [], false, filename
11
- else
12
- safe_load f, filename: filename, **kwargs
13
- end
9
+ safe_load f, filename: filename, **kwargs
14
10
  end
15
11
  end
16
12
  end
@@ -181,7 +181,7 @@ module Bridgetown
181
181
  sets = site.config["defaults"]
182
182
  return [] unless sets.is_a?(Array)
183
183
 
184
- sets.map do |set|
184
+ sets.filter_map do |set|
185
185
  if valid?(set)
186
186
  massage_scope!(set)
187
187
  # TODO: is this trip really necessary?
@@ -191,7 +191,7 @@ module Bridgetown
191
191
  Bridgetown.logger.warn set.to_s
192
192
  nil
193
193
  end
194
- end.compact
194
+ end
195
195
  end
196
196
 
197
197
  # Set path to blank if not specified and alias older type to collection
@@ -15,7 +15,7 @@ module Bridgetown
15
15
 
16
16
  # Set up Liquid file system access to components for the Render tag
17
17
  Liquid::Template.file_system = LiquidRenderer::FileSystem.new(
18
- @site.components_load_paths, "%s.liquid"
18
+ @site.config.components_load_paths, "%s.liquid"
19
19
  )
20
20
  Liquid::Template.file_system.site = site
21
21
 
@@ -9,40 +9,37 @@ module Bridgetown
9
9
  extend ActiveModel::Callbacks # also extends with DescendantsTracker
10
10
  define_model_callbacks :load, :save, :destroy
11
11
 
12
- def self.loads_id?(id)
13
- name == ActiveSupport::Inflector.classify(
14
- URI.parse(id).host.chomp(".collection")
15
- )
16
- end
12
+ class << self
13
+ def find(id)
14
+ unless Bridgetown::Current.site
15
+ raise "A Bridgetown site must be initialized and added to Current"
16
+ end
17
17
 
18
- def self.find(id)
19
- unless Bridgetown::Current.site
20
- raise "A Bridgetown site must be initialized and added to Current"
18
+ origin = origin_for_id(id)
19
+ klass_for_id(id, origin: origin).new(origin.read)
21
20
  end
22
21
 
23
- model_klass = klass_for_id(id)
24
- model_klass.new(read_data_for_id(id))
25
- end
26
-
27
- def self.klass_for_id(id)
28
- descendants.find do |klass|
29
- klass.loads_id?(id)
30
- end || self
31
- end
22
+ def origin_for_id(id)
23
+ scheme = URI.parse(id).scheme
24
+ origin_klass = Origin.descendants.find do |klass|
25
+ klass.handle_scheme?(scheme)
26
+ end
32
27
 
33
- def self.read_data_for_id(id)
34
- origin_for_id(id).read
35
- end
28
+ raise "No origin could be found for #{id}" unless origin_klass
36
29
 
37
- def self.origin_for_id(id)
38
- scheme = URI.parse(id).scheme
39
- origin_klass = Origin.descendants.find do |klass|
40
- klass.handle_scheme?(scheme)
30
+ origin_klass.new(id)
41
31
  end
42
32
 
43
- raise "No origin could be found for #{id}" unless origin_klass
33
+ def klass_for_id(id, origin: nil)
34
+ Bridgetown::Model::Base.descendants.find do |klass|
35
+ klass.will_load_id?(id, origin: origin)
36
+ end || Bridgetown::Model::Base
37
+ end
44
38
 
45
- origin_klass.new(id)
39
+ def will_load_id?(id, origin: nil)
40
+ origin ||= origin_for_id(id)
41
+ origin.verify_model?(self)
42
+ end
46
43
  end
47
44
 
48
45
  class << self
@@ -6,12 +6,14 @@ module Bridgetown
6
6
  # @return [Pathname]
7
7
  attr_reader :relative_path
8
8
 
9
- def self.handle_scheme?(scheme)
10
- scheme == "builder"
11
- end
12
-
13
- def self.id_for_builder_path(builder, path)
14
- "builder://#{builder.class.name.gsub("::", ".")}/#{path}"
9
+ class << self
10
+ def handle_scheme?(scheme)
11
+ scheme == "builder"
12
+ end
13
+
14
+ def id_for_builder_path(builder, path)
15
+ "builder://#{builder.class.name.gsub("::", ".")}/#{path}"
16
+ end
15
17
  end
16
18
 
17
19
  def initialize(id)
@@ -11,7 +11,7 @@ module Bridgetown
11
11
  # @return [String]
12
12
  attr_accessor :id
13
13
 
14
- # Override in subclass
14
+ # You must implement in subclasses
15
15
  def self.handle_scheme?(_scheme)
16
16
  false
17
17
  end
@@ -20,6 +20,15 @@ module Bridgetown
20
20
  self.id = id
21
21
  end
22
22
 
23
+ # You can override in subclass
24
+ def verify_model?(klass)
25
+ collection_name = URI.parse(id).host.chomp(".collection")
26
+
27
+ return klass.collection_name.to_s == collection_name if klass.respond_to?(:collection_name)
28
+
29
+ klass.name == ActiveSupport::Inflector.classify(collection_name)
30
+ end
31
+
23
32
  def read
24
33
  raise "Implement #read in a subclass of Bridgetown::Model::Origin"
25
34
  end
@@ -22,7 +22,7 @@ module Bridgetown
22
22
 
23
23
  def relative_path
24
24
  @relative_path ||= Pathname.new(
25
- Addressable::URI.unescape(url.path.delete_prefix("/")).split("/")[1..-1].join("/")
25
+ Addressable::URI.unescape(url.path.delete_prefix("/")).split("/")[1..].join("/")
26
26
  )
27
27
  end
28
28
 
@@ -5,7 +5,7 @@ module Bridgetown
5
5
  PLUGINS_GROUP = :bridgetown_plugins
6
6
  YARN_DEPENDENCY_REGEXP = %r!(.+)@([^@]*)$!.freeze
7
7
 
8
- attr_reader :site, :component_loaders
8
+ attr_reader :site, :loaders_manager
9
9
 
10
10
  @source_manifests = Set.new
11
11
  @registered_plugins = Set.new
@@ -37,15 +37,14 @@ module Bridgetown
37
37
  # Returns nothing
38
38
  def initialize(site)
39
39
  @site = site
40
- @component_loaders = {}
40
+ @loaders_manager = Bridgetown::Utils::LoadersManager.new(site.config)
41
41
  end
42
42
 
43
43
  def self.require_from_bundler
44
44
  if !ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile")
45
45
  require "bundler"
46
46
 
47
- required_gems = Bundler.require PLUGINS_GROUP
48
- required_gems.select! do |dep|
47
+ required_gems = Bundler.require(PLUGINS_GROUP).select do |dep|
49
48
  (dep.groups & [PLUGINS_GROUP]).any? && dep.should_include?
50
49
  end
51
50
 
@@ -133,12 +132,16 @@ module Bridgetown
133
132
  sorted_plugin_files.each do |plugin_file|
134
133
  self.class.add_registered_plugin plugin_file
135
134
  end
135
+ next if site.config[:plugins_use_zeitwerk]
136
+
136
137
  Bridgetown::Utils::RequireGems.require_with_graceful_fail(sorted_plugin_files)
137
138
  end
138
139
  end
139
140
 
140
141
  # Reload .rb plugin files via the watcher
141
142
  def reload_plugin_files
143
+ return if site.config[:plugins_use_zeitwerk]
144
+
142
145
  plugins_path.each do |plugin_search_path|
143
146
  plugin_files = Utils.safe_glob(plugin_search_path, File.join("**", "*.rb"))
144
147
  Array(plugin_files).each do |name|
@@ -159,35 +162,5 @@ module Bridgetown
159
162
  Array(site.config["plugins_dir"]).map { |d| File.expand_path(d) }
160
163
  end
161
164
  end
162
-
163
- def setup_component_loaders
164
- unless @component_loaders.keys.empty?
165
- @component_loaders.each do |_path, loader|
166
- loader.unload
167
- end
168
- @component_loaders = {}
169
- end
170
-
171
- # Because "first constant wins" in Zeitwerk, we need to load the local
172
- # source components _before_ we load any from plugins
173
- site.components_load_paths.reverse_each do |load_path|
174
- next unless Dir.exist? load_path
175
-
176
- begin
177
- @component_loaders[load_path] = Zeitwerk::Loader.new
178
- @component_loaders[load_path].push_dir(load_path)
179
- @component_loaders[load_path].enable_reloading if load_path.start_with?(site.root_dir)
180
- @component_loaders[load_path].ignore(File.join(load_path, "**", "*.js.rb"))
181
- @component_loaders[load_path].setup
182
- rescue Zeitwerk::Error # rubocop:disable Lint/SuppressedException
183
- end
184
- end
185
- end
186
-
187
- def reload_component_loaders
188
- @component_loaders.each do |path, loader|
189
- loader.reload if path.start_with?(site.root_dir)
190
- end
191
- end
192
165
  end
193
166
  end
@@ -14,9 +14,17 @@ require_relative "static_indexes"
14
14
 
15
15
  module Bridgetown
16
16
  module Rack
17
- def self.boot
18
- autoload_server_folder(root: Dir.pwd)
19
- RodaApp.opts[:bridgetown_preloaded_config] = Bridgetown::Current.preloaded_configuration
17
+ class << self
18
+ # @return [Bridgetown::Utils::LoadersManager]
19
+ attr_accessor :loaders_manager
20
+ end
21
+
22
+ def self.boot(roda_app = nil)
23
+ self.loaders_manager =
24
+ Bridgetown::Utils::LoadersManager.new(Bridgetown::Current.preloaded_configuration)
25
+ autoload_server_folder
26
+ (roda_app || RodaApp).opts[:bridgetown_preloaded_config] =
27
+ Bridgetown::Current.preloaded_configuration
20
28
  rescue Roda::RodaError => e
21
29
  if e.message.include?("sessions plugin :secret option")
22
30
  raise Bridgetown::Errors::InvalidConfigurationError,
@@ -27,29 +35,44 @@ module Bridgetown
27
35
  raise e
28
36
  end
29
37
 
30
- def self.autoload_server_folder(root:)
38
+ # @param root [String] root of Bridgetown site, defaults to config value
39
+ def self.autoload_server_folder( # rubocop:todo Metrics/MethodLength
40
+ root: Bridgetown::Current.preloaded_configuration.root_dir
41
+ )
31
42
  server_folder = File.join(root, "server")
32
- loader = Zeitwerk::Loader.new
33
- loader.push_dir server_folder
34
- loader.enable_reloading unless ENV["BRIDGETOWN_ENV"] == "production"
35
- loader.setup
36
- loader.eager_load
37
- loader.do_not_eager_load(File.join(server_folder, "roda_app.rb"))
38
-
39
- unless ENV["BRIDGETOWN_ENV"] == "production"
40
- begin
41
- Listen.to(server_folder) do |_modified, _added, _removed|
42
- loader.reload
43
- loader.eager_load
44
- Bridgetown::Rack::Routes.reload_subclasses
45
- end.start
46
- # interrupt isn't handled well by the listener
47
- rescue ThreadError # rubocop:disable Lint/SuppressedException
43
+ # Bridgetown::Current.preloaded_configuration.autoload_paths << server_folder
44
+
45
+ Bridgetown::Hooks.register_one(
46
+ :loader, :post_setup, reloadable: false
47
+ ) do |loader, load_path|
48
+ next unless load_path == server_folder
49
+
50
+ loader.eager_load
51
+ loader.do_not_eager_load(File.join(server_folder, "roda_app.rb"))
52
+
53
+ unless ENV["BRIDGETOWN_ENV"] == "production"
54
+ begin
55
+ Listen.to(server_folder) do |_modified, _added, _removed|
56
+ loader.reload
57
+ loader.eager_load
58
+ Bridgetown::Rack::Routes.reload_subclasses
59
+ end.start
60
+ # interrupt isn't handled well by the listener
61
+ rescue ThreadError # rubocop:disable Lint/SuppressedException
62
+ end
48
63
  end
49
64
  end
50
- rescue Zeitwerk::Error
51
- # We assume if there's an error it's because Zeitwerk already registered this folder,
52
- # so it's fine to swallow the error
65
+
66
+ Bridgetown::Hooks.register_one(
67
+ :loader, :post_reload, reloadable: false
68
+ ) do |loader, load_path|
69
+ next unless load_path == server_folder
70
+
71
+ loader.eager_load
72
+ Bridgetown::Rack::Routes.reload_subclasses
73
+ end
74
+
75
+ loaders_manager.setup_loaders([server_folder])
53
76
  end
54
77
  end
55
78
  end
@@ -6,7 +6,8 @@ class Roda
6
6
  module RodaPlugins
7
7
  module BridgetownSSR
8
8
  def self.configure(app, _opts = {}, &block)
9
- app.opts[:bridgetown_site] = Bridgetown::Site.start_ssr!(&block)
9
+ app.opts[:bridgetown_site] =
10
+ Bridgetown::Site.start_ssr!(loaders_manager: Bridgetown::Rack.loaders_manager, &block)
10
11
  end
11
12
  end
12
13
 
@@ -72,9 +72,9 @@ module Bridgetown
72
72
  instance_exec(@_roda_app.request, &self.class.router_block)
73
73
  end
74
74
 
75
- ruby2_keywords def method_missing(method_name, *args, &block)
75
+ def method_missing(method_name, *args, **kwargs, &block)
76
76
  if @_roda_app.respond_to?(method_name.to_sym)
77
- @_roda_app.send method_name.to_sym, *args, &block
77
+ @_roda_app.send method_name.to_sym, *args, **kwargs, &block
78
78
  else
79
79
  super
80
80
  end
@@ -15,7 +15,7 @@ module Bridgetown
15
15
  Layout.new(site, layout_directory, layout_file)
16
16
  end
17
17
 
18
- Bridgetown::PluginManager.source_manifests.map(&:layouts).compact.each do |plugin_layouts|
18
+ Bridgetown::PluginManager.source_manifests.filter_map(&:layouts).each do |plugin_layouts|
19
19
  layout_entries(plugin_layouts).each do |layout_file|
20
20
  @layouts[layout_name(layout_file)] ||= \
21
21
  Layout.new(site, plugin_layouts, layout_file, from_plugin: true)
@@ -40,7 +40,7 @@ module Bridgetown
40
40
  end
41
41
 
42
42
  def add_to(content_type, klass)
43
- existing_paths = content_type.map(&:relative_path).compact
43
+ existing_paths = content_type.filter_map(&:relative_path)
44
44
  @content_files.select { |item| item.is_a?(klass) }.each do |item|
45
45
  content_type << item unless existing_paths.include?(item.relative_path)
46
46
  end
@@ -161,9 +161,9 @@ module Bridgetown
161
161
  end
162
162
 
163
163
  def output_exts
164
- @output_exts ||= converters.map do |c|
164
+ @output_exts ||= converters.filter_map do |c|
165
165
  c.output_ext(document.extname)
166
- end.compact
166
+ end
167
167
  end
168
168
  end
169
169
  end
@@ -255,8 +255,8 @@ module Bridgetown
255
255
  to_h
256
256
  end
257
257
 
258
- ruby2_keywords def to_json(*options)
259
- as_json(*options).to_json(*options)
258
+ def to_json(...)
259
+ as_json(...).to_json(...)
260
260
  end
261
261
 
262
262
  def inspect
@@ -349,7 +349,7 @@ module Bridgetown
349
349
 
350
350
  # Look for alternative front matter or look at the filename pattern: slug.locale.ext
351
351
  def locale_from_alt_data_or_filename
352
- found_locale = data.language || data.lang || basename_without_ext.split(".")[1..-1].last
352
+ found_locale = data.language || data.lang || basename_without_ext.split(".")[1..].last
353
353
  return unless found_locale && site.config.available_locales.include?(found_locale.to_sym)
354
354
 
355
355
  found_locale
@@ -95,7 +95,7 @@ module Bridgetown
95
95
  def belongs_to_relation_for_type(type)
96
96
  if resource.data[type].is_a?(Array)
97
97
  other_slugs = other_collection_for_type(type).resources_by_slug
98
- resource.data[type].map { |slug| other_slugs[slug] }.compact
98
+ resource.data[type].filter_map { |slug| other_slugs[slug] }
99
99
  else
100
100
  other_collection_for_type(type).resources.find do |other_resource|
101
101
  other_resource.data.slug == resource.data[type]
@@ -22,8 +22,8 @@ module Bridgetown
22
22
  to_h
23
23
  end
24
24
 
25
- ruby2_keywords def to_json(*options)
26
- as_json(*options).to_json(*options)
25
+ def to_json(...)
26
+ as_json(...).to_json(...)
27
27
  end
28
28
  end
29
29
  end
@@ -48,8 +48,8 @@ module Bridgetown
48
48
  to_h
49
49
  end
50
50
 
51
- ruby2_keywords def to_json(*options)
52
- as_json(*options).to_json(*options)
51
+ def to_json(...)
52
+ as_json(...).to_json(...)
53
53
  end
54
54
  end
55
55
  end
@@ -61,9 +61,9 @@ module Bridgetown
61
61
  @helpers ||= Helpers.new(self, site)
62
62
  end
63
63
 
64
- ruby2_keywords def method_missing(method_name, *args, &block)
64
+ def method_missing(method_name, *args, **kwargs, &block)
65
65
  if helpers.respond_to?(method_name.to_sym)
66
- helpers.send method_name.to_sym, *args, &block
66
+ helpers.send method_name.to_sym, *args, **kwargs, &block
67
67
  else
68
68
  super
69
69
  end
@@ -13,9 +13,10 @@ module Bridgetown
13
13
  include SSR
14
14
  include Writable
15
15
 
16
- attr_reader :root_dir, :source, :dest, :cache_dir, :config,
17
- :liquid_renderer, :components_load_paths,
18
- :includes_load_paths
16
+ attr_reader :root_dir, :source, :dest, :cache_dir, :config, :liquid_renderer
17
+
18
+ # @return [Bridgetown::Utils::LoadersManager]
19
+ attr_reader :loaders_manager
19
20
 
20
21
  # All files not pages/documents or structured data in the source folder
21
22
  # @return [Array<StaticFile>]
@@ -33,11 +34,20 @@ module Bridgetown
33
34
 
34
35
  # Initialize a new Site.
35
36
  #
36
- # config - A Hash containing site configuration details.
37
- def initialize(config)
37
+ # @param config [Bridgetown::Configuration]
38
+ # @param loaders_manager [Bridgetown::Utils::LoadersManager] initialized if none provided
39
+ def initialize(config, loaders_manager: nil)
38
40
  self.config = config
39
41
  locale
40
42
 
43
+ loaders_manager = if loaders_manager
44
+ loaders_manager.config = self.config
45
+ loaders_manager
46
+ else
47
+ Bridgetown::Utils::LoadersManager.new(self.config)
48
+ end
49
+ @loaders_manager = loaders_manager
50
+
41
51
  @plugin_manager = PluginManager.new(self)
42
52
  @cleaner = Cleaner.new(self)
43
53
  @reader = Reader.new(self)