bridgetown-core 1.0.0.alpha5 → 1.0.0.alpha9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/bin/bridgetown +8 -1
  4. data/bridgetown-core.gemspec +2 -3
  5. data/lib/bridgetown-core/cache.rb +1 -1
  6. data/lib/bridgetown-core/collection.rb +1 -1
  7. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +7 -0
  8. data/lib/bridgetown-core/commands/configure.rb +7 -0
  9. data/lib/bridgetown-core/commands/console.rb +38 -12
  10. data/lib/bridgetown-core/commands/doctor.rb +8 -5
  11. data/lib/bridgetown-core/commands/new.rb +3 -2
  12. data/lib/bridgetown-core/commands/start.rb +4 -2
  13. data/lib/bridgetown-core/component.rb +2 -2
  14. data/lib/bridgetown-core/concerns/front_matter_importer.rb +1 -1
  15. data/lib/bridgetown-core/concerns/site/configurable.rb +6 -3
  16. data/lib/bridgetown-core/concerns/site/extensible.rb +2 -1
  17. data/lib/bridgetown-core/concerns/site/ssr.rb +38 -16
  18. data/lib/bridgetown-core/configuration.rb +77 -46
  19. data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
  20. data/lib/bridgetown-core/configurations/cypress/cypress.json +4 -0
  21. data/lib/bridgetown-core/configurations/cypress/cypress_dir/fixtures/example.json +5 -0
  22. data/lib/bridgetown-core/configurations/cypress/cypress_dir/integration/navbar.spec.js +17 -0
  23. data/lib/bridgetown-core/configurations/cypress/cypress_dir/plugins/index.js +21 -0
  24. data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/commands.js +25 -0
  25. data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/index.js +20 -0
  26. data/lib/bridgetown-core/configurations/cypress/cypress_tasks +33 -0
  27. data/lib/bridgetown-core/configurations/cypress.rb +13 -0
  28. data/lib/bridgetown-core/configurations/minitesting.rb +19 -15
  29. data/lib/bridgetown-core/configurations/netlify/netlify.toml +2 -2
  30. data/lib/bridgetown-core/configurations/netlify.rb +2 -4
  31. data/lib/bridgetown-core/configurations/purgecss.rb +2 -2
  32. data/lib/bridgetown-core/configurations/render/render.yaml.erb +26 -0
  33. data/lib/bridgetown-core/configurations/render.rb +6 -0
  34. data/lib/bridgetown-core/configurations/tailwindcss.rb +3 -5
  35. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  36. data/lib/bridgetown-core/converters/serbea_templates.rb +71 -0
  37. data/lib/bridgetown-core/core_ext/psych.rb +1 -5
  38. data/lib/bridgetown-core/frontmatter_defaults.rb +2 -2
  39. data/lib/bridgetown-core/liquid_renderer/file_system.rb +1 -3
  40. data/lib/bridgetown-core/liquid_renderer.rb +1 -1
  41. data/lib/bridgetown-core/model/base.rb +23 -26
  42. data/lib/bridgetown-core/model/builder_origin.rb +8 -6
  43. data/lib/bridgetown-core/model/origin.rb +10 -1
  44. data/lib/bridgetown-core/model/plugin_origin.rb +1 -1
  45. data/lib/bridgetown-core/plugin_manager.rb +9 -36
  46. data/lib/bridgetown-core/rack/boot.rb +46 -23
  47. data/lib/bridgetown-core/rack/roda.rb +2 -1
  48. data/lib/bridgetown-core/rack/routes.rb +2 -2
  49. data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
  50. data/lib/bridgetown-core/readers/plugin_content_reader.rb +1 -1
  51. data/lib/bridgetown-core/renderer.rb +2 -2
  52. data/lib/bridgetown-core/resource/base.rb +3 -3
  53. data/lib/bridgetown-core/resource/relations.rb +1 -1
  54. data/lib/bridgetown-core/resource/taxonomy_term.rb +2 -2
  55. data/lib/bridgetown-core/resource/taxonomy_type.rb +2 -2
  56. data/lib/bridgetown-core/ruby_template_view.rb +2 -2
  57. data/lib/bridgetown-core/site.rb +15 -5
  58. data/lib/bridgetown-core/utils/loaders_manager.rb +72 -0
  59. data/lib/bridgetown-core/utils.rb +13 -14
  60. data/lib/bridgetown-core/version.rb +1 -1
  61. data/lib/bridgetown-core/watcher.rb +16 -7
  62. data/lib/bridgetown-core/yaml_parser.rb +1 -5
  63. data/lib/bridgetown-core.rb +0 -1
  64. data/lib/site_template/README.md +1 -1
  65. data/lib/site_template/Rakefile +3 -3
  66. metadata +31 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e1d25e217de2040b4951a2143b0968808ebcd755055351f1745579d362d57df
