bridgetown-core 0.21.3 → 1.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) 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 +17 -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 +9 -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/errors.rb +0 -2
  49. data/lib/bridgetown-core/filters/url_filters.rb +2 -0
  50. data/lib/bridgetown-core/filters.rb +11 -12
  51. data/lib/bridgetown-core/frontmatter_defaults.rb +44 -82
  52. data/lib/bridgetown-core/{page.rb → generated_page.rb} +34 -60
  53. data/lib/bridgetown-core/generators/prototype_generator.rb +49 -61
  54. data/lib/bridgetown-core/helpers.rb +8 -3
  55. data/lib/bridgetown-core/hooks.rb +2 -2
  56. data/lib/bridgetown-core/layout.rb +15 -4
  57. data/lib/bridgetown-core/liquid_renderer.rb +1 -3
  58. data/lib/bridgetown-core/log_adapter.rb +1 -1
  59. data/lib/bridgetown-core/log_writer.rb +7 -1
  60. data/lib/bridgetown-core/model/base.rb +12 -4
  61. data/lib/bridgetown-core/model/builder_origin.rb +23 -11
  62. data/lib/bridgetown-core/model/origin.rb +3 -0
  63. data/lib/bridgetown-core/model/plugin_origin.rb +34 -0
  64. data/lib/bridgetown-core/model/repo_origin.rb +1 -1
  65. data/lib/bridgetown-core/plugin_manager.rb +10 -10
  66. data/lib/bridgetown-core/publisher.rb +1 -1
  67. data/lib/bridgetown-core/rack/boot.rb +47 -0
  68. data/lib/bridgetown-core/rack/logger.rb +22 -0
  69. data/lib/bridgetown-core/rack/roda.rb +66 -0
  70. data/lib/bridgetown-core/rack/routes.rb +88 -0
  71. data/lib/bridgetown-core/rack/static_indexes.rb +30 -0
  72. data/lib/bridgetown-core/reader.rb +20 -47
  73. data/lib/bridgetown-core/readers/layout_reader.rb +2 -2
  74. data/lib/bridgetown-core/readers/plugin_content_reader.rb +8 -7
  75. data/lib/bridgetown-core/renderer.rb +2 -12
  76. data/lib/bridgetown-core/resource/base.rb +34 -11
  77. data/lib/bridgetown-core/resource/permalink_processor.rb +23 -12
  78. data/lib/bridgetown-core/resource/relations.rb +2 -3
  79. data/lib/bridgetown-core/resource/taxonomy_term.rb +1 -5
  80. data/lib/bridgetown-core/resource/transformer.rb +8 -6
  81. data/lib/bridgetown-core/ruby_template_view.rb +6 -8
  82. data/lib/bridgetown-core/site.rb +4 -8
  83. data/lib/bridgetown-core/static_file.rb +14 -21
  84. data/lib/bridgetown-core/tags/find.rb +6 -6
  85. data/lib/bridgetown-core/tags/highlight.rb +5 -5
  86. data/lib/bridgetown-core/tags/include.rb +22 -32
  87. data/lib/bridgetown-core/tags/link.rb +4 -0
  88. data/lib/bridgetown-core/tags/live_reload_dev_js.rb +13 -0
  89. data/lib/bridgetown-core/tags/post_url.rb +9 -14
  90. data/lib/bridgetown-core/tags/render_content.rb +2 -2
  91. data/lib/bridgetown-core/tasks/bridgetown_tasks.rake +54 -0
  92. data/lib/bridgetown-core/url.rb +5 -4
  93. data/lib/bridgetown-core/utils/aux.rb +57 -0
  94. data/lib/bridgetown-core/utils/ruby_exec.rb +3 -45
  95. data/lib/bridgetown-core/utils/ruby_front_matter.rb +22 -7
  96. data/lib/bridgetown-core/utils.rb +60 -33
  97. data/lib/bridgetown-core/version.rb +2 -2
  98. data/lib/bridgetown-core/watcher.rb +4 -6
  99. data/lib/bridgetown-core.rb +16 -23
  100. data/lib/site_template/Gemfile.erb +6 -2
  101. data/lib/site_template/README.md +6 -6
  102. data/lib/site_template/Rakefile +49 -0
  103. data/lib/site_template/bridgetown.config.yml +2 -3
  104. data/lib/site_template/config/puma.rb +27 -0
  105. data/lib/site_template/config.ru +7 -0
  106. data/lib/site_template/frontend/javascript/index.js.erb +3 -3
  107. data/lib/site_template/package.json.erb +7 -12
  108. data/lib/site_template/server/roda_app.rb +22 -0
  109. data/lib/site_template/server/routes/hello.rb.sample +10 -0
  110. data/lib/site_template/src/_components/head.liquid +2 -1
  111. data/lib/site_template/src/about.md +0 -1
  112. data/lib/site_template/src/posts.md +2 -3
  113. metadata +63 -18
  114. data/lib/bridgetown-core/concerns/data_accessible.rb +0 -20
  115. data/lib/bridgetown-core/concerns/validatable.rb +0 -56
  116. data/lib/bridgetown-core/document.rb +0 -437
  117. data/lib/bridgetown-core/drops/document_drop.rb +0 -80
  118. data/lib/bridgetown-core/drops/excerpt_drop.rb +0 -19
  119. data/lib/bridgetown-core/drops/page_drop.rb +0 -18
  120. data/lib/bridgetown-core/excerpt.rb +0 -200
  121. data/lib/bridgetown-core/readers/data_reader.rb +0 -89
  122. data/lib/bridgetown-core/readers/page_reader.rb +0 -26
  123. data/lib/bridgetown-core/readers/post_reader.rb +0 -109
  124. data/lib/bridgetown-core/regenerator.rb +0 -202
  125. data/lib/bridgetown-core/related_posts.rb +0 -55
  126. data/lib/site_template/config/.keep +0 -0
  127. data/lib/site_template/start.js +0 -17
  128. data/lib/site_template/sync.js +0 -35
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bridgetown
4
+ module Utils
5
+ module Aux
6
+ def self.with_color(name, message)
7
+ return message unless !name.nil? && Bridgetown::Utils::Ansi::COLORS[name.to_sym]
8
+
9
+ Bridgetown::Utils::Ansi.send(name, message)
10
+ end
11
+
12
+ def self.running_pids
13
+ @running_pids ||= []
14
+ end
15
+
16
+ def self.add_pid(pid)
17
+ running_pids << pid
18
+ end
19
+
20
+ def self.run_process(name, color, cmd)
21
+ Thread.new do
22
+ rd, wr = IO.pipe("BINARY")
23
+ pid = Process.spawn(cmd, out: wr, err: wr, pgroup: true)
24
+ @mutex.synchronize do
25
+ add_pid pid
26
+ end
27
+
28
+ loop do
29
+ line = rd.gets
30
+ line.to_s.lines.map(&:chomp).each do |message|
31
+ output = +""
32
+ output << with_color(color, "[#{name}] ") if color
33
+ output << message
34
+ @mutex.synchronize do
35
+ $stdout.puts output
36
+ $stdout.flush
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def self.group(&block)
44
+ @mutex = Thread::Mutex.new
45
+ instance_exec(&block)
46
+ end
47
+
48
+ def self.kill_processes
49
+ Bridgetown.logger.info "Stopping auxiliary processes..."
50
+ running_pids.each do |pid|
51
+ Process.kill("SIGTERM", -Process.getpgid(pid))
52
+ rescue Errno::ESRCH, Errno::EPERM, Errno::ECHILD # rubocop:disable Lint/SuppressedException
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -3,10 +3,7 @@
3
3
  module Bridgetown
