bridgetown-core 2.0.0.beta2 → 2.0.0.beta3

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 (60) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/bridgetown-core.gemspec +1 -1
  4. data/lib/bridgetown-core/cache.rb +3 -19
  5. data/lib/bridgetown-core/cleaner.rb +17 -19
  6. data/lib/bridgetown-core/collection.rb +1 -1
  7. data/lib/bridgetown-core/commands/build.rb +6 -17
  8. data/lib/bridgetown-core/commands/concerns/actions.rb +4 -0
  9. data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +7 -6
  10. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +14 -13
  11. data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
  12. data/lib/bridgetown-core/commands/esbuild/update.rb +17 -3
  13. data/lib/bridgetown-core/commands/esbuild.rb +1 -1
  14. data/lib/bridgetown-core/component.rb +1 -1
  15. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  16. data/lib/bridgetown-core/concerns/publishable.rb +2 -0
  17. data/lib/bridgetown-core/concerns/site/content.rb +4 -1
  18. data/lib/bridgetown-core/concerns/site/extensible.rb +6 -1
  19. data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +20 -13
  20. data/lib/bridgetown-core/concerns/site/localizable.rb +2 -0
  21. data/lib/bridgetown-core/concerns/site/processable.rb +2 -0
  22. data/lib/bridgetown-core/concerns/site/renderable.rb +3 -0
  23. data/lib/bridgetown-core/concerns/site/ssr.rb +0 -1
  24. data/lib/bridgetown-core/configuration.rb +8 -14
  25. data/lib/bridgetown-core/converter.rb +2 -7
  26. data/lib/bridgetown-core/converters/identity.rb +3 -11
  27. data/lib/bridgetown-core/converters/liquid_templates.rb +3 -5
  28. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  29. data/lib/bridgetown-core/converters/markdown.rb +11 -14
  30. data/lib/bridgetown-core/converters/serbea_templates.rb +3 -4
  31. data/lib/bridgetown-core/drops/drop.rb +29 -42
  32. data/lib/bridgetown-core/drops/resource_drop.rb +3 -12
  33. data/lib/bridgetown-core/errors.rb +2 -8
  34. data/lib/bridgetown-core/filters/condition_helpers.rb +6 -9
  35. data/lib/bridgetown-core/filters/date_filters.rb +22 -35
  36. data/lib/bridgetown-core/filters/grouping_filters.rb +11 -11
  37. data/lib/bridgetown-core/filters.rb +53 -72
  38. data/lib/bridgetown-core/front_matter/defaults.rb +8 -13
  39. data/lib/bridgetown-core/generated_page.rb +6 -6
  40. data/lib/bridgetown-core/generators/prototype_generator.rb +0 -2
  41. data/lib/bridgetown-core/hooks.rb +0 -1
  42. data/lib/bridgetown-core/layout.rb +3 -4
  43. data/lib/bridgetown-core/liquid_extensions.rb +3 -5
  44. data/lib/bridgetown-core/log_adapter.rb +37 -56
  45. data/lib/bridgetown-core/plugin_manager.rb +7 -3
  46. data/lib/bridgetown-core/rack/logger.rb +0 -2
  47. data/lib/bridgetown-core/resource/base.rb +8 -8
  48. data/lib/bridgetown-core/resource/permalink_processor.rb +1 -1
  49. data/lib/bridgetown-core/ruby_template_view.rb +0 -1
  50. data/lib/bridgetown-core/static_file.rb +15 -20
  51. data/lib/bridgetown-core/tags/class_map.rb +1 -1
  52. data/lib/bridgetown-core/tags/post_url.rb +2 -32
  53. data/lib/bridgetown-core/utils/require_gems.rb +1 -3
  54. data/lib/bridgetown-core/utils.rb +41 -44
  55. data/lib/bridgetown-core/watcher.rb +2 -3
  56. data/lib/bridgetown-core.rb +1 -2
  57. data/lib/roda/plugins/bridgetown_server.rb +2 -3
  58. data/lib/site_template/package.json.erb +1 -0
  59. data/lib/site_template/postcss.config.js.erb +1 -1
  60. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ad323d78c36221049d27482e186a24793c5e52b478e913b778ba0d8809658990