4
- data.tar.gz: 61f132206080c941392bcd1f0bb995f349cadea050dba16b6c02753471e48706
3
+ metadata.gz: 913ec78ef91ecd5b8e9f56777878f68bcb31625c9af575597bf56a0bf025f252
4
+ data.tar.gz: f1e4b3292c9f4edf1ebf0318ba2d2751d0b220dc7346536014d4328772cb1879
5
5
  SHA512:
6
- metadata.gz: 0ff3379e1bf073afd9fd9d5d882cea276c3130fa527e64586faba1c91f8e4d5563b8b59f8d4d3f78abe9589f59511d2c68e824803ba314bbf50a1270df07dfd2
7
- data.tar.gz: 7a2afb73e70f34cc0e1e68ee0304c2973b760530ae51f4a6700caad90a897e9c636be4216653b6c08d43accaf9c47380f0217805c7e25c5527ccfafb09510d80
6
+ metadata.gz: f8affaf97ca29c3e093bf0562259bd9d878ccc216ba63a52ceb3388cfd735b92a32add0dadb8a2b748b7ba416c5a9167c0f6983dc5705b9622fbac445f4fd352
7
+ data.tar.gz: 56917b674308b501407ab2a4eb7882cc679794e895291db31f4bc80724c1d1e8cbcabd25b86784300e91b0ec3a0cc80bc8789f01730615965fe4b267b8a6570f
data/.rubocop.yml CHANGED
@@ -11,6 +11,7 @@ AllCops:
11
11
  - vendor/**/*
12
12
  - tmp/**/*
13
13
  - test/source/**/*
14
+ - test/resources/src/_pages/*.rb
14
15
  - lib/site_template/Rakefile
15
16
  - lib/site_template/config.ru
16
17
  - lib/site_template/config/**/*
data/bin/bridgetown CHANGED
@@ -19,11 +19,18 @@ Bridgetown::PluginManager.require_from_bundler
19
19
  # TODO: need to change behavior of Colorator gem
20
20
  ENV["THOR_SHELL"] = "Basic" if ENV["NO_COLOR"]
21
21
 
22
- output_version = if ARGV[0] == "-v"
22
+ output_version = if ARGV[0] == "-v" || ARGV[0] == "--version"
23
23
  puts "bridgetown #{Bridgetown::VERSION} \"#{Bridgetown::CODE_NAME}\""
24
24
  true
25
25
  end
26
26
 
27
+ if env_index = ARGV.index { |arg| arg == "-e" } # rubocop:disable Lint/AssignmentInCondition
28
+ env = ARGV[env_index + 1]
29
+ ENV["BRIDGETOWN_ENV"] = env if env
30
+ elsif env_flag = ARGV.find { |arg| arg.start_with?("--environment=") } # rubocop:disable Lint/AssignmentInCondition
31
+ ENV["BRIDGETOWN_ENV"] = env_flag.split("=").last
32
+ end
33
+
27
34
  ENV["RACK_ENV"] = ENV["BRIDGETOWN_ENV"]
28
35
 
29
36
  require "bridgetown-core/commands/base"
@@ -28,8 +28,7 @@ Gem::Specification.new do |s|
28
28
 
29
29
  s.rdoc_options = ["--charset=UTF-8"]
30
30
 
31
- s.required_ruby_version = ">= 2.5.0"
32
- s.required_rubygems_version = ">= 2.7.0"
31
+ s.required_ruby_version = ">= 2.7.0"
33
32
 
