bridgetown-core 2.0.0.beta2 → 2.0.0.beta4

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/bridgetown-core.gemspec +43 -42
  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 +6 -5
  7. data/lib/bridgetown-core/commands/base.rb +7 -0
  8. data/lib/bridgetown-core/commands/build.rb +35 -22
  9. data/lib/bridgetown-core/commands/concerns/actions.rb +4 -0
  10. data/lib/bridgetown-core/commands/console.rb +0 -1
  11. data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +7 -6
  12. data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +14 -13
  13. data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
  14. data/lib/bridgetown-core/commands/esbuild/update.rb +17 -3
  15. data/lib/bridgetown-core/commands/esbuild.rb +1 -1
  16. data/lib/bridgetown-core/commands/start.rb +12 -2
  17. data/lib/bridgetown-core/component.rb +1 -1
  18. data/lib/bridgetown-core/concerns/intuitive_expectations.rb +67 -0
  19. data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
  20. data/lib/bridgetown-core/concerns/publishable.rb +2 -0
  21. data/lib/bridgetown-core/concerns/site/content.rb +4 -1
  22. data/lib/bridgetown-core/concerns/site/extensible.rb +6 -1
  23. data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +33 -18
  24. data/lib/bridgetown-core/concerns/site/localizable.rb +2 -0
  25. data/lib/bridgetown-core/concerns/site/processable.rb +2 -0
  26. data/lib/bridgetown-core/concerns/site/renderable.rb +3 -0
  27. data/lib/bridgetown-core/concerns/site/ssr.rb +1 -2
  28. data/lib/bridgetown-core/concerns/site/writable.rb +1 -0
  29. data/lib/bridgetown-core/concerns/viewable.rb +46 -0
  30. data/lib/bridgetown-core/configuration.rb +29 -23
  31. data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +5 -5
  32. data/lib/bridgetown-core/configurations/minitesting.rb +24 -64
  33. data/lib/bridgetown-core/converter.rb +2 -7
  34. data/lib/bridgetown-core/converters/erb_templates.rb +11 -7
  35. data/lib/bridgetown-core/converters/identity.rb +3 -11
  36. data/lib/bridgetown-core/converters/liquid_templates.rb +3 -5
  37. data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
  38. data/lib/bridgetown-core/converters/markdown.rb +11 -14
  39. data/lib/bridgetown-core/converters/serbea_templates.rb +10 -8
  40. data/lib/bridgetown-core/drops/drop.rb +29 -42
  41. data/lib/bridgetown-core/drops/resource_drop.rb +3 -12
  42. data/lib/bridgetown-core/errors.rb +2 -8
  43. data/lib/bridgetown-core/filters/condition_helpers.rb +6 -9
  44. data/lib/bridgetown-core/filters/date_filters.rb +22 -35
  45. data/lib/bridgetown-core/filters/grouping_filters.rb +11 -11
  46. data/lib/bridgetown-core/filters.rb +53 -72
  47. data/lib/bridgetown-core/front_matter/defaults.rb +14 -19
  48. data/lib/bridgetown-core/generated_page.rb +6 -6
  49. data/lib/bridgetown-core/generators/prototype_generator.rb +0 -2
  50. data/lib/bridgetown-core/helpers.rb +2 -2
  51. data/lib/bridgetown-core/hooks.rb +0 -1
  52. data/lib/bridgetown-core/layout.rb +3 -4
  53. data/lib/bridgetown-core/liquid_extensions.rb +3 -5
  54. data/lib/bridgetown-core/log_adapter.rb +37 -56
  55. data/lib/bridgetown-core/plugin_manager.rb +7 -3
  56. data/lib/bridgetown-core/rack/boot.rb +7 -57
  57. data/lib/bridgetown-core/rack/default_config.ru +14 -0
  58. data/lib/bridgetown-core/rack/loader_hooks.rb +83 -0
  59. data/lib/bridgetown-core/rack/logger.rb +0 -2
  60. data/lib/bridgetown-core/rack/routes.rb +3 -2
  61. data/lib/bridgetown-core/resource/base.rb +8 -8
  62. data/lib/bridgetown-core/resource/permalink_processor.rb +1 -1
  63. data/lib/bridgetown-core/resource/relations.rb +3 -1
  64. data/lib/bridgetown-core/ruby_template_view.rb +0 -1
  65. data/lib/bridgetown-core/static_file.rb +15 -20
  66. data/lib/bridgetown-core/tags/class_map.rb +1 -1
  67. data/lib/bridgetown-core/tags/post_url.rb +2 -32
  68. data/lib/bridgetown-core/utils/initializers.rb +2 -2
  69. data/lib/bridgetown-core/utils/require_gems.rb +1 -3
  70. data/lib/bridgetown-core/utils.rb +41 -44
  71. data/lib/bridgetown-core/watcher.rb +2 -3
  72. data/lib/bridgetown-core.rb +29 -10
  73. data/lib/roda/plugins/bridgetown_server.rb +13 -25
  74. data/lib/roda/plugins/bridgetown_ssr.rb +21 -3
  75. data/lib/roda/plugins/flashier.rb +57 -0
  76. data/lib/roda/plugins/generic_index.html +127 -0
  77. data/lib/roda/plugins/ssg.rb +3 -2
  78. data/lib/site_template/config/initializers.rb +2 -0
  79. data/lib/site_template/package.json.erb +1 -0
  80. data/lib/site_template/postcss.config.js.erb +1 -1
  81. metadata +26 -7
  82. data/lib/bridgetown-core/commands/doctor.rb +0 -147