4
- data.tar.gz: dfc80b46023d5f28e38f2116e62676f579d175f1fcca023c46bb921298c99dc7
3
+ metadata.gz: 6f521946dedcb0f22d30ef1ca8be0aa3c2f1eb967dfc629f0da7c1640ddfba1e
4
+ data.tar.gz: 2f6479875ecc1f3271d20e4b1626c8bff8e305f8e5cb82fa49d6676b786b4495
5
5
  SHA512:
6
- metadata.gz: b0a025a6629018fc3cd5687f6675aee4ce0f4ef0edb740c35b1ba45f1f77df3fc6bb85b658d52a469d9b7f2e83820efcb636a9e062d1b196372fb8cb0b3b447e
7
- data.tar.gz: a7af845632eda73b48f00fe07863f2b90f287e35402239203be296808aa5ae57d41fb3e8a498882254ed3407022f5f88d0895e0e81d59d861f83794f6bdbef76
6
+ metadata.gz: 4036965b0db3c36e648dd4e80cd2656d4aeb03619a37530e6145bf84dbcd6f46eda5ccbaa051f3c605922b72618a4ebdd2de6e2d14962f441afad0ed6bb40a8d
7
+ data.tar.gz: 86b1e921da1dbaf594760f5269d47517ff54498bba74ff721f82d0963308f694a0452715a5b875da963fc29e9074a4221b84e4887aaa36dd6847491d9df0e501
data/.rubocop.yml CHANGED
@@ -43,3 +43,6 @@ Style/OpenStructUse:
43
43
  Style/StringConcatenation:
44
44
  Exclude:
45
45
  - test/test_apply_command.rb
46
+
47
+ Style/SafeNavigationChainLength:
48
+ Enabled: false
@@ -52,7 +52,7 @@ Gem::Specification.new do |s|
52
52
  s.add_runtime_dependency("rouge", [">= 3.0", "< 5.0"])
53
53
  s.add_runtime_dependency("serbea", "~> 2.1")
54
54
  s.add_runtime_dependency("signalize", "~> 1.3")
55
- s.add_runtime_dependency("streamlined", ">= 0.5.2")
55
+ s.add_runtime_dependency("streamlined", ">= 0.6.0")
56
56
  s.add_runtime_dependency("thor", "~> 1.1")
57
57
  s.add_runtime_dependency("tilt", "~> 2.0")
58
58
  s.add_runtime_dependency("zeitwerk", "~> 2.5")
@@ -33,8 +33,6 @@ module Bridgetown
33
33
 
34
34
  # Compare the current config to the cached config
35
35
  # If they are different, clear all caches
36
- #
37
- # Returns nothing.
38
36
  def clear_if_config_changed(config)
39
37
  config = config.inspect
40
38
  cache = Bridgetown::Cache.new "Bridgetown::Cache"
@@ -49,8 +47,6 @@ module Bridgetown
49
47
  private
50
48
 
51
49
  # Delete all cached items from all caches
52
- #
53
- # Returns nothing.
54
50
  def delete_cache_files
55
51
  FileUtils.rm_rf(@cache_dir) if disk_cache_enabled
56
52
  end
@@ -60,9 +56,7 @@ module Bridgetown
60
56
 
61
57
  # Get an existing named cache, or create a new one if none exists
62
58
  #
63
- # name - name of the cache
64
- #
65
- # Returns nothing.
59
+ # @param name [String] name of the cache
66
60
  def initialize(name)
67
61
  @cache = Bridgetown::Cache.base_cache[name] ||= {}
68
62
  @name = name.gsub(%r![^\w\s-]!, "-")
@@ -77,7 +71,7 @@ module Bridgetown
77
71
  # Retrieve a cached item
78
72
  # Raises if key does not exist in cache
79
73
  #
80
- # Returns cached value
74
+ # @return [Object] cached value
81
75
  def [](key)
82
76
  return @cache[key] if @cache.key?(key)
83
77
 
@@ -88,8 +82,6 @@ module Bridgetown
88
82
  end
89
83
 
90
84
  # Add an item to cache
91
- #
92
- # Returns nothing.
93
85
  def []=(key, value)
94
86
  @cache[key] = value