34
33
  s.add_runtime_dependency("activemodel", "~> 6.0")
35
34
  s.add_runtime_dependency("activesupport", "~> 6.0")
@@ -44,12 +43,12 @@ Gem::Specification.new do |s|
44
43
  s.add_runtime_dependency("kramdown", "~> 2.1")
45
44
  s.add_runtime_dependency("kramdown-parser-gfm", "~> 1.0")
46
45
  s.add_runtime_dependency("liquid", "~> 5.0")
47
- s.add_runtime_dependency("liquid-component", ">= 0.1")
48
46
  s.add_runtime_dependency("listen", "~> 3.0")
49
47
  s.add_runtime_dependency("rack-indifferent", ">= 1.2.0")
50
48
  s.add_runtime_dependency("rake", ">= 13.0")
51
49
  s.add_runtime_dependency("roda", "~> 3.46")
52
50
  s.add_runtime_dependency("rouge", "~> 3.0")
51
+ s.add_runtime_dependency("serbea", "~> 1.0")
53
52
  s.add_runtime_dependency("terminal-table", "~> 1.8")
54
53
  s.add_runtime_dependency("thor", "~> 1.1")
55
54
  s.add_runtime_dependency("tilt", "~> 2.0")
@@ -144,7 +144,7 @@ module Bridgetown
144
144
  @base_dir ||= File.join(Bridgetown::Cache.cache_dir, @name)
145
145
  return @base_dir if hash.nil?
146
146
 
147
- File.join(@base_dir, hash[0..1], hash[2..-1]).freeze
147
+ File.join(@base_dir, hash[0..1], hash[2..]).freeze
148
148
  end
149
149
 
150
150
  # Given a key, return a SHA2 hash that can be used for caching this item to disk.
@@ -234,7 +234,7 @@ module Bridgetown
234
234
  end
235
235
 
236
236
  resources.each do |data_resource|
237
- segments = data_resource.relative_path.each_filename.to_a[1..-1]
237
+ segments = data_resource.relative_path.each_filename.to_a[1..]
238
238
  nested = []
239
239
  segments.each_with_index do |segment, index|
240
240
  sanitized_segment = sanitize_filename.(File.basename(segment, ".*"))
@@ -3,6 +3,13 @@
3
3
  module Bridgetown
4
4
  module Commands
5
5
  module ConfigurationOverridable
6
+ def self.included(klass)
7
+ desc = "The environment used for this command (aka development, test, production, etc.)"
8
+ klass.class_option :environment,
9
+ aliases: "-e",
10
+ desc: desc
11
+ end
12
+
6
13
  # Create a full Bridgetown configuration with the options passed in as overrides
7
14
  #
8
15
  # options - the configuration overrides
@@ -41,6 +41,7 @@ module Bridgetown
41
41
  configuration_file = find_in_source_paths("#{configuration}.rb")
42
42
 
43
43
  inside(New.created_site_dir || Dir.pwd) do
44
+ @templates_dir = File.expand_path("../configurations/#{configuration}", __dir__)
44
45
  apply configuration_file, verbose: false
45
46
  end
46
47
  end
@@ -62,6 +63,12 @@ module Bridgetown
62
63
  return Dir.glob("*.rb").map { |file| file.sub(".rb", "") }
63
64
  end
64
65
  end
66
+
67
+ def in_templates_dir(*paths)
68
+ paths.reduce(@templates_dir) do |base, path|
69
+ Bridgetown.sanitized_path(base, path.to_s)
70
+ end
71
+ end
65
72
  end
66
73
  end
67
74
  end
@@ -1,6 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
+ module ConsoleMethods
5
+ def site
6
+ Bridgetown::Current.site
7
+ end
8
+
9
+ def collections
10
+ site.collections
11
+ end
12
+
13
+ def reload!
14
+ Bridgetown.logger.info "Reloading site..."
15
+
16
+ I18n.reload! # make sure any locale files get read again
17
+ Bridgetown::Hooks.trigger :site, :pre_reload, site
18
+ Bridgetown::Hooks.clear_reloadable_hooks
19
+ site.plugin_manager.reload_plugin_files
20
+ site.loaders_manager.reload_loaders
21
+
22
+ ConsoleMethods.site_reset(site)
23
+ end
24
+
25
+ def self.site_reset(site)
26
+ site.reset
27
+ Bridgetown.logger.info "Reading files..."
28
+ site.read
29
+ Bridgetown.logger.info "", "done!"
30
+ Bridgetown.logger.info "Running generators..."
31
+ site.generate
32
+ Bridgetown.logger.info "", "done!"
33
+ end
34
+ end
35
+
4
36
  module Commands