@@ -7,93 +7,53 @@ say_status :minitesting, "Adding test gems and examples"
7
7
  append_to_file "Gemfile" do
8
8
  <<~GEMS
9
9
  \n
10
- group :test, optional: true do
11
- gem "nokogiri"
10
+ group :test do
12
11
  gem "minitest"
13
- gem "minitest-profile"
14
12
  gem "minitest-reporters"
15
- gem "shoulda"
16
- gem "rails-dom-testing"
13
+ gem "rack-test"
17
14
  end
18
15
  GEMS
19
16
  end
20
17
 
21
- create_file "test/helper.rb" do
22
- <<~RUBY
23
- require "nokogiri"
24
- require "minitest/autorun"
25
- require "minitest/reporters"
26
- require "minitest/profile"
27
- require "shoulda"
28
- require "rails-dom-testing"
18
+ gsub_file "Gemfile", '# gem "nokolexbor"', 'gem "nokolexbor"'
29
19
 
30
- # Report with color.
31
- Minitest::Reporters.use! [
32
- Minitest::Reporters::DefaultReporter.new(
33
- color: true
34
- ),
35
- ]
36
-
37
- Minitest::Test.class_eval do
38
- include Rails::Dom::Testing::Assertions
39
-
40
- def site
41
- @site ||= Bridgetown::Current.site
42
- end
43
-
44
- def nokogiri(input)
45
- input.respond_to?(:output) ? Nokogiri::HTML(input.output) : Nokogiri::HTML(input)
46
- end
47
-
48
- def document_root(root)
49
- @document_root = root.is_a?(Nokogiri::XML::Document) ? root : nokogiri(root)
50
- end
20
+ insert_into_file "Rakefile", after: %(ENV["BRIDGETOWN_ENV"] = "test"\n Bridgetown::Commands::Build.start\nend\n) do
21
+ <<~RUBY
51
22
 
52
- def document_root_element
53
- if @document_root.nil?
54
- raise "Call `document_root' with a Nokogiri document before testing your assertions"
55
- end
56
- @document_root
57
- end
23
+ require "minitest/test_task"
24
+ Minitest::TestTask.create(:test) do |t| # add on to the test task
25
+ t.warning = false
58
26
  end
59
27
  RUBY
60
28
  end
61
29
 
62
- create_file "test/test_homepage.rb" do
30
+ create_file "test/minitest_helper.rb" do
63
31
  <<~RUBY
64
- require_relative "./helper"
65
-
66
- class TestHomepage < Minitest::Test
67
- context "homepage" do
68
- setup do
69
- page = site.collections.pages.resources.find { |doc| doc.relative_url == "/" }
70
- document_root page
71
- end
32
+ ENV["MT_NO_EXPECTATIONS"] = "true"
33
+ require "minitest/autorun"
34
+ require "minitest/reporters"
35
+ Minitest::Reporters.use! [Minitest::Reporters::ProgressReporter.new]
72
36
 
73
- should "exist" do
74
- assert_select "body"
75
- end
76
- end
77
- end
37
+ require "bridgetown/test"
78
38
  RUBY
