bridgetown-core 0.21.4 → 1.0.0.alpha4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -0
  3. data/Rakefile +5 -5
  4. data/bin/bridgetown +2 -0
  5. data/bridgetown-core.gemspec +3 -0
  6. data/lib/bridgetown-core/cache.rb +3 -5
  7. data/lib/bridgetown-core/cleaner.rb +2 -10
  8. data/lib/bridgetown-core/collection.rb +62 -86
  9. data/lib/bridgetown-core/commands/base.rb +62 -2
  10. data/lib/bridgetown-core/commands/build.rb +33 -12
  11. data/lib/bridgetown-core/commands/concerns/actions.rb +2 -2
  12. data/lib/bridgetown-core/commands/concerns/build_options.rb +3 -10
  13. data/lib/bridgetown-core/commands/concerns/configuration_overridable.rb +3 -1
  14. data/lib/bridgetown-core/commands/console.rb +3 -3
  15. data/lib/bridgetown-core/commands/doctor.rb +13 -11
  16. data/lib/bridgetown-core/commands/new.rb +14 -6
  17. data/lib/bridgetown-core/commands/plugins.rb +8 -11
  18. data/lib/bridgetown-core/commands/serve/servlet.rb +4 -4
  19. data/lib/bridgetown-core/commands/serve.rb +37 -37
  20. data/lib/bridgetown-core/commands/start.rb +106 -0
  21. data/lib/bridgetown-core/commands/webpack/webpack.defaults.js.erb +2 -2
  22. data/lib/bridgetown-core/commands/webpack.rb +1 -1
  23. data/lib/bridgetown-core/component.rb +2 -6
  24. data/lib/bridgetown-core/concerns/liquid_renderable.rb +2 -2
  25. data/lib/bridgetown-core/concerns/site/configurable.rb +1 -13
  26. data/lib/bridgetown-core/concerns/site/content.rb +7 -118
  27. data/lib/bridgetown-core/concerns/site/extensible.rb +3 -4
  28. data/lib/bridgetown-core/concerns/site/localizable.rb +3 -1
  29. data/lib/bridgetown-core/concerns/site/processable.rb +8 -20
  30. data/lib/bridgetown-core/concerns/site/renderable.rb +19 -30
  31. data/lib/bridgetown-core/concerns/site/ssr.rb +53 -0
  32. data/lib/bridgetown-core/concerns/site/writable.rb +6 -9
  33. data/lib/bridgetown-core/configuration.rb +19 -48
  34. data/lib/bridgetown-core/configurations/minitesting.rb +1 -1
  35. data/lib/bridgetown-core/configurations/turbo.rb +1 -1
  36. data/lib/bridgetown-core/converter.rb +1 -0
  37. data/lib/bridgetown-core/converters/erb_templates.rb +8 -5
  38. data/lib/bridgetown-core/converters/liquid_templates.rb +5 -2
  39. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  40. data/lib/bridgetown-core/converters/smartypants.rb +1 -0
  41. data/lib/bridgetown-core/current.rb +4 -0
  42. data/lib/bridgetown-core/drops/collection_drop.rb +1 -1
  43. data/lib/bridgetown-core/drops/drop.rb +4 -4
  44. data/lib/bridgetown-core/drops/generated_page_drop.rb +23 -0
  45. data/lib/bridgetown-core/drops/resource_drop.rb +3 -3
  46. data/lib/bridgetown-core/drops/site_drop.rb +3 -47
  47. data/lib/bridgetown-core/entry_filter.rb +1 -0
  48. data/lib/bridgetown-core/filters/url_filters.rb +2 -0
  49. data/lib/bridgetown-core/filters.rb +11 -12
  50. data/lib/bridgetown-core/frontmatter_defaults.rb +44 -82
  51. data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -60
  52. data/lib/bridgetown-core/generators/prototype_generator.rb +46 -58
  53. data/lib/bridgetown-core/helpers.rb +8 -3
  54. data/lib/bridgetown-core/hooks.rb +2 -2
  55. data/lib/bridgetown-core/layout.rb +15 -4
  56. data/lib/bridgetown-core/liquid_renderer.rb +1 -3
  57. data/lib/bridgetown-core/log_adapter.rb +1 -1
  58. data/lib/bridgetown-core/log_writer.rb +7 -1
  59. data/lib/bridgetown-core/model/base.rb +12 -4
  60. data/lib/bridgetown-core/model/builder_origin.rb +23 -11
  61. data/lib/bridgetown-core/model/origin.rb +3 -0
  62. data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
  63. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  64. data/lib/bridgetown-core/plugin_manager.rb +10 -10
  65. data/lib/bridgetown-core/publisher.rb +1 -1
  66. data/lib/bridgetown-core/rack/boot.rb +55 -0
  67. data/lib/bridgetown-core/rack/logger.rb +22 -0
  68. data/lib/bridgetown-core/rack/roda.rb +66 -0
  69. data/lib/bridgetown-core/rack/routes.rb +88 -0
  70. data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
  71. data/lib/bridgetown-core/reader.rb +16 -48
  72. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  73. data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
  74. data/lib/bridgetown-core/renderer.rb +2 -12
  75. data/lib/bridgetown-core/resource/base.rb +34 -11
  76. data/lib/bridgetown-core/resource/permalink_processor.rb +23 -12
  77. data/lib/bridgetown-core/resource/relations.rb +2 -3
  78. data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
  79. data/lib/bridgetown-core/resource/transformer.rb +8 -6
  80. data/lib/bridgetown-core/ruby_template_view.rb +6 -8
  81. data/lib/bridgetown-core/site.rb +4 -8
  82. data/lib/bridgetown-core/static_file.rb +14 -21
  83. data/lib/bridgetown-core/tags/find.rb +6 -6
  84. data/lib/bridgetown-core/tags/highlight.rb +5 -5
  85. data/lib/bridgetown-core/tags/include.rb +22 -32
  86. data/lib/bridgetown-core/tags/link.rb +4 -0
  87. data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
  88. data/lib/bridgetown-core/tags/post_url.rb +9 -14
  89. data/lib/bridgetown-core/tags/render_content.rb +2 -2
  90. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +60 -0
  91. data/lib/bridgetown-core/url.rb +5 -4
  92. data/lib/bridgetown-core/utils/aux.rb +57 -0
  93. data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
  94. data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
  95. data/lib/bridgetown-core/utils.rb +44 -11
  96. data/lib/bridgetown-core/version.rb +2 -2
  97. data/lib/bridgetown-core/watcher.rb +4 -6
  98. data/lib/bridgetown-core.rb +16 -23
  99. data/lib/site_template/Gemfile.erb +6 -2
  100. data/lib/site_template/README.md +6 -6
  101. data/lib/site_template/Rakefile +49 -0
  102. data/lib/site_template/bridgetown.config.yml +2 -3
  103. data/lib/site_template/config/puma.rb +27 -0
  104. data/lib/site_template/config.ru +7 -0
  105. data/lib/site_template/package.json.erb +1 -9
  106. data/lib/site_template/server/roda_app.rb +22 -0
  107. data/lib/site_template/server/routes/hello.rb.sample +10 -0
  108. data/lib/site_template/src/_components/head.liquid +2 -1
  109. data/lib/site_template/src/_layouts/default.liquid +1 -1
  110. data/lib/site_template/src/about.md +0 -1
  111. data/lib/site_template/src/posts.md +2 -3
  112. metadata +63 -18
  113. data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
  114. data/lib/bridgetown-core/concerns/validatable.rb +0 -56
  115. data/lib/bridgetown-core/document.rb +0 -437
  116. data/lib/bridgetown-core/drops/document_drop.rb +0 -80
  117. data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
  118. data/lib/bridgetown-core/drops/page_drop.rb +0 -18
  119. data/lib/bridgetown-core/excerpt.rb +0 -200
  120. data/lib/bridgetown-core/readers/data_reader.rb +0 -89
  121. data/lib/bridgetown-core/readers/page_reader.rb +0 -26
  122. data/lib/bridgetown-core/readers/post_reader.rb +0 -109
  123. data/lib/bridgetown-core/regenerator.rb +0 -202
  124. data/lib/bridgetown-core/related_posts.rb +0 -55
  125. data/lib/site_template/config/.keep +0 -0
  126. data/lib/site_template/start.js +0 -17
  127. data/lib/site_template/sync.js +0 -35