4
4
  module Utils
5
5
  module RubyExec
6
- extend self
7
-
8
- # TODO: Deprecate storing Ruby code in YAML, Rb, etc. and just use native Ruby Front Matter
9
- def search_data_for_ruby_code(convertible, renderer) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
6
+ def self.search_data_for_ruby_code(convertible)
10
7
  return if convertible.data.empty?
11
8
 
12
9
  # Iterate using `keys` here so inline Ruby script can add new data keys
@@ -14,49 +11,10 @@ module Bridgetown
14
11
  data_keys = convertible.data.keys
15
12
  data_keys.each do |k|
16
13
  v = convertible.data[k]
17
- next unless v.is_a?(Rb) || v.is_a?(Hash) || v.is_a?(Proc)
18
-
19
- if v.is_a?(Proc)
20
- convertible.data[k] = convertible.instance_exec(&v)
21
- elsif v.is_a?(Hash)
22
- v.each do |nested_k, nested_v|
23
- next unless nested_v.is_a?(Rb)
24
-
25
- convertible.data[k][nested_k] = run(nested_v, convertible, renderer)
26
- end
27
- else
28
- convertible.data[k] = run(v, convertible, renderer)
29
- end
30
- end
31
- end
32
-
33
- # Sets up a new context in which to eval Ruby coming from front matter.
34
- #
35
- # ruby_code - a string of code
36
- # convertible - the Document/Page/Layout with the Ruby front matter
37
- # renderer - the Renderer instance that's processing the document (optional)
38
- #
39
- # Returns the transformed output of the code
40
- def run(ruby_code, convertible, renderer)
41
- return unless ruby_code.is_a?(Rb)
14
+ next unless v.is_a?(Proc)
42
15
 