79
39
  end
80
40
 
81
- create_file "plugins/test_output.rb" do
41
+ create_file "test/test_homepage.rb" do
82
42
  <<~RUBY
83
- module TestOutput
84
- unless Bridgetown.env.development?
85
- Bridgetown::Hooks.register_one :site, :post_write do
86
- # Load test suite to run on exit
87
- require "nokogiri"
88
- Dir["test/**/*.rb"].each { |file| require_relative("../\#{file}") }
89
- rescue LoadError
90
- Bridgetown.logger.warn "Testing:", "To run tests, you must first run \`bundle install --with test\`"
91
- end
43
+ require "minitest_helper"
44
+
45
+ class TestHomepage < Bridgetown::Test
46
+ def test_homepage
47
+ html get "/"
48
+
49
+ assert document.query_selector("body")
92
50
  end
93
51
  end
94
52
  RUBY
95
53
  end
96
54
 
55
+ run "bundle install", env: { "BUNDLE_GEMFILE" => Bundler::SharedHelpers.in_bundle? }
56
+
97
57
  say_status :minitesting, "All set! To get started, look at test/test_homepage.rb and then run \`bin/bridgetown test\`"
98
58
 
99
59
  # rubocop:enable all
@@ -40,7 +40,6 @@ module Bridgetown
40
40
  #
41
41
  # @param content [String] content of file (without front matter).
42
42
  # @param convertible [Bridgetown::Layout, Bridgetown::Resource::Base]
43
- #
44
43
  # @return [String] the converted content.
45
44
  def convert(content, convertible = nil) # rubocop:disable Lint/UnusedMethodArgument
46
45
  content
@@ -48,10 +47,8 @@ module Bridgetown
48
47
 
49
48
  # Does the given extension match this converter's list of acceptable extensions?
50
49
  #
51
- # @param [String] ext
52
- # The file's extension (including the dot)
50
+ # @param ext [String] the file's extension (including the dot)
53
51
  # @param convertible [Bridgetown::Layout, Bridgetown::Resource::Base]
54
- #
55
52
  # @return [Boolean] Whether the extension matches one in the list
56
53
  def matches(ext, _convertible = nil)
57
54
  (self.class.extname_list || []).include?(ext.downcase)
@@ -67,9 +64,7 @@ module Bridgetown
67
64
  # You can override this in Converter subclasses as needed. Default is ".html", unless the
68
65
  # converter is a template engine and the input file doesn't match the normal template extension
69
66
  #
70
- # @param [String] ext
71
- # The extension of the original file
72
- #
67
+ # @param ext [String] the extension of the original file
73
68
  # @return [String] The output file extension (including the dot)
74
69
  def output_ext(ext)
75
70
  if self.class.template_engine
@@ -119,13 +119,17 @@ module Bridgetown
119
119
  def convert(content, convertible)
120
120
  erb_view = Bridgetown::ERBView.new(convertible)
121
121
 
122
- erb_renderer = Tilt::ErubiTemplate.new(
123
- convertible.path,
124
- line_start(convertible),
125
- outvar: "@_erbout",
126
- bufval: "Bridgetown::OutputBuffer.new",
127
- engine_class: ERBEngine
128
- ) { content }
122
+ erb_renderer =
123
+ convertible.site.tmp_cache["erb-tmpl:#{convertible.path}:#{content.hash}"] ||=
124
+ Tilt::ErubiTemplate.new(
125
+ convertible.path,
126
+ line_start(convertible),
127
+ outvar: "@_erbout",
128
+ bufval: "Bridgetown::OutputBuffer.new",
129
+ engine_class: ERBEngine
130
+ ) do
131
+ content
132
+ end
129
133
 
130
134
  if convertible.is_a?(Bridgetown::Layout)
131
135
  erb_renderer.render(erb_view) do
@@ -9,21 +9,13 @@ module Bridgetown
9
9
 
10
10
  support_slots
11
11
 
12
- # Public: Does the given extension match this converter's list of acceptable extensions?
13
- # Takes one argument: the file's extension (including the dot).
14
- #
15
- # _ext - The String extension to check (not relevant here)
16
- #
17
- # Returns true since it always matches.
12
+ # @return [Boolean] true since it always matches.
18
13
  def matches(*)
19
14
  true
20
15
  end
21
16
 