@@ -32,8 +32,8 @@ module Bridgetown
32
32
  require "amazing_print" unless options[:"bypass-ap"]
33
33
 
34
34
  Bridgetown.logger.info "Starting:", "Bridgetown v#{Bridgetown::VERSION.magenta}" \
35
- " (codename \"#{Bridgetown::CODE_NAME.yellow}\")" \
36
- " console…"
35
+ " (codename \"#{Bridgetown::CODE_NAME.yellow}\")" \
36
+ " console…"
37
37
  Bridgetown.logger.info "Environment:", Bridgetown.environment.cyan
38
38
  site = Bridgetown::Site.new(configuration_with_overrides(options))
39
39
 
@@ -54,7 +54,7 @@ module Bridgetown
54
54
  IRB.conf[:IRB_RC]&.call(irb.context)
55
55
  IRB.conf[:MAIN_CONTEXT] = irb.context
56
56
  eval("site = $BRIDGETOWN_SITE", workspace.binding, __FILE__, __LINE__)
57
- Bridgetown.logger.info "Console:", "Now loaded as " + "site".cyan + " variable."
57
+ Bridgetown.logger.info "Console:", "Now loaded as #{"site".cyan} variable."
58
58
 
59
59
  trap("SIGINT") do
60
60
  irb.signal_handle