95
87
  return unless disk_cache_enabled?
@@ -112,8 +104,6 @@ module Bridgetown
112
104
  end
113
105
 
114
106
  # Remove one particular item from the cache
115
- #
116
- # Returns nothing.
117
107
  def delete(key)
118
108
  @cache.delete(key)
119
109
  File.delete(path_to(hash(key))) if disk_cache_enabled?
@@ -121,7 +111,7 @@ module Bridgetown
121
111
 
122
112
  # Check if `key` already exists in this cache
123
113
  #
124
- # Returns true if key exists in the cache, false otherwise
114
+ # @return [Boolean] true if key exists in the cache, false otherwise
125
115
  def key?(key)
126
116
  # First, check if item is already cached in memory
127
117
  return true if @cache.key?(key)
@@ -153,14 +143,11 @@ module Bridgetown
153
143
  end
154
144
 
155
145
  # Remove all this caches items from disk
156
- #
157
- # Returns nothing.
158
146
  def delete_cache_files
159
147
  FileUtils.rm_rf(path_to) if disk_cache_enabled?
160
148
  end
161
149
 
162
150
  # Load `path` from disk and return the result.
163
- # This MUST NEVER be called in Safe Mode
164
151
  # rubocop:disable Security/MarshalLoad
165
152
  def load(path)
166
153
  raise unless disk_cache_enabled?
@@ -173,9 +160,6 @@ module Bridgetown
173
160
  # rubocop:enable Security/MarshalLoad
174
161
 
175
162
  # Given a path and a value, save value to disk at path.
176
- # This should NEVER be called in Safe Mode
177
- #
178
- # Returns nothing.
179
163
  def dump(path, value)
180
164
  return unless disk_cache_enabled?
181
165
 
@@ -17,9 +17,9 @@ module Bridgetown
17
17
 
18
18
  private
19
19
 
20
- # Private: The list of files and directories to be deleted during cleanup process
20
+ # The list of files and directories to be deleted during cleanup process
21
21
  #
22
- # Returns an Array of the file and directory paths
22
+ # @return [Array<String>] file and directory paths
23
23
  def obsolete_files
24
24
  out = (existing_files - new_files - new_dirs + replaced_files).to_a
25
25
  Bridgetown::Hooks.trigger :clean, :on_obsolete, out
@@ -27,10 +27,9 @@ module Bridgetown
27
27
  out
28
28
  end
29
29
 
30
- # Private: The list of existing files, apart from those included in
31
- # keep_files and hidden files.
30
+ # The list of existing files, apart from those included in keep_files and hidden files
32
31
  #
33
- # Returns a Set with the file paths
32
+ # @return [Set<String>] file paths
34
33
  def existing_files
35
34
  files = Set.new
36
35
  regex = keep_file_regex
@@ -45,9 +44,9 @@ module Bridgetown
45
44
  files
46
45
  end
47
46
 
48
- # Private: The list of files to be created when site is built.
47
+ # The list of files to be created when site is built.
49
48
  #
50
- # Returns a Set with the file paths
49
+ # @return [Set<String>] file paths
51
50
  def new_files
52
51
  @new_files ||= Set.new.tap do |files|
53
52
  site.each_site_file do |item|
@@ -60,17 +59,17 @@ module Bridgetown
60
59
  end
61
60
  end
62
61
 
63
- # Private: The list of directories to be created when site is built.
62
+ # The list of directories to be created when site is built.
64
63
  # These are the parent directories of the files in #new_files.
65
64
  #
66
- # Returns a Set with the directory paths
65
+ # @return [Set<String>] directory paths
67
66
  def new_dirs
68
67
  @new_dirs ||= new_files.flat_map { |file| parent_dirs(file) }.to_set
69
68
  end
70
69
 
71
- # Private: The list of parent directories of a given file
70
+ # The list of parent directories of a given file
72
71
  #
73
- # Returns an Array with the directory paths
72
+ # @return [Array<String>] directory paths
74
73
  def parent_dirs(file)
75
74
  parent_dir = File.dirname(file)
76
75
  if parent_dir == site.dest
@@ -80,29 +79,28 @@ module Bridgetown
80
79
  end
81
80
  end
