bridgetown-core 2.0.0.beta2 → 2.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/bridgetown-core.gemspec +43 -42
- data/lib/bridgetown-core/cache.rb +3 -19
- data/lib/bridgetown-core/cleaner.rb +17 -19
- data/lib/bridgetown-core/collection.rb +6 -5
- data/lib/bridgetown-core/commands/base.rb +7 -0
- data/lib/bridgetown-core/commands/build.rb +35 -22
- data/lib/bridgetown-core/commands/concerns/actions.rb +4 -0
- data/lib/bridgetown-core/commands/console.rb +0 -1
- data/lib/bridgetown-core/commands/esbuild/esbuild.config.js +7 -6
- data/lib/bridgetown-core/commands/esbuild/esbuild.defaults.js.erb +14 -13
- data/lib/bridgetown-core/commands/esbuild/migrate-from-webpack.rb +1 -1
- data/lib/bridgetown-core/commands/esbuild/update.rb +17 -3
- data/lib/bridgetown-core/commands/esbuild.rb +1 -1
- data/lib/bridgetown-core/commands/start.rb +12 -2
- data/lib/bridgetown-core/component.rb +1 -1
- data/lib/bridgetown-core/concerns/intuitive_expectations.rb +67 -0
- data/lib/bridgetown-core/concerns/layout_placeable.rb +1 -1
- data/lib/bridgetown-core/concerns/publishable.rb +2 -0
- data/lib/bridgetown-core/concerns/site/content.rb +4 -1
- data/lib/bridgetown-core/concerns/site/extensible.rb +6 -1
- data/lib/bridgetown-core/concerns/site/fast_refreshable.rb +33 -18
- data/lib/bridgetown-core/concerns/site/localizable.rb +2 -0
- data/lib/bridgetown-core/concerns/site/processable.rb +2 -0
- data/lib/bridgetown-core/concerns/site/renderable.rb +3 -0
- data/lib/bridgetown-core/concerns/site/ssr.rb +1 -2
- data/lib/bridgetown-core/concerns/site/writable.rb +1 -0
- data/lib/bridgetown-core/concerns/viewable.rb +46 -0
- data/lib/bridgetown-core/configuration.rb +29 -23
- data/lib/bridgetown-core/configurations/gh-pages/gh-pages.yml +5 -5
- data/lib/bridgetown-core/configurations/minitesting.rb +24 -64
- data/lib/bridgetown-core/converter.rb +2 -7
- data/lib/bridgetown-core/converters/erb_templates.rb +11 -7
- data/lib/bridgetown-core/converters/identity.rb +3 -11
- data/lib/bridgetown-core/converters/liquid_templates.rb +3 -5
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/converters/markdown.rb +11 -14
- data/lib/bridgetown-core/converters/serbea_templates.rb +10 -8
- data/lib/bridgetown-core/drops/drop.rb +29 -42
- data/lib/bridgetown-core/drops/resource_drop.rb +3 -12
- data/lib/bridgetown-core/errors.rb +2 -8
- data/lib/bridgetown-core/filters/condition_helpers.rb +6 -9
- data/lib/bridgetown-core/filters/date_filters.rb +22 -35
- data/lib/bridgetown-core/filters/grouping_filters.rb +11 -11
- data/lib/bridgetown-core/filters.rb +53 -72
- data/lib/bridgetown-core/front_matter/defaults.rb +14 -19
- data/lib/bridgetown-core/generated_page.rb +6 -6
- data/lib/bridgetown-core/generators/prototype_generator.rb +0 -2
- data/lib/bridgetown-core/helpers.rb +2 -2
- data/lib/bridgetown-core/hooks.rb +0 -1
- data/lib/bridgetown-core/layout.rb +3 -4
- data/lib/bridgetown-core/liquid_extensions.rb +3 -5
- data/lib/bridgetown-core/log_adapter.rb +37 -56
- data/lib/bridgetown-core/plugin_manager.rb +7 -3
- data/lib/bridgetown-core/rack/boot.rb +7 -57
- data/lib/bridgetown-core/rack/default_config.ru +14 -0
- data/lib/bridgetown-core/rack/loader_hooks.rb +83 -0
- data/lib/bridgetown-core/rack/logger.rb +0 -2
- data/lib/bridgetown-core/rack/routes.rb +3 -2
- data/lib/bridgetown-core/resource/base.rb +8 -8
- data/lib/bridgetown-core/resource/permalink_processor.rb +1 -1
- data/lib/bridgetown-core/resource/relations.rb +3 -1
- data/lib/bridgetown-core/ruby_template_view.rb +0 -1
- data/lib/bridgetown-core/static_file.rb +15 -20
- data/lib/bridgetown-core/tags/class_map.rb +1 -1
- data/lib/bridgetown-core/tags/post_url.rb +2 -32
- data/lib/bridgetown-core/utils/initializers.rb +2 -2
- data/lib/bridgetown-core/utils/require_gems.rb +1 -3
- data/lib/bridgetown-core/utils.rb +41 -44
- data/lib/bridgetown-core/watcher.rb +2 -3
- data/lib/bridgetown-core.rb +29 -10
- data/lib/roda/plugins/bridgetown_server.rb +13 -25
- data/lib/roda/plugins/bridgetown_ssr.rb +21 -3
- data/lib/roda/plugins/flashier.rb +57 -0
- data/lib/roda/plugins/generic_index.html +127 -0
- data/lib/roda/plugins/ssg.rb +3 -2
- data/lib/site_template/config/initializers.rb +2 -0
- data/lib/site_template/package.json.erb +1 -0
- data/lib/site_template/postcss.config.js.erb +1 -1
- metadata +26 -7
- 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
|
11
|
-
gem "nokogiri"
|
10
|
+
group :test do
|
12
11
|
gem "minitest"
|
13
|
-
gem "minitest-profile"
|
14
12
|
gem "minitest-reporters"
|
15
|
-
gem "
|
16
|
-
gem "rails-dom-testing"
|
13
|
+
gem "rack-test"
|
17
14
|
end
|
18
15
|
GEMS
|
19
16
|
end
|
20
17
|
|
21
|
-
|
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
|
-
|
31
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
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/
|
30
|
+
create_file "test/minitest_helper.rb" do
|
63
31
|
<<~RUBY
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
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 "
|
41
|
+
create_file "test/test_homepage.rb" do
|
82
42
|
<<~RUBY
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
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]
|
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]
|
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 =
|
123
|
-
convertible.path
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
49
|
+
# @return [Array<Symbol>]
|
50
50
|
def valid_processors
|
51
51
|
[:kramdown] + third_party_processors
|
52
52
|
end
|
53
53
|
|
54
|
-
#
|
54
|
+
# A list of processors that you provide via plugins
|
55
55
|
#
|
56
|
-
#
|
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
|
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
|
-
#
|
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
|
-
#
|
94
|
-
#
|
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
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
14
|
+
# @param is_mutable [Boolean] set mutability of the class
|
15
15
|
#
|
16
|
-
#
|
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
|
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
|
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
|
-
#
|
56
|
-
#
|
57
|
-
#
|
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
|
62
|
-
# val
|
63
|
-
#
|
64
|
-
#
|
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::
|
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
|
-
#
|
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
|
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
|
-
#
|
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
|
-
#
|
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
|
-
#
|
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
|
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
|
-
#
|
200
|
-
#
|
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
|
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
|
-
#
|
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
|
-
|
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
|
-
|
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
|
-
#
|
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
|
-
#
|
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)
|