43
- klass = Class.new
44
- obj = klass.new
45
-
46
- if convertible.is_a?(Layout)
47
- klass.attr_accessor :layout, :site, :data
48
- obj.layout = convertible
49
- else
50
- klass.attr_accessor :document, :page, :renderer, :site, :data
51
- obj.document = obj.page = convertible
52
- obj.renderer = renderer
16
+ convertible.data[k] = convertible.instance_exec(&v)
53
17
  end
54
- obj.site = convertible.site
55
- obj.data = convertible.data
56
-
57
- # This is where the magic happens! DON'T BE EVIL!!! ;-)
58
- output = obj.instance_eval(ruby_code)
59
- output.is_a?(Hash) ? output.with_dot_access : output
60
18
  end
61
19
  end
62
20
  end
@@ -3,20 +3,23 @@
3
3
  module Bridgetown
4
4
  module Utils
5
5
  module RubyFrontMatterDSL
6
- def front_matter(&block)
7
- RubyFrontMatter.new.tap { |fm| fm.instance_exec(&block) }
6
+ def front_matter(scope: nil, &block)
7
+ RubyFrontMatter.new(scope: scope).tap { |fm| fm.instance_exec(&block) }
8
8
  end
9
9
  end
10
10
 
11
11
  class RubyFrontMatter
12
- def initialize
12
+ def initialize(scope: nil)
13
13
  @data = {}
14
+ @scope = scope
14
15
  end
15
16
 
16
- def method_missing(key, value) # rubocop:disable Style/MissingRespondToMissing
17
- return super if respond_to?(key)
17
+ def method_missing(key, *value, &block) # rubocop:disable Metrics/CyclomaticComplexity, Style/MissingRespondToMissing
18
+ return super if respond_to?(key) || (value.length.zero? && block.nil? && !@data.key?(key))
18
19
 
19
- set(key, value)
20
+ return get(key) if value.length.zero? && block.nil? && @data.key?(key)
21
+
22
+ set(key, value[0], &block)
20
23
  end
21
24
 
22
25
  def each(&block)
@@ -27,7 +30,19 @@ module Bridgetown
27
30
  @data[key]
28
31
  end
29
32
 
30
- def set(key, value)
33
+ def set(key, value = nil, &block)
34
+ # Handle nested data within a block
35
+ if block
36
+ value = self.class.new(scope: @scope).tap do |fm|
37
+ fm.instance_exec(&block)
38
+ end.to_h
39
+ end
40
+
41
+ # Execute lambda value within the resolver
42
+ if @scope && value.is_a?(Hash) && value[:from].is_a?(Proc)
43
+ value = @scope.instance_exec(&value[:from])
44
+ end
45
+
31
46
  @data[key] = value
32
47
  end
33
48
 
@@ -1,16 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- module Utils
4
+ module Utils # rubocop:todo Metrics/ModuleLength
5
5
  extend self
6
6
  autoload :Ansi, "bridgetown-core/utils/ansi"
7
+ autoload :Aux, "bridgetown-core/utils/aux"
7
8
  autoload :RequireGems, "bridgetown-core/utils/require_gems"
8
9
  autoload :RubyExec, "bridgetown-core/utils/ruby_exec"
10
+ autoload :RubyFrontMatter, "bridgetown-core/utils/ruby_front_matter"
9
11
  autoload :RubyFrontMatterDSL, "bridgetown-core/utils/ruby_front_matter"
10
12
 
11
13
  # Constants for use in #slugify
12
14
  SLUGIFY_MODES = %w(raw default pretty simple ascii latin).freeze