22
- # Public: The extension to be given to the output file (including the dot).
23
- #
24
- # ext - The String extension or original file.
25
- #
26
- # Returns The String output file extension.
17
+ # @param ext [String] the extension of the original file
18
+ # @return [String] The output file extension (including the dot)
27
19
  def output_ext(ext)
28
20
  ext
29
21
  end
@@ -22,7 +22,6 @@ module Bridgetown
22
22
  # @param convertible [
23
23
  # Bridgetown::GeneratedPage, Bridgetown::Resource::Base, Bridgetown::Layout]
24
24
  # The instantiated object which is processing the file.
25
- #
26
25
  # @return [String] The converted content.
27
26
  def convert(content, convertible)
28
27
  self.class.cached_partials ||= {}
@@ -55,17 +54,16 @@ module Bridgetown
55
54
  # rubocop: enable Metrics/MethodLength
56
55
  # rubocop: enable Metrics/AbcSize
57
56
 
58
- # Fetches the payload used in Liquid rendering.
59
- # Falls back to site.site_payload if no payload is set.
57
+ # Fetches the payload used in Liquid rendering, aka `site.site_payload`
60
58
  #
61
- # Returns a Bridgetown::Drops::UnifiedPayloadDrop
59
+ # @return [Bridgetown::Drops::UnifiedPayloadDrop]
62
60
  def payload
63
61
  @payload ||= site.site_payload
64
62
  end
65
63
 
66
64
  # Set page content to payload and assign paginator if document has one.
67
65
  #
68
- # Returns nothing
66
+ # @return [void]
69
67
  def configure_payload(content = nil)
70
68
  payload["page"] = document.to_liquid
71
69
  payload["paginator"] = document.respond_to?(:paginator) ? document.paginator.to_liquid : nil
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kramdown
4
- # A Kramdown::Document subclass meant to optimize memory usage from initializing
4
+ # A `Kramdown::Document`` subclass meant to optimize memory usage from initializing
5
5
  # a kramdown document for parsing.
6
6
  #
7
7
  # The optimization is by using the same options Hash (and its derivatives) for
@@ -43,26 +43,25 @@ module Bridgetown
43
43
  end
44
44
  # rubocop:enable Naming/AccessorMethodName
45
45
 
46
- # Public: Provides you with a list of processors comprised of the ones we support internally
46
+ # Provides you with a list of processors comprised of the ones we support internally
47
47
  # and the ones that you have provided to us
48
48
  #
49
- # Returns an array of symbols.
49
+ # @return [Array<Symbol>]
50
50
  def valid_processors
51
51
  [:kramdown] + third_party_processors
52
52
  end
53
53
 
54
- # Public: A list of processors that you provide via plugins.
54
+ # A list of processors that you provide via plugins
55
55
  #
56
- # Returns an array of symbols
56
+ # @return [Array<Symbol>]
57
57
  def third_party_processors
58
58
  self.class.constants - [:KramdownParser, :PRIORITIES]
59
59
  end
60
60
 
61
- # Logic to do the content conversion.
61
+ # Logic to do the content conversion
62
62
  #
63
- # content - String content of file (without front matter).
64
- #
65
- # Returns a String of the converted content.
63
+ # @param content [String] content of file (without front matter)
64
+ # @return [String] converted content
66
65
  def convert(content, convertible = nil)
67
66
  setup
68
67
  if @cache
@@ -85,13 +84,11 @@ module Bridgetown
85
84
  self.class.const_get(converter_name).new(@config) if custom_class_allowed?(converter_name)
86
85
  end
87
86
 
88
- # Private: Determine whether a class name is an allowed custom
89
- # markdown class name.
90
- #
91
- # parser_name - the name of the parser class
87
+ # Determine whether a class name is an allowed custom markdown class name.
92
88
  #
93
- # Returns true if the parser name contains only alphanumeric characters and is defined
94
- # within Bridgetown::Converters::Markdown
89
+ # @param parser_name [Symbol] name of the parser class
90
+ # @return [Boolean] true if the parser name contains only alphanumeric characters and is
91
+ # defined within `Bridgetown::Converters::Markdown`
95
92
  def custom_class_allowed?(parser_name)
96
93
  parser_name !~ %r![^A-Za-z0-9_]! && self.class.constants.include?(parser_name.to_sym)
97
94
  end