@@ -50,7 +50,7 @@ module Bridgetown
50
50
  "Detected '_posts' directory outside custom `collections_dir`!"
51
51
  Bridgetown.logger.warn "",
52
52
  "Please move '#{posts_at_root}' into the custom directory at " \
53
- "'#{site.in_source_dir(site.config["collections_dir"])}'"
53
+ "'#{site.in_source_dir(site.config["collections_dir"])}'"
54
54
  false
55
55
  end
56
56
 
@@ -64,21 +64,23 @@ module Bridgetown
64
64
 
65
65
  conflicting_urls = true
66
66
  Bridgetown.logger.warn "Conflict:", "The URL '#{url}' is the destination" \
67
- " for the following pages: #{paths.join(", ")}"
67
+ " for the following pages: #{paths.join(", ")}"
68
68
  end
69
69
  conflicting_urls
70
70
  end
71
71
 
72
72
  def urls_only_differ_by_case(site)
73
73
  urls_only_differ_by_case = false
74
- urls = case_insensitive_urls(site.pages + site.docs_to_write, site.dest)
74
+ urls = case_insensitive_urls(site.resources, site.dest)
75
75
  urls.each_value do |real_urls|
76
76
  next unless real_urls.uniq.size > 1
77
77
 
78
78
  urls_only_differ_by_case = true
79
- Bridgetown.logger.warn "Warning:", "The following URLs only differ" \
80
- " by case. On a case-insensitive file system one of the URLs" \
81
- " will be overwritten by the other: #{real_urls.join(", ")}"
79
+ Bridgetown.logger.warn(
80
+ "Warning:",
81
+ "The following URLs only differ by case. On a case-insensitive file system one of the" \
82
+ " URLs will be overwritten by the other: #{real_urls.join(", ")}"
83
+ )
82
84
  end
83
85
  urls_only_differ_by_case
84
86
  end
@@ -106,9 +108,9 @@ module Bridgetown
106
108
  urls
107
109
  end
108
110
 
109
- def case_insensitive_urls(things, destination)
111
+ def case_insensitive_urls(things, _destination)
110
112
  things.each_with_object({}) do |thing, memo|
111
- dest = thing.destination(destination)
113
+ dest = thing.destination.output_path
112
114
  (memo[dest.downcase] ||= []) << dest
113
115
  end
114
116
  end
@@ -117,7 +119,7 @@ module Bridgetown
117
119
  return true unless url.nil? || url.empty?
118
120
 
119
121
  Bridgetown.logger.warn "Warning:", "You didn't set an URL in the config file, "\
120
- "you may encounter problems with some plugins."
122
+ "you may encounter problems with some plugins."
121
123
  false