13
- SLUGIFY_RAW_REGEXP = Regexp.new('\\s+').freeze
15
+ SLUGIFY_RAW_REGEXP = Regexp.new("\\s+").freeze
14
16
  SLUGIFY_DEFAULT_REGEXP = Regexp.new("[^\\p{M}\\p{L}\\p{Nd}]+").freeze
15
17
  SLUGIFY_PRETTY_REGEXP = Regexp.new("[^\\p{M}\\p{L}\\p{Nd}._~!$&'()+,;=@]+").freeze
16
18
  SLUGIFY_ASCII_REGEXP = Regexp.new("[^[A-Za-z0-9]]+").freeze
@@ -201,7 +203,7 @@ module Bridgetown
201
203
  slug = replace_character_sequence_with_hyphen(string, mode: mode)
202
204
 
203
205
  # Remove leading/trailing hyphen
204
- slug.gsub!(%r!^\-|\-$!i, "")
206
+ slug.gsub!(%r!^-|-$!i, "")
205
207
 
206
208
  slug.downcase! unless cased
207
209
 
@@ -314,9 +316,7 @@ module Bridgetown
314
316
  lines.map do |line|
315
317
  continue_processing = !skip_pre_lines
316
318
 
317
- if skip_pre_lines
318
- skip_pre_lines = false if line.include?("</pre>")
319
- end
319
+ skip_pre_lines = false if skip_pre_lines && line.include?("</pre>")
320
320
  if line.include?("<pre")
321
321
  skip_pre_lines = true
322
322
  continue_processing = false
@@ -338,7 +338,7 @@ module Bridgetown
338
338
  else
339
339
  line
340
340
  end
341
- end.join("")
341
+ end.join
342
342
  end
343
343
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength, Metrics/PerceivedComplexity
344
344
 
@@ -354,28 +354,19 @@ module Bridgetown
354
354
  # @raise [WebpackAssetError] if unable to find css or js in the manifest
355
355
  # file
356
356
  def parse_webpack_manifest_file(site, asset_type)
357
- manifest_file = site.in_root_dir(".bridgetown-webpack", "manifest.json")
358
- return "MISSING_WEBPACK_MANIFEST" unless File.exist?(manifest_file)
357
+ return log_webpack_asset_error("Webpack manifest") if site.frontend_manifest.nil?
359
358
 
360
- manifest = JSON.parse(File.read(manifest_file))
359
+ asset_path = if %w(js css).include?(asset_type)
360
+ site.frontend_manifest["main.#{asset_type}"]
361
+ else
362
+ site.frontend_manifest.find do |item, _|
363
+ item.sub(%r{^../(frontend/|src/)?}, "") == asset_type
364
+ end&.last
365
+ end
361
366
 
362
- known_assets = %w(js css)
363
- asset_path = nil
364
- if known_assets.include?(asset_type)
365
- asset_path = manifest["main.#{asset_type}"]
366
- log_webpack_asset_error(asset_type) && return if asset_path.nil?
367
- else
368
- asset_path = manifest.find do |item, _|
369
- item.sub(%r{^../(frontend/|src/)?}, "") == asset_type
370
- end&.last
371
- end
367
+ return log_webpack_asset_error(asset_type) if asset_path.nil?
372
368
 
373
- if asset_path
374
- static_frontend_path(site, ["js", asset_path])
375
- else
376
- Bridgetown.logger.error("Unknown Webpack asset type", asset_type)
377
- nil
378
- end
369
+ static_frontend_path site, ["js", asset_path]
379
370
  end
380
371
 
381
372
  def static_frontend_path(site, additional_parts = [])
@@ -389,10 +380,13 @@ module Bridgetown
389
380
  end
390
381
 
391
382
  def log_webpack_asset_error(asset_type)
392
- error_message = "There was an error parsing your #{asset_type} files. \
393
- Please check your #{asset_type} for any errors."
383
+ Bridgetown.logger.warn(
384
+ "Webpack:",
385
+ "There was an error parsing your #{asset_type} file. \
386
+ Please check your #{asset_type} file for any errors."
387
+ )
394
388
 
395
- Bridgetown.logger.warn(Errors::WebpackAssetError, error_message)
389
+ "MISSING_WEBPACK_MANIFEST_FILE"
396
390
  end
397
391
 
398
392
  def default_github_branch_name(repo_url)
@@ -404,6 +398,39 @@ module Bridgetown
404
398
  "master"