@@ -25,20 +25,22 @@ module Bridgetown
25
25
  template_engine :serbea
26
26
  input :serb
27
27
 
28
- # Logic to do the Serbea content conversion.
28
+ # Logic to do the Serbea content conversion
29
29
  #
30
- # @param content [String] Content of the file (without front matter).
30
+ # @param content [String] Content of the file (without front matter)
31
31
  # @param convertible [
32
32
  # Bridgetown::GeneratedPage, Bridgetown::Resource::Base, Bridgetown::Layout]
33
33
  # The instantiated object which is processing the file.
34
- #
35
- # @return [String] The converted content.
34
+ # @return [String] The converted content
36
35
  def convert(content, convertible)
37
36
  serb_view = Bridgetown::SerbeaView.new(convertible)
38
- serb_renderer = Tilt::SerbeaTemplate.new(
39
- convertible.path,
40
- line_start(convertible)
41
- ) { content }
37
+
38
+ serb_renderer =
39
+ convertible.site.tmp_cache["serb-tmpl:#{convertible.path}:#{content.hash}"] ||=
40
+ Tilt::SerbeaTemplate.new(
41
+ convertible.path,
42
+ line_start(convertible)
43
+ ) { content }
42
44
 
43
45
  if convertible.is_a?(Bridgetown::Layout)
44
46
  serb_renderer.render(serb_view) do
@@ -11,23 +11,22 @@ module Bridgetown
11
11
  # Mutability determines whether or not pre-defined fields may be
12
12
  # overwritten.
13
13
  #
14
- # is_mutable - Boolean set mutability of the class (default: nil)
14
+ # @param is_mutable [Boolean] set mutability of the class
15
15
  #
16
- # Returns the mutability of the class
16
+ # @return [Boolean] the mutability of the class
17
17
  def self.mutable(is_mutable = nil)
18
18
  @is_mutable = is_mutable || false
19
19
  end
20
20
 
21
+ # @return [Boolean] the mutability of the class
21
22
  def self.mutable?
22
23
  @is_mutable
23
24
  end
24
25
 
25
26
  # Create a new Drop
26
27
  #
27
- # obj - the Bridgetown Site, Collection, or Resource required by the
28
+ # @param obj [Object] the Bridgetown Site, Collection, or Resource required by the
28
29
  # drop.
29
- #
30
- # Returns nothing
31
30
  def initialize(obj) # rubocop:disable Lint/MissingSuper
32
31
  @obj = obj
33
32
  end
@@ -37,9 +36,8 @@ module Bridgetown
37
36
  # and finally check the underlying hash (e.g. document front matter)
38
37
  # if all the previous places didn't match.
39
38
  #
40
- # key - the string key whose value to fetch
41
- #
42
- # Returns the value for the given key, or nil if none exists
39
+ # @param key [String] key whose value to fetch
40
+ # @return [Object, nil] returns the value for the given key if present
43
41
  def [](key)
44
42
  if self.class.mutable? && mutations.key?(key)
45
43
  mutations[key]
@@ -51,26 +49,22 @@ module Bridgetown
51
49
  end
52
50
  alias_method :invoke_drop, :[]
53
51
 
54
- # Set a field in the Drop. If mutable, sets in the mutations and
55
- # returns. If not mutable, checks first if it's trying to override a
56
- # Drop method and raises a DropMutationException if so. If not
57
- # mutable and the key is not a method on the Drop, then it sets the
58
- # key to the value in the underlying hash (e.g. document front
59
- # matter)
52
+ # Set a field in the Drop. If mutable, sets in the mutations and returns. If not mutable,
53
+ # checks first if it's trying to override a Drop method and raises an exception if so.
54
+ # If not mutable and the key is not a method on the Drop, then it sets the key to the value
55
+ # in the underlying hash (e.g. document front matter)
60
56
  #
61
- # key - the String key whose value to set
62
- # val - the Object to set the key's value to
63
- #
64
- # Returns the value the key was set to unless the Drop is not mutable
65
- # and the key matches a method in which case it raises a
66
- # DropMutationException.
57
+ # @param key [String] key whose value to set
58
+ # @param val [Object] what to set the key's value to
59
+ # @return [Object] the value the key was set to unless the Drop is not mutable
60
+ # and the key matches a method in which case it raises an exception
67
61
  def []=(key, val)
68
62
  setter = "#{key}="