5
37
  class Console < Thor::Group
6
38
  extend Summarizable
@@ -37,24 +69,18 @@ module Bridgetown
37
69
  Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
38
70
  site = Bridgetown::Site.new(configuration_with_overrides(options))
39
71
 
40
- unless options[:blank]
41
- site.reset
42
- Bridgetown.logger.info "Reading files..."
43
- site.read
44
- Bridgetown.logger.info "", "done!"
45
- Bridgetown.logger.info "Running generators..."
46
- site.generate
47
- Bridgetown.logger.info "", "done!"
48
- end
72
+ ConsoleMethods.site_reset(site) unless options[:blank]
49
73
 
50
- $BRIDGETOWN_SITE = site
74
+ IRB::ExtendCommandBundle.include ConsoleMethods
51
75
  IRB.setup(nil)
52
76
  workspace = IRB::WorkSpace.new
53
77
  irb = IRB::Irb.new(workspace)
54
78
  IRB.conf[:IRB_RC]&.call(irb.context)
55
79
  IRB.conf[:MAIN_CONTEXT] = irb.context
56
- eval("site = $BRIDGETOWN_SITE", workspace.binding, __FILE__, __LINE__)
57
- Bridgetown.logger.info "Console:", "Now loaded as #{"site".cyan} variable."
80
+ Bridgetown.logger.info "Console:", "Your site is now available as #{"site".cyan}"
81
+ Bridgetown.logger.info "",
82
+ "You can also access #{"collections".cyan} or perform a" \
83
+ " #{"reload!".cyan}"
58
84
 
59
85
  trap("SIGINT") do
60
86
  irb.signal_handle
@@ -57,8 +57,7 @@ module Bridgetown
57
57
  def conflicting_urls(site)
58
58
  conflicting_urls = false
59
59
  urls = {}
60
- urls = collect_urls(urls, site.pages, site.dest)
61
- urls = collect_urls(urls, site.collections.posts.docs, site.dest)
60
+ urls = collect_urls(urls, site.contents, site.dest)
62
61
  urls.each do |url, paths|
63
62
  next unless paths.size > 1
64
63
 
@@ -98,7 +97,11 @@ module Bridgetown
98
97
 
99
98
  def collect_urls(urls, things, destination)
100
99
  things.each do |thing|
101
- dest = thing.destination(destination)
100
+ dest = if thing.method(:destination).arity == 1
101
+ thing.destination(destination)
102
+ else
103
+ thing.destination
104
+ end
102
105
  if urls[dest]
103
106
  urls[dest] << thing.path
104
107
  else
@@ -110,8 +113,8 @@ module Bridgetown
110
113
 
111
114
  def case_insensitive_urls(things, _destination)
112
115
  things.each_with_object({}) do |thing, memo|
113
- dest = thing.destination.output_path
114
- (memo[dest.downcase] ||= []) << dest
116
+ dest = thing.destination&.output_path
117
+ (memo[dest.downcase] ||= []) << dest if dest
115
118
  end
116
119
  end
117
120
 
@@ -138,7 +138,7 @@ module Bridgetown
138
138
 
139
139
  if @skipped_bundle
140
140
  logger.info "Bundle install skipped.".yellow
141
- logger.info "You will need to run #{"bundle binstub bridgetown-core".cyan} manually."
141
+ logger.info "You will need to run #{"bundle binstubs bridgetown-core".cyan} manually."
142
142
  end
143
143
 
144
144
  logger.info "Yarn install skipped.".yellow if @skipped_yarn
@@ -152,7 +152,8 @@ module Bridgetown
152
152
  Bridgetown.with_unbundled_env do