405
399
  end
406
400
 
401
+ def live_reload_js(site) # rubocop:disable Metrics/MethodLength
402
+ return "" unless Bridgetown.env.development? && !site.config.skip_live_reload
403
+
404
+ code = <<~JAVASCRIPT
405
+ let first_mod = 0
406
+ let connection_errors = 0
407
+ const checkForReload = () => {
408
+ fetch("/_bridgetown/live_reload").then(response => {
409
+ if (response.ok) {
410
+ response.json().then(data => {
411
+ const last_mod = data.last_mod
412
+ if (first_mod === 0) {
413
+ first_mod = last_mod
414
+ } else if (last_mod > first_mod) {
415
+ location.reload()
416
+ }
417
+ setTimeout(() => checkForReload(), 700)
418
+ })
419
+ } else {
420
+ if (connection_errors < 20) setTimeout(() => checkForReload(), 6000)
421
+ connection_errors++
422
+ }
423
+ }).catch((err) => {
424
+ if (connection_errors < 20) setTimeout(() => checkForReload(), 6000)
425
+ connection_errors++
426
+ })
427
+ }
428
+ checkForReload()
429
+ JAVASCRIPT
430
+
431
+ %(<script type="module">#{code}</script>).html_safe
432
+ end
433
+
407
434
  private
408
435
 
409
436
  def merge_values(target, overwrite)
@@ -419,9 +446,9 @@ module Bridgetown
419
446
  end
420
447
 
421
448
  def merge_default_proc(target, overwrite)
422
- if target.is_a?(Hash) && overwrite.is_a?(Hash) && target.default_proc.nil?
423
- target.default_proc = overwrite.default_proc
424
- end
449
+ return unless target.is_a?(Hash) && overwrite.is_a?(Hash) && target.default_proc.nil?
450
+
451
+ target.default_proc = overwrite.default_proc
425
452
  end
426
453
 
427
454
  def duplicate_frozen_values(target)
@@ -453,7 +480,7 @@ module Bridgetown
453
480
  end
454
481
 
455
482
  # Strip according to the mode
456
- string.gsub(replaceable_char, "-")
483
+ string.to_s.gsub(replaceable_char, "-")
457
484
  end
458
485
  end
459
486
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bridgetown
4
- VERSION = "0.21.3"
5
- CODE_NAME = "Broughton Beach"
4
+ VERSION = "1.0.0.alpha3"
5
+ CODE_NAME = "Pearl"
6
6
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "listen"
4
-
5
3
  module Bridgetown
6
4
  module Watcher
7
5
  extend self
@@ -19,9 +17,9 @@ module Bridgetown
19
17
  listener = build_listener(site, options)
20
18
  listener.start
21
19
 
22
- Bridgetown.logger.info "Auto-regeneration:", "enabled."
20
+ Bridgetown.logger.info "Auto-regeneration:", "enabled." unless options[:using_puma]
23
21
 
24
- unless options["serving"]
22
+ unless options[:serving]
25
23
  trap("INT") do
26
24
  listener.stop
27
25
  Bridgetown.logger.info "", "Halting auto-regeneration."
@@ -118,7 +116,7 @@ module Bridgetown
118
116
  rescue ArgumentError
119
117
  # Could not find a relative path
120
118
  end
121
- end.compact + [%r!^\.bridgetown\-metadata!]
119
+ end.compact + [%r!^\.bridgetown-metadata!]
122
120
  end
123
121
 
124
122
  def sleep_forever
@@ -134,7 +132,7 @@ module Bridgetown
134
132
  site.plugin_manager.reload_component_loaders
135
133
  site.process
136
134
  Bridgetown.logger.info "Done! 🎉", "#{"Completed".green} in less than" \
137
- " #{(Time.now - time).ceil(2)} seconds."
135
+ " #{(Time.now - time).ceil(2)} seconds."
138
136
  rescue Exception => e
139
137
  Bridgetown.logger.error "Error:", e.message
140
138
 
@@ -47,6 +47,7 @@ require "hash_with_dot_access"
47
47
  require "addressable/uri"
48
48
  require "liquid"
49
49
  require "liquid-component"
50
+ require "listen"
50
51
  require "kramdown"
51
52
  require "colorator"
52
53
  require "i18n"
@@ -66,53 +67,39 @@ end
66
67
  class Rb < String; end
67
68
 
68
69
  module Bridgetown
70
+ autoload :Cache, "bridgetown-core/cache"
71
+ autoload :Current, "bridgetown-core/current"
69
72
  autoload :Cleaner, "bridgetown-core/cleaner"
70
73
  autoload :Collection, "bridgetown-core/collection"
71
74
  autoload :Component, "bridgetown-core/component"
72
75
  autoload :Configuration, "bridgetown-core/configuration"
73
- autoload :DataAccessible, "bridgetown-core/concerns/data_accessible"
76
+ autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
74
77
  autoload :Deprecator, "bridgetown-core/deprecator"
75
- autoload :Document, "bridgetown-core/document"
76
78
  autoload :EntryFilter, "bridgetown-core/entry_filter"
77
79
  # TODO: we have too many errors! This is silly
78
80
  autoload :Errors, "bridgetown-core/errors"
79
- autoload :Excerpt, "bridgetown-core/excerpt"
80
81
  autoload :FrontmatterDefaults, "bridgetown-core/frontmatter_defaults"
81
82
  autoload :FrontMatterImporter, "bridgetown-core/concerns/front_matter_importer"
83
+ autoload :GeneratedPage, "bridgetown-core/generated_page"
82
84
  autoload :Hooks, "bridgetown-core/hooks"
83
85
  autoload :Layout, "bridgetown-core/layout"
84
86
  autoload :LayoutPlaceable, "bridgetown-core/concerns/layout_placeable"
85
- autoload :Cache, "bridgetown-core/cache"
86
- autoload :Current, "bridgetown-core/current"
87
- # TODO: remove this when legacy content engine is gone:
88
- autoload :DataReader, "bridgetown-core/readers/data_reader"
89
- autoload :DefaultsReader, "bridgetown-core/readers/defaults_reader"
90
87
  autoload :LayoutReader, "bridgetown-core/readers/layout_reader"
91
- # TODO: remove this when legacy content engine is gone:
92
- autoload :PostReader, "bridgetown-core/readers/post_reader"
93
- # TODO: remove this when legacy content engine is gone:
94
- autoload :PageReader, "bridgetown-core/readers/page_reader"
95
- autoload :PluginContentReader, "bridgetown-core/readers/plugin_content_reader"
88
+ autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable"
89
+ autoload :LiquidRenderer, "bridgetown-core/liquid_renderer"
96
90
  autoload :LogAdapter, "bridgetown-core/log_adapter"
97
- autoload :Page, "bridgetown-core/page"
98
- autoload :GeneratedPage, "bridgetown-core/page"
91
+ autoload :PluginContentReader, "bridgetown-core/readers/plugin_content_reader"
99
92
  autoload :PluginManager, "bridgetown-core/plugin_manager"
100
93
  autoload :Publishable, "bridgetown-core/concerns/publishable"
101
94
  autoload :Publisher, "bridgetown-core/publisher"
102
95
  autoload :Reader, "bridgetown-core/reader"
103
- # TODO: remove this when the incremental regenerator is gone:
104
- autoload :Regenerator, "bridgetown-core/regenerator"
105
- autoload :RelatedPosts, "bridgetown-core/related_posts"
106
96
  autoload :Renderer, "bridgetown-core/renderer"
107
- autoload :LiquidRenderable, "bridgetown-core/concerns/liquid_renderable"
108
- autoload :LiquidRenderer, "bridgetown-core/liquid_renderer"
109
97
  autoload :RubyTemplateView, "bridgetown-core/ruby_template_view"
110
98
  autoload :LogWriter, "bridgetown-core/log_writer"
111
99
  autoload :Site, "bridgetown-core/site"
112
100
  autoload :StaticFile, "bridgetown-core/static_file"
113
101
  autoload :URL, "bridgetown-core/url"
114
102
  autoload :Utils, "bridgetown-core/utils"
115
- autoload :Validatable, "bridgetown-core/concerns/validatable"
116
103
  autoload :VERSION, "bridgetown-core/version"
117
104
  autoload :Watcher, "bridgetown-core/watcher"
118
105
  autoload :YAMLParser, "bridgetown-core/yaml_parser"
@@ -126,7 +113,6 @@ module Bridgetown
126
113
  require "bridgetown-core/filters"
127
114
 
128
115
  require "bridgetown-core/drops/drop"
129
- require "bridgetown-core/drops/document_drop"
130
116
  require "bridgetown-core/drops/resource_drop"
131
117
  require_all "bridgetown-core/converters"
132
118
  require_all "bridgetown-core/converters/markdown"
@@ -173,6 +159,12 @@ module Bridgetown
173
159
  Bridgetown::Commands::Registrations.register(&block)
174
160
  end
175
161
 
162
+ def load_tasks
163
+ require "bridgetown-core/commands/base"
164
+ Bridgetown::PluginManager.require_from_bundler
165
+ load File.expand_path("bridgetown-core/tasks/bridgetown_tasks.rake", __dir__)
166
+ end
167
+
176
168
  # Determines the correct Bundler environment block method to use and passes
177
169
  # the block on to it.
178
170
  #
@@ -257,12 +249,13 @@ end
257
249
 
258
250
  module Bridgetown
259
251
  module Model; end
252
+
260
253
  module Resource
261
254
  def self.register_extension(mod)
262
255
  if mod.const_defined?(:LiquidResource)
263
256
  Bridgetown::Drops::ResourceDrop.include mod.const_get(:LiquidResource)
264
257
  end
265
- if mod.const_defined?(:RubyResource)
258
+ if mod.const_defined?(:RubyResource) # rubocop:disable Style/GuardClause
266
259
  Bridgetown::Resource::Base.include mod.const_get(:RubyResource)
267
260
  end
268
261
  end
@@ -3,9 +3,9 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
3
3
 
4
4
  # Hello! This is where you manage which Bridgetown version is used to run.
5
5
  # When you want to use a different version, change it below, save the
6
- # file and run `bundle install`. Run Bridgetown with `bundle exec`, like so:
6
+ # file and run `bundle install`. Run Bridgetown like so:
7
7
  #
8
- # bundle exec bridgetown serve
8
+ # bin/bridgetown start (or console, etc.)
9
9
  #
10
10
  # This will help ensure the proper Bridgetown version is running.
11
11
  #
@@ -17,3 +17,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
17
17
  # Happy Bridgetowning!
18
18
 
19
19
  gem "bridgetown", "~> <%= Bridgetown::VERSION %>"
20
+
21
+ # Puma is a Rack-compatible server
22
+ # (you can optionally limit this to the "development" group)
23
+ gem "puma", "~> 5.2"
@@ -18,9 +18,9 @@ Welcome to your new Bridgetown website! You can update this README file to provi
18
18
  - [Ruby](https://www.ruby-lang.org/en/downloads/)
19
19
  - `>= 2.5`
20
20
  - [Bridgetown Gem](https://rubygems.org/gems/bridgetown)
21
- - `gem install bundler bridgetown -N`
21
+ - `gem install bridgetown -N`
22
22
  - [Node](https://nodejs.org)
23
- - `>= 10.13`
23
+ - `>= 12`
24
24
  - [Yarn](https://yarnpkg.com)
25
25
 
26
26
  ## Install
@@ -33,7 +33,7 @@ bundle install && yarn install
33
33
 
34
34
  ## Development
35
35
 
36
- To start your site in development mode, run `yarn start` and navigate to [localhost:4000](https://localhost:4000/)!
36
+ To start your site in development mode, run `bin/bridgetown start` and navigate to [localhost:4000](https://localhost:4000/)!
37
37
 
38
38
  Use a [theme](https://github.com/topics/bridgetown-theme), add some [plugins](https://www.bridgetownrb.com/plugins/), and/or run some [automations](https://github.com/topics/bridgetown-automation) to get started quickly.
39
39
 
@@ -41,13 +41,13 @@ Use a [theme](https://github.com/topics/bridgetown-theme), add some [plugins](ht
41
41
 
42
42
  ```sh
43
43
  # running locally
44
- yarn start
44
+ bin/bridgetown start
45
45
 
46
46
  # build & deploy to production
47
- yarn deploy
47
+ bin/bridgetown deploy
48
48
 
49
49
  # load the site up within a Ruby console (IRB)
50
- bundle exec bridgetown console
50
+ bin/bridgetown console
51
51
  ```
52
52
 
53
53
  > Learn more: [Bridgetown CLI Documentation](https://www.bridgetownrb.com/docs/command-line-usage)
@@ -0,0 +1,49 @@
1
+ require "bridgetown"
2
+
3
+ Bridgetown.load_tasks
4
+
5
+ #
6
+ # Standard set of tasks, which you can customize if you wish:
7
+ #
8
+ desc "Build the Bridgetown site for deployment"
9
+ task :deploy => [:clean, "frontend:build"] do
10
+ Bridgetown::Commands::Build.start
11
+ end
12
+
13
+ desc "Build the site in a test environment"
14
+ task :test do
15
+ ENV["BRIDGETOWN_ENV"] = "test"
16
+ Bridgetown::Commands::Build.start
17
+ end
18
+
19
+ desc "Runs the clean command"
20
+ task :clean do
21
+ Bridgetown::Commands::Clean.start
22
+ end
23
+
24
+ namespace :frontend do
25
+ desc "Build the frontend with Webpack for deployment"
26
+ task :build do
27
+ sh "yarn run webpack-build"
28
+ end
29
+
30
+ desc "Watch the frontend with Webpack during development"
31
+ task :dev do
32
+ sh "yarn run webpack-dev --color"
33
+ rescue Interrupt
34
+ end
35
+ end
36
+
37
+ #
38
+ # Add your own Rake tasks here! You can use `environment` as a prerequisite
39
+ # in order to write automations or other commands requiring a loaded site.
40
+ #
41
+ # task :my_task => :environment do
42
+ # puts site.root_dir
43
+ # automation do
44
+ # say_status :rake, "I'm a Rake tast =) #{site.config.url}"
45
+ # end
46
+ # end
47
+
48
+ # Run rake without specifying any command to execute a deploy build by default.
49
+ task default: :deploy
@@ -4,11 +4,10 @@
4
4
  # which you are expected to set up once and rarely edit after that.
5
5
  #
6
6
  # For technical reasons, this file is *NOT* reloaded automatically when you use
7
- # 'bundle exec bridgetown serve'. If you change this file, please restart the
8
- # server process.
7
+ # `bin/bridgetown start`. If you change this file, please restart the server process.
9
8
  #
10
9
  # For reloadable site metadata like title, SEO description, social media
11
- # handles, etc., take a look at src/_data/site_metadata.yml
10
+ # handles, etc., take a look at `src/_data/site_metadata.yml`
12
11
  #
13
12
  # If you need help with YAML syntax, here are some quick references for you:
14
13
  # https://learn-the-web.algonquindesign.ca/topics/markdown-yaml-cheat-sheet/#yaml
@@ -0,0 +1,27 @@
1
+ # Puma is a fast, concurrent web server for Ruby & Rack
2
+ #
3
+ # Learn more at: https://puma.io
4
+ #
5
+ port ENV.fetch("BRIDGETOWN_PORT") { 4000 }
6
+
7
+ # You can adjust the number of workers (separate processes) and threads
8
+ # (per process) based on your production system
9
+ #
10
+ if ENV["BRIDGETOWN_ENV"] == "production"
11
+ workers ENV.fetch("BRIDGETOWN_CONCURRENCY") { 4 }
12
+ end
13
+
14
+ max_threads_count = ENV.fetch("BRIDGETOWN_MAX_THREADS") { 5 }
15
+ min_threads_count = ENV.fetch("BRIDGETOWN_MIN_THREADS") { max_threads_count }
16
+ threads min_threads_count, max_threads_count
17
+
18
+ # Preload the application for maximum performance
19
+ #
20
+ preload_app!
21
+
22
+ # Use the Bridgetown logger format
23
+ #
24
+ require "bridgetown-core/rack/logger"
25
+ log_formatter do |msg|
26
+ Bridgetown::Rack::Logger.message_with_prefix msg
27
+ end
@@ -0,0 +1,7 @@
1
+ # This file is used by Rack-based servers during the Bridgetown boot process.
2
+
3
+ require "bridgetown-core/rack/boot"
4
+
5
+ Bridgetown::Rack.boot
6
+
7
+ run RodaApp.freeze.app # see server/roda_app.rb
@@ -1,8 +1,8 @@
1
- <% if options["use-postcss"] %>
1
+ <%- if options["use-postcss"] -%>
2
2
  import "index.css"
3
- <% else %>
3
+ <%- else -%>
4
4
  import "index.scss"
5
- <% end %>
5
+ <%- end -%>
6
6
 
7
7
  // Import all javascript files from src/_components
8
8
  const componentsContext = require.context("bridgetownComponents", true, /.js$/)