82
81
 
83
- # Private: The list of existing files that will be replaced by a directory
84
- # during build
82
+ # The list of existing files that will be replaced by a directory during build
85
83
  #
86
- # Returns a Set with the file paths
84
+ # @return [Set<String>] file paths
87
85
  def replaced_files
88
86
  new_dirs.select { |dir| File.file?(dir) }.to_set
89
87
  end
90
88
 
91
- # Private: The list of directories that need to be kept because they are
89
+ # The list of directories that need to be kept because they are
92
90
  # parent directories of files specified in keep_files
93
91
  #
94
- # Returns a Set with the directory paths
92
+ # @return [Set<String>] directory paths
95
93
  def keep_dirs
96
94
  site.config.keep_files.flat_map { |file| parent_dirs(site.in_dest_dir(file)) }.to_set
97
95
  end
98
96
 
99
- # Private: Creates a regular expression from the config's keep_files array
97
+ # Creates a regular expression from the config's keep_files array
100
98
  #
101
- # Examples
99
+ # @example
102
100
  # ['.git','.svn'] with site.dest "/myblog/_site" creates
103
101
  # the following regex: /\A\/myblog\/_site\/(\.git|\/.svn)/
104
102
  #
105
- # Returns the regular expression
103
+ # @return [Regexp]
106
104
  def keep_file_regex
107
105
  %r!\A#{Regexp.quote(site.dest)}/(#{Regexp.union(site.config.keep_files).source})!
108
106
  end
@@ -400,7 +400,7 @@ module Bridgetown
400
400
 
401
401
  def model_id_from_relative_path(model_relative_path, manifest: nil)
402
402
  scheme = manifest ? "plugin" : "repo"
403
- id = +"#{scheme}://#{label}.collection/"
403
+ id = "#{scheme}://#{label}.collection/"
404
404
  id += "#{manifest.origin}/" if manifest
405
405
  id += Addressable::URI.escape(model_relative_path).gsub("#", "%23")
406
406
  id
@@ -66,11 +66,7 @@ module Bridgetown
66
66
  build_site(config_options)
67
67
  end
68
68
 
69
- # TODO: remove this logic…I can't find "detach" anywhere
70
- if config_options.fetch("detach", false)
71
- Bridgetown.logger.info "Auto-regeneration:",
72
- "disabled when running server detached."
73
- elsif config_options.fetch("watch", false)
69
+ if config_options.fetch("watch", false)
74
70
  watch_site(config_options)
75
71
  else
76
72
  Bridgetown.logger.info "Auto-regeneration:", "disabled. Use --watch to enable."
@@ -79,11 +75,9 @@ module Bridgetown
79
75
 
80
76
  protected
81
77
 
82
- # Build your Bridgetown site.
78
+ # Build your Bridgetown site
83
79
  #
84
- # options - A Hash of options passed to the command or loaded from config
85
- #
86
- # Returns nothing.
80
+ # @param options [Bridgetown::Configuration] options loaded from config and/or CLI
87
81
  def build_site(config_options)
88
82
  t = Time.now
89
83
  display_folder_paths(config_options)
@@ -97,27 +91,22 @@ module Bridgetown
97
91
  "#{(Time.now - t).ceil(2)} seconds."
98
92
  end
99
93
 
100
- # Watch for file changes and rebuild the site.
101
- #
102
- # options - A Hash of options passed to the command or loaded from config
94
+ # Watch for file changes and rebuild the site
103
95
  #
104
- # Returns nothing.
96
+ # @param options [Bridgetown::Configuration] options loaded from config and/or CLI
105
97
  def watch_site(config_options)
106
98
  Bridgetown::Watcher.watch(@site, config_options)
107
99
  end
108
100
 
109
101
  # Display the source and destination folder paths
110
102
  #
111
- # options - A Hash of options passed to the command
112
- #
113
- # Returns nothing.
103
+ # @param options [Bridgetown::Configuration] options loaded from config and/or CLI
114
104
  def display_folder_paths(config_options)
115
105
  source = File.expand_path(config_options["source"])
116
106
  destination = File.expand_path(config_options["destination"])
117
107
  Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
118
108
  Bridgetown.logger.info "Source:", source