153
153
  inside(path) do
154
154
  run "bundle install", abort_on_failure: true
155
- run "bundle binstub bridgetown-core"
155
+ run "bundle binstubs bridgetown-core"
156
+ run "cp bin/bridgetown bin/bt"
156
157
  end
157
158
  end
158
159
  end
@@ -30,8 +30,10 @@ module Bridgetown
30
30
  Bridgetown::Commands::Build.print_startup_message
31
31
  sleep 0.25
32
32
 
33
- unless Bundler.definition.specs.find { |s| s.name == "puma" }
34
- raise "** No Rack-compatible server found **"
33
+ begin
34
+ require("puma/detect")
35
+ rescue LoadError
36
+ raise "** Puma server gem not found. Check your Gemfile and Bundler env? **"
35
37
  end
36
38
 
37
39
  options = Thor::CoreExt::HashWithIndifferentAccess.new(self.options)
@@ -164,9 +164,9 @@ module Bridgetown
164
164
  end
165
165
  end
166
166
 
167
- ruby2_keywords def method_missing(method, *args, &block)
167
+ def method_missing(method, *args, **kwargs, &block)
168
168
  if helpers.respond_to?(method.to_sym)
169
- helpers.send method.to_sym, *args, &block
169
+ helpers.send method.to_sym, *args, **kwargs, &block
170
170
  else
171
171
  super
172
172
  end
@@ -32,7 +32,7 @@ module Bridgetown
32
32
  self.front_matter_line_count = ruby_content[1].lines.size
33
33
  process_ruby_data(ruby_content[1], file_path, 2)
34
34
  elsif Bridgetown::Utils.has_rbfm_header?(file_path)
35
- process_ruby_data(File.read(file_path).lines[1..-1].join("\n"), file_path, 2)
35
+ process_ruby_data(File.read(file_path).lines[1..].join("\n"), file_path, 2)
36
36
  elsif is_a?(Layout)
37
37
  self.content = file_contents
38
38
  {}
@@ -155,10 +155,10 @@ class Bridgetown::Site
155
155
  Bridgetown::Cache.disable_disk_cache! if config["disable_disk_cache"]
156
156
  end
157
157
 
158
- def configure_component_paths
158
+ def configure_component_paths # rubocop:todo Metrics/AbcSize
159
159
  # Loop through plugins paths first
160
160
  plugin_components_load_paths = Bridgetown::PluginManager.source_manifests
161
- .map(&:components).compact
161
+ .filter_map(&:components)
162
162
 
163
163
  local_components_load_paths = config["components_dir"].yield_self do |dir|
164
164
  dir.is_a?(Array) ? dir : [dir]
@@ -172,7 +172,10 @@ class Bridgetown::Site
172
172
  end
173
173
  end
174
174
 
175
- @components_load_paths = plugin_components_load_paths + local_components_load_paths
175
+ config.components_load_paths = plugin_components_load_paths + local_components_load_paths
176
+ # Because "first constant wins" in Zeitwerk, we need to load the local
177
+ # source components _before_ we load any from plugins
178
+ config.autoload_paths += config.components_load_paths.reverse
176
179
  end
177
180
 
178
181
  def configure_file_read_opts
@@ -3,13 +3,14 @@
3
3
  class Bridgetown::Site
4
4
  module Extensible
5
5
  # Load necessary libraries, plugins, converters, and generators.
6
+ # This is only ever run once for the lifecycle of the site object.
6
7
  # @see Converter
7
8
  # @see Generator
8
9
  # @see PluginManager
9
10
  # @return [void]
10
11
  def setup
11
12
  plugin_manager.require_plugin_files
12
- plugin_manager.setup_component_loaders
13
+ loaders_manager.setup_loaders
13
14
  self.converters = instantiate_subclasses(Bridgetown::Converter)
14
15
  self.generators = instantiate_subclasses(Bridgetown::Generator)
15
16
  end
@@ -8,29 +8,16 @@ class Bridgetown::Site
8
8
 
9
9
  module ClassMethods
10
10
  # Establish an SSR pipeline for a persistent backend process