122
124
  end
123
125
 
@@ -128,7 +130,7 @@ module Bridgetown
128
130
  # https://git.io/vFfbx
129
131
  rescue TypeError
130
132
  Bridgetown.logger.warn "Warning:", "The site URL does not seem to be valid, "\
131
- "check the value of `url` in your config file."
133
+ "check the value of `url` in your config file."
132
134
  false
133
135
  end
134
136
 
@@ -136,7 +138,7 @@ module Bridgetown
136
138
  return true if url.is_a?(String) && Addressable::URI.parse(url).absolute?
137
139
 
138
140
  Bridgetown.logger.warn "Warning:", "Your site URL does not seem to be absolute, "\
139
- "check the value of `url` in your config file."
141
+ "check the value of `url` in your config file."
140
142
  false
141
143
  end
142
144
  end
@@ -59,8 +59,10 @@ module Bridgetown
59
59
 
60
60
  if preserve_source_location?(new_site_path, options)
61
61
  say_status :conflict, "#{new_site_path} exists and is not empty.", :red
62
- Bridgetown.logger.abort_with "Ensure #{new_site_path} is empty or else " \
63
- "try again with `--force` to proceed and overwrite any files."
62
+ Bridgetown.logger.abort_with(
63
+ "Ensure #{new_site_path} is empty or else try again with `--force` to proceed and" \
64
+ " overwrite any files."
65
+ )
64
66
  end
65
67
 
66
68
  self.destination_root = self.class.created_site_dir = new_site_path
@@ -119,21 +121,26 @@ module Bridgetown
119
121
  invoke(Configure, options[:configure].split(","), {}) if options[:configure]
120
122
 
121
123
  logger = Bridgetown.logger
122
- yarn_start = "yarn start"
124
+ bt_start = "bin/bridgetown start"
123
125
  logger.info ""
124
126
  logger.info "Success!".green, "🎉 Your new Bridgetown site was" \
125
- " generated in #{cli_path.cyan}."
127
+ " generated in #{cli_path.cyan}."
126
128
  if options["skip-yarn"]
127
129
  logger.info "You can now #{"cd".cyan} #{cli_path.cyan} to get started."
128
130
  logger.info "You'll probably also want to #{"yarn install".cyan}" \
129
131
  " to load in your frontend assets."
130
132
  else
131
- logger.info "You can now #{"cd".cyan} and run #{yarn_start.cyan} to get started."
133
+ logger.info "You can now #{"cd".cyan} #{cli_path.cyan} and run #{bt_start.cyan}" \
134
+ " to get started."
132
135
  end
133
136
  logger.info "Then check out our online documentation for" \
134
137
  " next steps: #{DOCSURL.cyan}"
135
138
 
136
- logger.info "Bundle install skipped.".yellow if @skipped_bundle
139
+ if @skipped_bundle
140
+ logger.info "Bundle install skipped.".yellow
141
+ logger.info "You will need to run #{"bundle binstub bridgetown-core".cyan} manually."
142
+ end
143
+
137
144
  logger.info "Yarn install skipped.".yellow if @skipped_yarn
138
145
  end
139
146
  # rubocop:enable Metrics/CyclomaticComplexity
@@ -145,6 +152,7 @@ module Bridgetown
145
152
  Bridgetown.with_unbundled_env do
146
153
  inside(path) do
147
154
  run "bundle install", abort_on_failure: true
155
+ run "bundle binstub bridgetown-core"
148
156
  end
149
157
  end
150
158
  end
@@ -112,12 +112,12 @@ module Bridgetown
112
112
  source_manifest.origin.to_s == directive[0]
113
113
  end
114
114
 
115
- if manifest&.respond_to?(directive[1].downcase)
115
+ if manifest.respond_to?(directive[1].downcase)
116
116
  dir = manifest.send(directive[1].downcase)
117
117
  Bridgetown.logger.info("Opening the #{dir.green} folder for" \
118
- " #{manifest.origin.to_s.cyan}…")
118
+ " #{manifest.origin.to_s.cyan}…")
119
119
  Bridgetown.logger.info("Type #{"exit".yellow} when you're done to" \
120
- " return to your site root.")
120
+ " return to your site root.")
121
121
  puts