119
109
  Bridgetown.logger.info "Destination:", destination
120
- # TODO: work with arrays
121
110
  return unless config_options["plugins_dir"].is_a?(String)
122
111
 
123
112
  plugins_dir = File.expand_path(config_options["plugins_dir"])
@@ -116,6 +116,10 @@ module Bridgetown
116
116
  run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_install_command} #{package_details}" # rubocop:disable Layout
117
117
  end
118
118
 
119
+ def remove_npm_package(package_details)
120
+ run "#{Bridgetown::PluginManager.package_manager} #{Bridgetown::PluginManager.package_manager_uninstall_command} #{package_details}" # rubocop:disable Layout
121
+ end
122
+
119
123
  def apply_from_url(url)
120
124
  apply transform_automation_url(url.dup)
121
125
  end
@@ -1,16 +1,17 @@
1
- const build = require("./config/esbuild.defaults.js")
1
+ import build from "./config/esbuild.defaults.js"
2
2
 
3
3
  // You can customize this as you wish, perhaps to add new esbuild plugins.
4
4
  //
5
5
  // ```
6
- // const path = require("path")
7
- // const esbuildCopy = require('esbuild-plugin-copy').default
6
+ // import { copy } from 'esbuild-plugin-copy'
7
+ //
8
8
  // const esbuildOptions = {
9
9
  // plugins: [
10
- // esbuildCopy({
10
+ // copy({
11
+ // resolveFrom: 'cwd',
11
12
  // assets: {
12
- // from: [path.resolve(__dirname, 'node_modules/somepackage/files/*')],
13
- // to: [path.resolve(__dirname, 'output/_bridgetown/somepackage/files')],
13
+ // from: ['./node_modules/somepackage/files/*')],
14
+ // to: ['./output/_bridgetown/somepackage/files')],
14
15
  // },
15
16
  // verbose: false
16
17
  // }),
@@ -16,19 +16,19 @@ const autogeneratedBridgetownConfig = {
16
16
  "islandsDir": "_islands"
17
17
  }
18
18
 
19
- const path = require("path")
20
- const fsLib = require("fs")
19
+ import path from "path"
20
+ import fsLib from "fs"
21
21
  const fs = fsLib.promises
22
- const { pathToFileURL, fileURLToPath } = require("url")
23
- const glob = require("glob")
24
- const postcss = require("postcss")
25
- const postCssImport = require("postcss-import")
26
- const readCache = require("read-cache")
22
+ import { pathToFileURL, fileURLToPath } from "url"
23
+ import { glob } from "glob"
24
+ import postcss from "postcss"
25
+ import postCssImport from "postcss-import"
26
+ import readCache from "read-cache"
27
27
 
28
28
  // Detect if an NPM package is available