11
- def start_ssr! # rubocop:todo Metrics/AbcSize
11
+ def start_ssr!(loaders_manager: nil, &block)
12
12
  if Bridgetown::Current.site
13
13
  raise Bridgetown::Errors::FatalException, "Bridgetown SSR already started! " \
14
14
  "Check your Rack app for threading issues"
15
15
  end
16
16
 
17
17
  Bridgetown::PluginManager.require_from_bundler
18
- site = new(Bridgetown::Current.preloaded_configuration)
18
+ site = new(Bridgetown::Current.preloaded_configuration, loaders_manager: loaders_manager)
19
19
  site.enable_ssr
20
-
21
- Bridgetown::Hooks.trigger :site, :pre_read, site
22
- site.defaults_reader.tap do |d|
23
- d.path_defaults.clear
24
- d.read
25
- end
26
- site.layouts = Bridgetown::LayoutReader.new(site).read
27
- site.collections.data.tap do |coll|
28
- coll.read
29
- site.data = coll.merge_data_resources
30
- end
31
- Bridgetown::Hooks.trigger :site, :post_read, site
32
-
33
- yield(site) if block_given? # provide additional setup hook
20
+ site.ssr_setup(&block)
34
21
 
35
22
  site
36
23
  end
@@ -45,6 +32,41 @@ class Bridgetown::Site
45
32
  @ssr_enabled = true
46
33
  end
47
34
 
35
+ def ssr_setup(&block) # rubocop:disable Metrics/AbcSize
36
+ config.serving = true
37
+ Bridgetown::Hooks.trigger :site, :pre_read, self
38
+ defaults_reader.tap do |d|
39
+ d.path_defaults.clear
40
+ d.read
41
+ end
42
+ reader.read_layouts
43
+ collections.data.tap do |coll|
44
+ coll.read
45
+ self.data = coll.merge_data_resources
46
+ end
47
+ Bridgetown::Hooks.trigger :site, :post_read, self
48
+
49
+ hook = block&.(self) # provide additional setup hook
50
+ return if Bridgetown.env.production?
51
+
52
+ @ssr_reload_hook = hook if hook.is_a?(Proc) && hook.lambda?
53
+ Bridgetown::Watcher.watch(self, config)
54
+ end
55
+
56
+ def ssr_reload
57
+ reset soft: true
58
+ reader.read_layouts
59
+
60
+ collections.data.tap do |coll|
61
+ coll.resources.clear
62
+ coll.read
63
+ coll.merge_data_resources.each do |k, v|
64
+ data[k] = v
65
+ end
66
+ end
67
+ @ssr_reload_hook.() if @ssr_reload_hook.is_a?(Proc)
68
+ end
69
+
48
70
  def disable_ssr
49
71
  Bridgetown.logger.info "SSR:", "now disabled."
50
72
  @ssr_enabled = false
@@ -11,64 +11,68 @@ module Bridgetown
11
11
  # Strings rather than symbols are used for compatibility with YAML.