69
63
  if respond_to?(setter)
70
64
  public_send(setter, val)
71
65
  elsif respond_to?(key.to_s)
72
66
  unless self.class.mutable?
73
- raise Errors::DropMutationException, "Key #{key} cannot be set in the drop."
67
+ raise Errors::FatalException, "Key #{key} cannot be set in the drop."
74
68
  end
75
69
 
76
70
  mutations[key] = val
@@ -82,7 +76,7 @@ module Bridgetown
82
76
  # Generates a list of strings which correspond to content getter
83
77
  # methods.
84
78
  #
85
- # Returns an Array of strings which represent method-specific keys.
79
+ # @return [Array<String>] method-specific keys
86
80
  def content_methods
87
81
  @content_methods ||= (
88
82
  self.class.instance_methods \
@@ -95,9 +89,8 @@ module Bridgetown
95
89
 
96
90
  # Check if key exists in Drop
97
91
  #
98
- # key - the string key whose value to fetch
99
- #
100
- # Returns true if the given key is present
92
+ # @param key [String] key whose value to set
93
+ # @return [Boolean] true if the given key is present
101
94
  def key?(key)
102
95
  return false if key.nil?
103
96
  return true if self.class.mutable? && mutations.key?(key)
@@ -121,7 +114,7 @@ module Bridgetown
121
114
  # value. It includes Drop methods, mutations, and the underlying object's
122
115
  # data. See the documentation for Drop#keys for more.
123
116
  #
124
- # Returns a Hash with all the keys and values resolved.
117
+ # @return [Hash<String, Object>] all the keys and values resolved
125
118
  def to_h
126
119
  keys.each_with_object({}) do |(key, _), result|
127
120
  result[key] = self[key]
@@ -132,33 +125,27 @@ module Bridgetown
132
125
  # Inspect the drop's keys and values through a JSON representation
133
126
  # of its keys and values.
134
127
  #
135
- # Returns a pretty generation of the hash representation of the Drop.
128
+ # @return [String]
136
129
  def inspect
137
130
  JSON.pretty_generate to_h
138
131
  end
139
132
 
140
- # Generate a Hash for use in generating JSON.
141
- # This is useful if fields need to be cleared before the JSON can generate.
133
+ # Generate a Hash for use in generating JSON. Essentially an alias for `to_h`
142
134
  #
143
- # Returns a Hash ready for JSON generation.
135
+ # @return [Hash<String, Object>] all the keys and values resolved
144
136
  def hash_for_json(*)
145
137
  to_h
146
138
  end
147
139
 
148
- # Generate a JSON representation of the Drop.
140
+ # Generate a JSON representation of the Drop
149
141
  #
150
- # state - the JSON::State object which determines the state of current processing.
151
- #
152
- # Returns a JSON representation of the Drop in a String.
142
+ # @param state [JSON::State] object which determines the state of current processing
143
+ # @return [String] JSON representation of the Drop
153
144
  def to_json(state = nil)
154
145
  JSON.generate(hash_for_json(state), state)
155
146
  end
156
147
 
157
- # Collects all the keys and passes each to the block in turn.
158
- #
159
- # block - a block which accepts one argument, the key
160
- #
161
- # Returns nothing.
148
+ # Collects all the keys and passes each to the block in turn
162
149
  def each_key(&)
163
150
  keys.each(&)
164
151
  end
@@ -194,10 +181,10 @@ module Bridgetown
194
181
  end
195
182
  end
196
183
 
197
- # Imitate Hash.fetch method in Drop
184
+ # Imitate `Hash.fetch` method in Drop
198
185
  #
199
- # Returns value if key is present in Drop, otherwise returns default value
200
- # KeyError is raised if key is not present and no default value given
186
+ # @return [Object] value if key is present in Drop, otherwise returns default value.
187
+ # KeyError is raised if key is not present and no default value given
201
188
  def fetch(key, default = nil, &block)
202
189
  return self[key] if key?(key)
203
190
  raise KeyError, %(key not found: "#{key}") if default.nil? && block.nil?
@@ -58,9 +58,8 @@ module Bridgetown
58
58
  # Generate a Hash for use in generating JSON.
59
59
  # This is useful if fields need to be cleared before the JSON can generate.
60
60
  #
61
- # state - the JSON::State object which determines the state of current processing.
62
- #
63
- # Returns a Hash ready for JSON generation.
61
+ # @param state [JSON::State] object which determines the state of current processing
62
+ # @return [Hash<String, Object>] all the keys and values resolved
64
63
  def hash_for_json(state = nil)
65
64
  to_h.tap do |hash|
66
65
  # use collection label in the hash
@@ -76,19 +75,13 @@ module Bridgetown
76
75
  # Generate a Hash which breaks the recursive chain.
77
76
  # Certain fields which are normally available are omitted.
78
77
  #
79
- # Returns a Hash with only non-recursive fields present.
78
+ # @return [Hash<String, Object>] only non-recursive fields present
80
79
  def collapse_document(doc)
81
80
  doc.keys.each_with_object({}) do |(key, _), result|
82
81
  result[key] = doc[key] unless NESTED_OBJECT_FIELD_BLACKLIST.include?(key)
83
82
  end
84
83
  end
85
84
 
86
- # Generates a list of keys with user content as their values.
87
- # This gathers up the Drop methods and keys of the mutations and
88
- # underlying data hashes and performs a set union to ensure a list
89
- # of unique keys for the Drop.
90
- #
91
- # @return [Array<String>]
92
85
  def keys
93
86
  keys_to_remove = %w[next_resource previous_resource]
94
87
  (content_methods |
@@ -98,8 +91,6 @@ module Bridgetown
98
91
  end
99
92
  end
100
93
 
101
- # Inspect the drop's keys and values through a JSON representation
102
- # of its keys and values.
103
94
  def inspect
104
95
  JSON.pretty_generate hash_for_json
105
96
  end
@@ -4,16 +4,10 @@ module Bridgetown
4
4
  module Errors
5
5
  FatalException = Class.new(::RuntimeError)
6
6
 
7
- DropMutationException = Class.new(FatalException)
8
- InvalidPermalinkError = Class.new(FatalException)
9
- InvalidYAMLFrontMatterError = Class.new(FatalException)
10
- MissingDependencyException = Class.new(FatalException)
11
-
7
+ InvalidConfigurationError = Class.new(FatalException)
12
8
  InvalidDateError = Class.new(FatalException)
13
- InvalidPostNameError = Class.new(FatalException)
9
+ InvalidYAMLFrontMatterError = Class.new(FatalException)
14
10
  PostURLError = Class.new(FatalException)
15
- InvalidURLError = Class.new(FatalException)
16
- InvalidConfigurationError = Class.new(FatalException)
17
11
 
18
12
  def self.print_build_error(exc, trace: false, logger: Bridgetown.logger, server: false) # rubocop:todo Metrics
19
13
  logger.error "Exception raised:", exc.class.to_s.bold
@@ -2,10 +2,9 @@
2
2
 
3
3
  module Bridgetown
4
4
  module Filters
5
+ # The following set of code was *adapted* from `Liquid::If`
6
+ # ref: https://git.io/vp6K6
5
7
  module ConditionHelpers
6
- # ----------- The following set of code was *adapted* from Liquid::If
7
- # ----------- ref: https://git.io/vp6K6
8
-
9
8
  # Parse a string to a Liquid Condition
10
9
  def parse_condition(exp)
11
10
  parser = Liquid::Parser.new(exp)
@@ -19,9 +18,8 @@ module Bridgetown
19
18
  # the parsed expression based on whether the expression consists of binary operations with
20
19
  # Liquid operators `and` or `or`
21
20
  #
22
- # - parser: an instance of Liquid::Parser
23
- #
24
- # Returns an instance of Liquid::Condition
21
+ # @param parser [Liquid::Parser]
22
+ # @return [Liquid::Condition]
25
23
  def parse_binary_comparison(parser)
26
24
  condition = parse_comparison(parser)
27
25
  first_condition = condition
@@ -37,9 +35,8 @@ module Bridgetown
37
35
  # on whether the parsed expression involves a "comparison" operator
38
36
  # (e.g. <, ==, >, !=, etc)
39
37
  #
40
- # - parser: an instance of Liquid::Parser
41
- #
42
- # Returns an instance of Liquid::Condition
38
+ # @param parser [Liquid::Parser]
39
+ # @return [Liquid::Condition]
43
40
  def parse_comparison(parser)
44
41
  left_operand = Liquid::Expression.parse(parser.expression)
45
42
  operator = parser.consume?(:comparison)