29
29
  const moduleAvailable = name => {
30
30
  try {
31
- require.resolve(name)
31
+ import.meta.resolve(name)
32
32
  return true
33
33
  } catch (e) { }
34
34
  return false
@@ -43,7 +43,7 @@ const generateSourceMappingURL = sourceMap => {
43
43
  // Import Sass if available
44
44
  let sass
45
45
  if (moduleAvailable("sass")) {
46
- sass = require("sass")
46
+ sass = (await import("sass")).default
47
47
  }
48
48
 
49
49
  // Glob plugin derived from:
@@ -288,9 +288,9 @@ const bridgetownConfigured = (bridgetownConfig, outputFolder) => {
288
288
  }
289
289
 
290
290
  // Load the PostCSS config from postcss.config.js or whatever else is a supported location/format
291
- const postcssrc = require("postcss-load-config")
291
+ const postcssrc = (await import("postcss-load-config")).default
292
292
 
293
- module.exports = async (esbuildOptions, ...args) => {
293
+ export default async (esbuildOptions, ...args) => {
294
294
  let outputFolder;
295
295
  if (typeof esbuildOptions === "string") { // legacy syntax where first argument is output folder
296
296
  outputFolder = esbuildOptions
@@ -313,11 +313,12 @@ module.exports = async (esbuildOptions, ...args) => {
313
313
  esbuildOptions.plugins.push(bridgetownPreset(bridgetownConfig))
314
314
  if (esbuildOptions.bridgetownConfig) delete esbuildOptions.bridgetownConfig
315
315
 
316
- const esbuild = require("esbuild")
316
+ const esbuild = (await import("esbuild")).default
317
317
  const entryPoints = esbuildOptions.entryPoints || ["./frontend/javascript/index.js"]
318
318
  if (esbuildOptions.entryPoints) delete esbuildOptions.entryPoints
319
319
 
320
320
  const islands = glob.sync(`./${bridgetownConfig.source}/${bridgetownConfig.islandsDir}/*.{js,js.rb}`).map(item => `./${item}`)
321
+ const islandsAsObject = islands.reduce((obj, str) => obj[str] = str, {})
321
322
 
322
323
  esbuild.context({
323
324
  bundle: true,
@@ -339,7 +340,7 @@ module.exports = async (esbuildOptions, ...args) => {
339
340
  minify: process.argv.includes("--minify"),
340
341
  sourcemap: true,
341
342
  target: "es2020",
342
- entryPoints: [...entryPoints, ...islands],
343
+ entryPoints: Array.isArray(entryPoints) ? [...entryPoints, ...islands] : {...entryPoints, ...islandsAsObject},
343
344
  entryNames: "[dir]/[name].[hash]",
344
345
  outdir: path.join(process.cwd(), `${bridgetownConfig.destination}/_bridgetown/static`),
345
346
  publicPath: "/_bridgetown/static",
@@ -25,7 +25,7 @@ unless Bridgetown.environment.test?
25
25
  confirm = ask "\nThe following packages will be removed: \n\n#{packages_to_remove.join("\n")}\n\nWould you like to continue? [Yn]"
26
26
  return unless confirm.casecmp?("Y")
27
27
 
28
- run "yarn remove #{packages_to_remove.join(" ")}"
28
+ remove_npm_package packages_to_remove.join(" ")
29
29
  end
30
30
  end
31
31
 
@@ -2,8 +2,22 @@
2
2
 
3
3
  template "esbuild.defaults.js.erb", "config/esbuild.defaults.js", force: true
4
4
  copy_file "jsconfig.json"
5
- say "🎉 esbuild configuration updated successfully!"
5
+
6
+ unless File.read("package.json").include?('"type": "module"')
7
+ insert_into_file "package.json",
8
+ after: '"private": true,' do
9
+ <<-JS.chomp
10
+
11
+ "type": "module",
12
+ JS
13
+ end
14
+ end
15
+
16
+ gsub_file "postcss.config.js", "module.exports =", "export default"
17
+ gsub_file "esbuild.config.js", 'const build = require("./config/esbuild.defaults.js")',
18
+ 'import build from "./config/esbuild.defaults.js"'
19
+ add_npm_package "esbuild@latest glob@latest" unless Bridgetown.env.test?
20
+
21
+ say "\n🎉 esbuild configuration updated successfully!"
6
22
  say "You may need to add `$styles/` to the front of your main CSS imports."
7
23
  say "See https://www.bridgetownrb.com/docs/frontend-assets#esbuild-setup for details."
8
- say "⚠️ Don't forget to update the esbuild version in your `package.json` file to \"^0.20.2\""
9
- say "and run `npm install`!"
@@ -3,7 +3,7 @@
3
3
  module Bridgetown
4
4
  module Commands
5
5
  class Esbuild < Thor::Group
6
- include Thor::Actions
6
+ include Thor::Actions, Bridgetown::Commands::Actions
7
7
  extend Summarizable
8
8
 
9
9
  Registrations.register do
@@ -94,7 +94,7 @@ module Bridgetown
94
94
 
95
95
  def path_for_errors
96
96
  File.basename(component_template_path)
97
- rescue RuntimeError
97
+ rescue RuntimeError, TypeError
98
98
  source_location
99
99
  end
100
100
  end
@@ -4,7 +4,7 @@ module Bridgetown
4
4
  module LayoutPlaceable
5
5
  # Determine whether the file should be placed into layouts.
6
6
  #
7
- # Returns false if the document is an asset file or if the front matter
7
+ # @return [Boolean] false if the document is an asset file or if the front matter
8
8
  # specifies `layout: none`
9
9
  def place_in_layout?
10
10
  no_layout?.!
@@ -3,6 +3,8 @@
3
3
  module Bridgetown
4
4
  module Publishable
5
5
  # Whether the resource is published or not, as indicated in YAML front-matter
6
+ #
7
+ # @return [Boolean]
6
8
  def published?
7
9
  !(data.key?("published") && data["published"] == false)
8
10
  end
@@ -27,6 +27,7 @@ class Bridgetown::Site
27
27
  end
28
28
 
29
29
  # Returns the contents of the site metadata file or a blank hash
30
+ #
30
31
  # @return [HashWithDotAccess::Hash] Returns a hash of site metadata
31
32
  def metadata
32
33
  signals["site_metadata"] ||= HashWithDotAccess::Hash.new
@@ -49,7 +50,6 @@ class Bridgetown::Site
49
50
  #
50
51
  # @return [HashWithDotAccess::Hash{String, Symbol => Collection}] A Hash
51
52
  # containing a collection name-to-instance pairs.
52
- #
53
53
  # @return [HashWithDotAccess::Hash] Returns a blank hash if no items found
54
54
  def collections
55
55
  @collections ||= collection_names.each_with_object(
@@ -60,6 +60,7 @@ class Bridgetown::Site
60
60
  end
61
61
 
62
62
  # An array of collection names.
63
+ #
63
64
  # @return [Array<String>] an array of collection names from the configuration,
64
65
  # or an empty array if the `config["collections"]` key is not set.
65
66
  def collection_names
@@ -84,6 +85,7 @@ class Bridgetown::Site
84
85
  end
85
86
 
86
87
  # Get all loaded resources.
88
+ #
87
89
  # @return [Array<Bridgetown::Resource::Base>] an array of resources
88
90
  def resources
89
91
  collections.each_with_object(Set.new) do |(_, collection), set|
@@ -112,6 +114,7 @@ class Bridgetown::Site
112
114
  end
113
115
 
114
116
  # Loads and memoizes the parsed frontend bundler manifest file (if available)
117
+ #
115
118
  # @return [Hash]
116
119
  def frontend_manifest
117
120
  @frontend_manifest ||= begin
@@ -4,6 +4,7 @@ class Bridgetown::Site
4
4
  module Extensible
5
5
  # Load necessary libraries, plugins, converters, and generators.
6
6
  # This is only ever run once for the lifecycle of the site object.
7
+ #
7
8
  # @see Converter
8
9
  # @see Generator
9
10
  # @see PluginManager
@@ -16,6 +17,7 @@ class Bridgetown::Site
16
17
  end
17
18
 
18
19
  # Run all Generators.
20
+ #
19
21
  # @see Generator
20
22
  # @return [void]
21
23
  def generate
@@ -34,6 +36,7 @@ class Bridgetown::Site
34
36
  end
35
37
 
36
38
  # Get the implementation for the given Converter class.
39
+ #
37
40
  # @param klass [Class] The Class of the Converter to fetch.
38
41
  # @return [Converter] Returns the {Converter}
39
42
  # instance implementing the given `Converter` class.
@@ -46,7 +49,8 @@ class Bridgetown::Site
46
49
 
47
50
  # Create an array of instances of the subclasses of the class
48
51
  # passed in as argument.
49
- # @param klass [Class] - class which is the parent of the subclasses.
52
+ #
53
+ # @param klass [Class] class which is the parent of the subclasses.
50
54
  # @return [Array<Converter, Generator>] Returns an array of instances of
51
55
  # subclasses of `klass`.
52
56
  def instantiate_subclasses(klass)
@@ -56,6 +60,7 @@ class Bridgetown::Site
56
60
  end
57
61
 
58
62
  # Shorthand for registering a site hook via {Bridgetown::Hooks}
63
+ #
59
64
  # @param event [Symbol] name of the event (`:pre_read`, `:post_render`, etc.)
60
65
  # @yield the block will be called when the event is triggered
61
66
  # @yieldparam site the site which triggered the event hook
@@ -10,15 +10,16 @@ class Bridgetown::Site
10
10
  @fast_refresh_ordering = 0
11
11
  full_abort = false
12
12
  found_gen_pages = false
13
- paths.each do |path|
14
- res = resources.find do |resource|
13
+ paths.each do |path| # rubocop:todo Metrics
14
+ found_res = resources.select do |resource|
15
15
  resource.id.start_with?("repo://") && in_source_dir(resource.relative_path) == path
16
16
  end
17
17
 
18
18
  layouts_to_reload = Set.new
19
- locate_resource_layouts_and_partials_for_fash_refresh(path, layouts_to_reload) unless res
19
+ locate_resource_layouts_and_partials_for_fash_refresh(path, layouts_to_reload) unless
20
+ found_res.any?
20
21
 
21
- locate_components_for_fast_refresh(path) unless res
22
+ locate_components_for_fast_refresh(path) unless found_res.any?
22
23
 
23
24
  pages = locate_layouts_and_pages_for_fast_refresh(path, layouts_to_reload)
24
25
 
@@ -27,21 +28,22 @@ class Bridgetown::Site
27
28
  self, layout.instance_variable_get(:@base), layout.name
28
29
  )
29
30
  end
30
- liquid_renderer.reset unless layouts_to_reload.empty?
31
- next unless res || !pages.empty?
31
+ next unless found_res.any? || pages.any?
32
32
 
33
- unless pages.empty?
33
+ if pages.any?
34
34
  found_gen_pages = true
35
35
  mark_original_page_resources_for_fast_refresh(pages)
36
36
  next
37
37
  end
38
38
 
39
- res.prepare_for_fast_refresh!.tap { full_abort = true unless _1 }
40
- next unless res.collection.data?
39
+ found_res.each do |res|
40
+ res.prepare_for_fast_refresh!.tap { full_abort = true unless _1 }
41
+ next unless res.collection.data?
41
42
 
42
- res.collection.merge_data_resources.each do |k, v|
43
- data[k] = v
44
- signals[k] = v
43
+ res.collection.merge_data_resources.each do |k, v|
44
+ data[k] = v
45
+ signals[k] = v
46
+ end
45
47
  end
46
48
  end
47
49
 
@@ -60,6 +62,7 @@ class Bridgetown::Site
60
62
 
61
63
  Bridgetown::Hooks.trigger :site, :fast_refresh, self
62
64
 
65
+ liquid_renderer.reset
63
66
  transform_resources_for_fast_refresh(marked_resources, found_gen_pages)
64
67
  transform_generated_pages_for_fast_refresh
65
68
 
@@ -134,7 +137,11 @@ class Bridgetown::Site
134
137
  end
135
138
 
136
139
  def transform_resources_for_fast_refresh(marked_resources, found_gen_pages)
137
- marked_resources.each { _1.transform!.write }
140
+ marked_resources.each do |res|
141
+ render_with_locale(res) do
142
+ res.transform!.write
143
+ end
144
+ end
138
145
  number_of_resources = marked_resources.length
139
146
  number_of_resources += 1 if found_gen_pages
140
147
  Bridgetown.logger.info(
@@ -3,6 +3,7 @@
3
3
  class Bridgetown::Site
4
4
  module Localizable
5
5
  # Returns the current and/or default configured locale
6
+ #
6
7
  # @return String
7
8
  def locale
8
9
  @locale ||= begin
@@ -16,6 +17,7 @@ class Bridgetown::Site
16
17
  end
17
18
 
18
19
  # Sets the current locale for the site
20
+ #
19
21
  # @param new_locale [String] for example: "en" for English, "es" for Spanish
20
22
  def locale=(new_locale)
21
23
  I18n.locale = @locale = new_locale.to_sym
@@ -3,6 +3,7 @@
3
3
  class Bridgetown::Site
4
4
  module Processable
5
5
  # Reset, Read, Generate, Render, Cleanup, Process, and Write this Site to output.
6
+ #
6
7
  # @return [void]
7
8
  # @see #reset
8
9
  # @see #read
@@ -67,6 +68,7 @@ class Bridgetown::Site
67
68
  end
68
69
 
69
70
  # Read data from disk and load it into internal memory.
71
+ #
70
72
  # @return [void]
71
73
  def read
72
74
  Bridgetown::Hooks.trigger :site, :pre_read, self