12
12
  DEFAULTS = {
13
13
  # Where things are
14
- "root_dir" => Dir.pwd,
15
- "plugins_dir" => "plugins",
16
- "source" => File.join(Dir.pwd, "src"),
17
- "destination" => File.join(Dir.pwd, "output"),
18
- "collections_dir" => "",
19
- "cache_dir" => ".bridgetown-cache",
20
- "layouts_dir" => "_layouts",
21
- "data_dir" => "_data",
22
- "components_dir" => "_components",
23
- "partials_dir" => "_partials",
24
- "collections" => {},
25
- "taxonomies" => {
14
+ "root_dir" => Dir.pwd,
15
+ "plugins_dir" => "plugins",
16
+ "source" => File.join(Dir.pwd, "src"),
17
+ "destination" => File.join(Dir.pwd, "output"),
18
+ "collections_dir" => "",
19
+ "cache_dir" => ".bridgetown-cache",
20
+ "layouts_dir" => "_layouts",
21
+ "data_dir" => "_data",
22
+ "components_dir" => "_components",
23
+ "partials_dir" => "_partials",
24
+ "collections" => {},
25
+ "taxonomies" => {
26
26
  category: { key: "categories", title: "Category" }, tag: { key: "tags", title: "Tag" },
27
27
  },
28
+ "autoload_paths" => [],
29
+ "eager_load_paths" => [],
30
+ "autoloader_collapsed_paths" => [],
31
+ "plugins_use_zeitwerk" => true,
28
32
 
29
33
  # Handling Reading
30
- "include" => [".htaccess", "_redirects", ".well-known"],
31
- "exclude" => [],
32
- "keep_files" => [".git", ".svn", "_bridgetown"],
33
- "encoding" => "utf-8",
34
- "markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
35
- "strict_front_matter" => false,
36
- "slugify_mode" => "pretty",
34
+ "include" => [".htaccess", "_redirects", ".well-known"],
35
+ "exclude" => [],
36
+ "keep_files" => [".git", ".svn", "_bridgetown"],
37
+ "encoding" => "utf-8",
38
+ "markdown_ext" => "markdown,mkdown,mkdn,mkd,md",
39
+ "strict_front_matter" => false,
40
+ "slugify_mode" => "pretty",
37
41
 
38
42
  # Filtering Content
39
- "future" => false,
40
- "unpublished" => false,
41
- "ruby_in_front_matter" => true,
43
+ "future" => false,
44
+ "unpublished" => false,
45
+ "ruby_in_front_matter" => true,
42
46
 
43
47
  # Conversion
44
- "content_engine" => "resource",
45
- "markdown" => "kramdown",
46
- "highlighter" => "rouge",
47
- "excerpt_separator" => "\n\n",
48
+ "content_engine" => "resource",
49
+ "markdown" => "kramdown",
50
+ "highlighter" => "rouge",
51
+ "excerpt_separator" => "\n\n",
48
52
 
49
53
  # Serving
50
- "port" => "4000",
51
- "host" => "127.0.0.1",
52
- "base_path" => "/",
53
- "show_dir_listing" => false,
54
+ "port" => "4000",
55
+ "host" => "127.0.0.1",
56
+ "base_path" => "/",
57
+ "show_dir_listing" => false,
54
58
 
55
59
  # Output Configuration
56
- "available_locales" => [:en],
57
- "default_locale" => :en,
58
- "permalink" => nil, # default is set according to content engine
59
- "timezone" => nil, # use the local timezone
60
+ "available_locales" => [:en],
61
+ "default_locale" => :en,
62
+ "permalink" => nil, # default is set according to content engine
63
+ "timezone" => nil, # use the local timezone
60
64
 
61
- "quiet" => false,
62
- "verbose" => false,
63
- "defaults" => [],
65
+ "quiet" => false,
66
+ "verbose" => false,
67
+ "defaults" => [],
64
68
 
65
- "liquid" => {
69
+ "liquid" => {
66
70
  "error_mode" => "warn",
67
71
  "strict_filters" => false,
68
72
  "strict_variables" => false,
69
73
  },
70
74
 
71
- "kramdown" => {
75
+ "kramdown" => {
72
76
  "auto_ids" => true,
73
77
  "toc_levels" => (1..6).to_a,
74
78
  "entity_output" => "as_char",
@@ -98,6 +102,7 @@ module Bridgetown
98
102
  def from(user_config, starting_defaults = DEFAULTS)
99
103
  Utils.deep_merge_hashes(starting_defaults.deep_dup, Configuration[user_config])
100
104
  .merge_environment_specific_options!
105
+ .setup_load_paths!
101
106
  .setup_locales
102
107
  .add_default_collections
103
108
  .add_default_excludes
@@ -109,21 +114,21 @@ module Bridgetown
109
114
  override[config_key] || self[config_key] || DEFAULTS[config_key]
110
115
  end
111
116
 
112
- # Public: Directory of the top-level root where config files are located
117
+ # Directory of the top-level root where config files are located
113
118
  #
114
- # override - the command-line options hash
119
+ # @param override [Hash] options hash which will override value if key is present
115
120
  #
116
- # Returns the path to the Bridgetown root directory
117
- def root_dir(override = "")
121
+ # @return [String] path to the Bridgetown root directory
122
+ def root_dir(override = {})
118
123
  get_config_value_with_override("root_dir", override)
119
124
  end
120
125
 
121
126
  # Public: Directory of the Bridgetown source folder
122
127
  #
123
- # override - the command-line options hash
128
+ # @param override [Hash] options hash which will override value if key is present
124
129
  #
125
- # Returns the path to the Bridgetown source directory
126
- def source(override = "")
130
+ # @return [String] path to the Bridgetown source directory
131
+ def source(override = {})
127
132
  get_config_value_with_override("source", override)
128
133
  end
129
134
 
@@ -240,6 +245,32 @@ module Bridgetown
240
245
  self[k] = self[Bridgetown.environment][k]
241
246
  end
242
247
  delete(Bridgetown.environment)
248
+
249
+ self
250
+ end
251
+
252
+ def setup_load_paths!
253
+ if self[:plugins_use_zeitwerk]
254
+ autoload_paths.unshift({
255
+ path: self[:plugins_dir],
256
+ eager: true,
257
+ })
258
+ end
259
+
260
+ autoload_paths.map! do |load_path|
261
+ if load_path.is_a?(Hash)
262
+ expanded = File.expand_path(load_path[:path], root_dir)
263
+ self[:eager_load_paths] << expanded if load_path[:eager]
264
+ next expanded
265
+ end
266
+
267
+ File.expand_path(load_path, root_dir)
268
+ end
269
+
270
+ autoloader_collapsed_paths.map! do |collapsed_path|
271
+ File.expand_path(collapsed_path, root_dir)
272
+ end
273
+
243
274
  self
244
275
  end
245
276
 
@@ -2,8 +2,6 @@
2
2
 
3
3
  # rubocop:disable all
4
4
 
5
- TEMPLATE_PATH = File.expand_path("./bt-postcss", __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
 
@@ -21,6 +19,6 @@ plugins = %w(postcss-easy-import postcss-mixins postcss-color-function cssnano)
21
19
  say "Adding the following PostCSS plugins: #{plugins.join(' | ')}", :green
22
20
  run "yarn add -D #{plugins.join(' ')}"
23
21
 
24
- copy_file "#{TEMPLATE_PATH}/postcss.config.js", "postcss.config.js", force: true
22
+ copy_file in_templates_dir("postcss.config.js"), "postcss.config.js", force: true
25
23
 
26
24
  # rubocop:enable all
@@ -0,0 +1,4 @@
1
+ {
2
+ "baseUrl": "http://localhost:4000"
3
+ }
4
+
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "Using fixtures to represent data",
3
+ "email": "hello@cypress.io",
4
+ "body": "Fixtures are a great way to mock data for responses to routes"
5
+ }
@@ -0,0 +1,17 @@
1
+ describe("Testing that links exist in the navbar", () => {
2
+ beforeEach(() => {
3
+ cy.visit("/");
4
+ });
5
+ it("navbar links appear on all pages", () => {
6
+ const baseUrl = Cypress.config("baseUrl");
7
+
8
+ cy.get('[href="/"]').click();
9
+ cy.url().should("eq", baseUrl + "/");
10
+
11
+ cy.get('[href="/posts"]').click();
12
+ cy.url().should("eq", baseUrl + "/posts");
13
+
14
+ cy.get('[href="/about"]').click();
15
+ cy.url().should("eq", baseUrl + "/about");
16
+ });
17
+ });
@@ -0,0 +1,21 @@
1
+ /// <reference types="cypress" />
2
+ // ***********************************************************
3
+ // This example plugins/index.js can be used to load plugins
4
+ //
5
+ // You can change the location of this file or turn off loading
6
+ // the plugins file with the 'pluginsFile' configuration option.
7
+ //
8
+ // You can read more here:
9
+ // https://on.cypress.io/plugins-guide
10
+ // ***********************************************************
11
+
12
+ // This function is called when a project is opened or re-opened (e.g. due to
13
+ // the project's config changing)
14
+
15
+ /**
16
+ * @type {Cypress.PluginConfig}
17
+ */
18
+ module.exports = (on, config) => {
19
+ // `on` is used to hook into various events Cypress emits
20
+ // `config` is the resolved Cypress config
21
+ }