122
122
 
123
123
  Dir.chdir dir do
@@ -133,20 +133,18 @@ module Bridgetown
133
133
  Bridgetown.logger.info("Done!", "You're back in #{Dir.pwd.green}")
134
134
  else
135
135
  Bridgetown.logger.warn("Oops!", "I wasn't able to find the" \
136
- " #{directive[1]} folder for #{directive[0]}")
136
+ " #{directive[1]} folder for #{directive[0]}")
137
137
  end
138
138
  end
139
139
 
140
140
  desc "new NAME", "Create a new plugin NAME (please-use-dashes) by" \
141
141
  " cloning the sample plugin repo"
142
- # rubocop:disable Layout/LineLength
143
142
  def new(plugin_name)
144
143
  folder_name = plugin_name.underscore
145
144
  name = folder_name.dasherize
146
145
  module_name = folder_name.camelize
147
146
 
148
- # TODO: upon 0.21 release, remove the explicit branch name!
149
- run "git clone -b switch-to-minitest https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
147
+ run "git clone https://github.com/bridgetownrb/bridgetown-sample-plugin #{name}"
150
148
  new_gemspec = "#{name}.gemspec"
151
149
 
152
150
  inside name do # rubocop:todo Metrics/BlockLength
@@ -188,11 +186,10 @@ module Bridgetown
188
186
  say ""
189
187
  say_status "Done!", "Have fun writing your new #{name} plugin :)"
190
188
  say_status "Remember:", "Don't forget to rename the SamplePlugin" \
191
- " code identifiers and paths to your own" \
192
- " indentifer, as well as update your README " \
193
- " and CHANGELOG files as necessary."
189
+ " code identifiers and paths to your own" \
190
+ " indentifer, as well as update your README " \
191
+ " and CHANGELOG files as necessary."
194
192
  end
195
- # rubocop:enable Layout/LineLength
196
193
 
197
194
  protected
198
195
 
@@ -8,7 +8,7 @@ module Bridgetown
8
8
  class Servlet < WEBrick::HTTPServlet::FileHandler
9
9
  DEFAULTS = {
10
10
  "Cache-Control" => "private, max-age=0, proxy-revalidate, " \
11
- "no-store, no-cache, must-revalidate",
11
+ "no-store, no-cache, must-revalidate",
12
12
  }.freeze
13
13
 
14
14
  def initialize(server, root, callbacks)
@@ -51,9 +51,9 @@ module Bridgetown
51
51
  key = res.header.keys.grep(%r!content-type!i).first
52
52
  typ = res.header[key]
53
53
 
54
- unless %r!;\s*charset=!.match?(typ)
55
- res.header[key] = "#{typ}; charset=#{@bridgetown_opts["encoding"]}"
56
- end
54
+ return if %r!;\s*charset=!.match?(typ)
55
+
56
+ res.header[key] = "#{typ}; charset=#{@bridgetown_opts["encoding"]}"
57
57
  end
58
58
 
59
59
  def set_defaults
@@ -34,11 +34,7 @@ module Bridgetown
34
34
  def self.banner
35
35
  "bridgetown serve [options]"
36
36
  end
37
- summary "Serve your site locally using WEBrick"
38
-
39
- class << self
40
- attr_accessor :loaded_config
41
- end
37
+ summary "DEPRECATED (Serve your site locally using WEBrick)"
42
38
 
43
39
  DIRECTORY_INDEX = %w(
44
40
  index.htm
@@ -52,6 +48,10 @@ module Bridgetown
52
48
  ).freeze
53
49
 
54
50
  def serve
51
+ Bridgetown::Deprecator.deprecation_message(
52
+ "WEBrick (serve) will be removed in favor of Puma (start) in the next Bridgetown release"
53
+ )
54
+
55
55
  @mutex = Mutex.new
56
56
  @run_cond = ConditionVariable.new
57
57
  @running = false
@@ -59,14 +59,16 @@ module Bridgetown
59
59
  no_watch = options["watch"] == false
60
60
 
61
61
  options = Thor::CoreExt::HashWithIndifferentAccess.new(self.options)
62
-
63
62
  options["serving"] = true
64
63
  options["watch"] = true unless no_watch
65
64
 
66
- # TODO: this prints the configuration file log message out-of-order
67
- self.class.loaded_config = configuration_with_overrides(options)
65
+ config = Bridgetown::Current.preloaded_configuration ||
66
+ configuration_with_overrides(options)
68
67
  if Bridgetown.environment == "development"
69
- self.class.loaded_config["url"] = default_url(self.class.loaded_config)
68
+ default_url(config).tap do |url|
69
+ options["url"] = url
70
+ config.url = url
71
+ end
70
72
  end
71
73
 
72
74
  invoke(Build, [], options)
@@ -76,23 +78,22 @@ module Bridgetown
76
78
  protected
77
79
 
78
80
  def start_server
79
- config = self.class.loaded_config
80
- destination = config["destination"]
81
+ destination = Bridgetown::Current.preloaded_configuration.destination
81
82
  setup(destination)
82
83
 
83
- start_up_webrick(config, destination)
84
+ start_up_webrick(destination)
84
85
  end
85
86
 
86
87
  def setup(destination)
87
88
  require_relative "serve/servlet"
88
89
 
89
90
  FileUtils.mkdir_p(destination)
90
- if File.exist?(File.join(destination, "404.html"))
91
- WEBrick::HTTPResponse.class_eval do
92
- def create_error_page
93
- @header["Content-Type"] = "text/html; charset=UTF-8"
94
- @body = IO.read(File.join(@config[:DocumentRoot], "404.html"))
95
- end
91
+ return unless File.exist?(File.join(destination, "404.html"))
92
+
93
+ WEBrick::HTTPResponse.class_eval do
94
+ def create_error_page
95
+ @header["Content-Type"] = "text/html; charset=UTF-8"
96
+ @body = File.read(File.join(@config[:DocumentRoot], "404.html"))
96
97
  end
97
98
  end
98
99
  end
@@ -117,7 +118,8 @@ module Bridgetown
117
118
  opts
118
119
  end
119
120
 
120
- def start_up_webrick(opts, destination)
121
+ def start_up_webrick(destination)
122
+ opts = Bridgetown::Current.preloaded_configuration
121
123
  @server = WEBrick::HTTPServer.new(webrick_opts(opts)).tap { |o| o.unmount("") }
122
124
  @server.mount(opts["base_path"].to_s, Servlet, destination, file_handler_opts)
123
125
 
@@ -209,34 +211,32 @@ module Bridgetown
209
211
  begin
210
212
  opts[:SSLPrivateKey] = OpenSSL::PKey::RSA.new(read_file(src, key))
211
213
  rescue StandardError
212
- if defined?(OpenSSL::PKey::EC)
213
- opts[:SSLPrivateKey] = OpenSSL::PKey::EC.new(read_file(src, key))
214
- else
215
- raise
216
- end
214
+ raise unless defined?(OpenSSL::PKey::EC)
215
+
216
+ opts[:SSLPrivateKey] = OpenSSL::PKey::EC.new(read_file(src, key))
217
217
  end
218
218
  opts[:SSLEnable] = true
219
219
  end
220
220
 
221
221
  def start_callback(detached)
222
- unless detached
223
- proc do
224
- @mutex.synchronize do
225
- @running = true
226
- Bridgetown.logger.info("Server running…", "press ctrl-c to stop.")
227
- @run_cond.broadcast
228
- end
222
+ return if detached
223
+
224
+ proc do
225
+ @mutex.synchronize do
226
+ @running = true
227
+ Bridgetown.logger.info("Server running…", "press ctrl-c to stop.")
228
+ @run_cond.broadcast
229
229
  end
230
230
  end
231
231
  end
232
232
 
233
233
  def stop_callback(detached)
234
- unless detached
235
- proc do
236
- @mutex.synchronize do
237
- @running = false
238
- @run_cond.broadcast
239
- end
234
+ return if detached
235
+
236
+ proc do
237
+ @mutex.synchronize do
238
+ @running = false
239
+ @run_cond.broadcast
240
240
  end
241
241
  end
242
242
  end
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Commands
5
+ class Start < Thor::Group
6
+ extend BuildOptions
7
+ extend Summarizable
8
+ include ConfigurationOverridable
9
+
10
+ Registrations.register do
11
+ register(Start, "start", "start", Start.summary)
12
+ register(Start, "dev", "dev", "Alias of start")
13
+ end
14
+
15
+ class_option :bind, aliases: "-B", desc: "URI for Puma to bind to (start with tcp://)"
16
+ class_option :skip_frontend,
17
+ type: :boolean,
18
+ desc: "Don't load the frontend bundler (always true for production)"
19
+ class_option :skip_live_reload,
20
+ type: :boolean,
21
+ desc: "Don't use the live reload functionality (always true for production)"
22
+
23
+ def self.banner
24
+ "bridgetown start [options]"
25
+ end
26
+ summary "Start the Puma server, frontend bundler, and Bridgetown watcher"
27
+
28
+ def start # rubocop:todo Metrics/PerceivedComplexity
29
+ Bridgetown.logger.writer.enable_prefix
30
+ Bridgetown::Commands::Build.print_startup_message
31
+ sleep 0.25
32
+
33
+ unless Bundler.definition.specs.find { |s| s.name == "puma" }
34
+ raise "** No Rack-compatible server found **"
35
+ end
36
+
37
+ options = Thor::CoreExt::HashWithIndifferentAccess.new(self.options)
38
+ options[:using_puma] = true
39
+
40
+ # Load Bridgetown configuration into thread memory
41
+ bt_options = configuration_with_overrides(options)
42
+
43
+ if Bridgetown.env.development? && !options["url"]
44
+ scheme = bt_options.bind&.split("://")&.first == "ssl" ? "https" : "http"
45
+ port = bt_options.bind&.split(":")&.last || ENV["BRIDGETOWN_PORT"] || 4000
46
+ bt_options.url = "#{scheme}://localhost:#{port}"
47
+ end
48
+
49
+ puma_pid =
50
+ Process.fork do
51
+ require "puma/cli"
52
+
53
+ Puma::Runner.class_eval do
54
+ def output_header(mode)
55
+ log "* Puma version: #{Puma::Const::PUMA_VERSION} (#{ruby_engine}) (\"#{Puma::Const::CODE_NAME}\")" # rubocop:disable Layout/LineLength
56
+ if mode == "cluster"
57
+ log "* Cluster Master PID: #{Process.pid}"
58
+ else
59
+ log "* PID: #{Process.pid}"
60
+ end
61
+ end
62
+ end
63
+
64
+ puma_args = []
65
+ if bt_options[:bind]
66
+ puma_args << "--bind"
67
+ puma_args << bt_options[:bind]
68
+ end
69
+
70
+ cli = Puma::CLI.new puma_args
71
+ cli.run
72
+ end
73
+
74
+ begin
75
+ unless Bridgetown.env.production? || options[:skip_frontend]
76
+ require "rake"
77
+ Rake.with_application do |rake|
78
+ rake.load_rakefile
79
+ rake["frontend:watcher"].invoke(true)
80
+ end
81
+ end
82
+
83
+ Signal.trap("TERM") do
84
+ Process.kill "SIGINT", puma_pid
85
+ sleep 0.5 # let it breathe
86
+ exit 0 # this runs the ensure block below
87
+ end
88
+
89
+ Process.setproctitle("bridgetown #{Bridgetown::VERSION} [#{File.basename(Dir.pwd)}]")
90
+
91
+ build_args = ["-w"] + ARGV.reject { |arg| arg == "start" }
92
+ Bridgetown::Commands::Build.start(build_args)
93
+ rescue StandardError => e
94
+ Process.kill "SIGINT", puma_pid
95
+ sleep 0.5
96
+ raise e
97
+ ensure
98
+ # Shut down webpack, browsersync, etc. if they're running
99
+ Bridgetown::Utils::Aux.kill_processes
100
+ end
101
+
102
+ sleep 0.5 # finish cleaning up
103
+ end
104
+ end
105
+ end
106
+ end
@@ -24,8 +24,8 @@ const output = {
24
24
 
25
25
  // Rules and Loaders
26
26
 
27
- const jsRule = {
28
- test: /\.(js|jsx)/,
27
+ const jsRule = {
28
+ test: /\.(js|jsx)$/,
29
29
  use: {
30
30
  loader: "esbuild-loader",
31
31
  options: {
@@ -66,7 +66,7 @@ module Bridgetown
66
66
 
67
67
  longest_action = supported_actions.keys.max_by(&:size).size
68
68
  supported_actions.each do |action, description|
69
- say action.ljust(longest_action).to_s.bold.blue + "\t" + "# #{description}"
69
+ say "#{action.ljust(longest_action).to_s.bold.blue}\t# #{description}"
70
70
  end
71
71
  end
72
72
 
@@ -30,7 +30,7 @@ module Bridgetown
30
30
  #
31
31
  # @param ext [String] erb, slim, etc.
32
32
  def renderer_for_ext(ext, &block)
33
- @_tmpl ||= case ext
33
+ @_tmpl ||= case ext.to_s
34
34
  when "erb"
35
35
  include ERBCapture
36
36
  Tilt::ErubiTemplate.new(component_template_path,
@@ -97,9 +97,7 @@ module Bridgetown
97
97
  #
98
98
  # @return [String] or nil
99
99
  def content
100
- @_content ||= begin
101
- view_context.capture(self, &@_content_block) if @_content_block
102
- end
100
+ @_content ||= (view_context.capture(self, &@_content_block) if @_content_block)
103
101
  end
104
102
 
105
103
  # Provide a render helper for evaluation within the component context.
@@ -166,7 +164,6 @@ module Bridgetown
166
164
  end
167
165
  end
168
166
 
169
- # rubocop:disable Style/MissingRespondToMissing
170
167
  ruby2_keywords def method_missing(method, *args, &block)
171
168
  if helpers.respond_to?(method.to_sym)
172
169
  helpers.send method.to_sym, *args, &block
@@ -178,6 +175,5 @@ module Bridgetown
178
175
  def respond_to_missing?(method, include_private = false)
179
176
  helpers.respond_to?(method.to_sym, include_private) || super
180
177
  end
181
- # rubocop:enable Style/MissingRespondToMissing
182
178
  end
183
179
  end
@@ -14,10 +14,10 @@ module Bridgetown
14
14
  end
15
15
 
16
16
  def liquid_engine_configured?
17
- data["template_engine"] == "liquid" ||
17
+ data["template_engine"].to_s == "liquid" ||
18
18
  (
19
19
  data["template_engine"].nil? && (
20
- site.config[:template_engine].nil? || site.config[:template_engine] == "liquid"
20
+ site.config[:template_engine].nil? || site.config[:template_engine].to_s == "liquid"
21
21
  )
22
22
  )
23
23
  end
@@ -62,18 +62,6 @@ class Bridgetown::Site
62
62
  @frontmatter_defaults ||= Bridgetown::FrontmatterDefaults.new(self)
63
63
  end
64
64
 
65
- # Whether to perform a full rebuild without incremental regeneration.
66
- # If either `override["incremental"]` or `config["incremental"]` are true,
67
- # fully rebuild the site. If not, incrementally build the site.
68
- #
69
- # @param [Hash] override
70
- # An override hash to override the current config value
71
- # @option override [Boolean] "incremental" Whether to incrementally build
72
- # @return [Boolean] true for full rebuild, false for normal build
73
- def incremental?(override = {})
74
- override["incremental"] || config["incremental"]
75
- end
76
-
77
65
  # Returns the current instance of {Publisher} or creates a new instance of
78
66
  # {Publisher} if one doesn't exist.
79
67
  #
@@ -177,7 +165,7 @@ class Bridgetown::Site
177
165
  dir.is_a?(Array) ? dir : [dir]
178
166
  end
179
167
  local_components_load_paths.map! do |dir|
180
- if !!(dir =~ %r!^\.\.?\/!)
168
+ if !!(dir =~ %r!^\.\.?/!)
181
169
  # allow ./dir or ../../dir type options
182
170
  File.expand_path(dir.to_s, root_dir)
183
171
  else