bridgetown-core 1.0.0.alpha4 → 1.0.0.alpha8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bridgetown-core.gemspec +1 -2
- data/lib/bridgetown-core/cache.rb +1 -1
- data/lib/bridgetown-core/collection.rb +1 -1
- data/lib/bridgetown-core/commands/configure.rb +7 -0
- data/lib/bridgetown-core/commands/new.rb +3 -2
- data/lib/bridgetown-core/commands/start.rb +4 -2
- data/lib/bridgetown-core/component.rb +2 -2
- data/lib/bridgetown-core/concerns/front_matter_importer.rb +1 -1
- data/lib/bridgetown-core/concerns/site/configurable.rb +6 -8
- data/lib/bridgetown-core/concerns/site/extensible.rb +2 -1
- data/lib/bridgetown-core/concerns/site/ssr.rb +38 -16
- data/lib/bridgetown-core/configuration.rb +77 -47
- data/lib/bridgetown-core/configurations/bt-postcss.rb +1 -3
- data/lib/bridgetown-core/configurations/cypress/cypress.json +4 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/fixtures/example.json +5 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/integration/navbar.spec.js +17 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/plugins/index.js +21 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/commands.js +25 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_dir/support/index.js +20 -0
- data/lib/bridgetown-core/configurations/cypress/cypress_tasks +33 -0
- data/lib/bridgetown-core/configurations/cypress.rb +13 -0
- data/lib/bridgetown-core/configurations/minitesting.rb +19 -15
- data/lib/bridgetown-core/configurations/netlify/netlify.toml +2 -2
- data/lib/bridgetown-core/configurations/netlify.rb +2 -4
- data/lib/bridgetown-core/configurations/purgecss.rb +2 -2
- data/lib/bridgetown-core/configurations/render/render.yaml.erb +26 -0
- data/lib/bridgetown-core/configurations/render.rb +6 -0
- data/lib/bridgetown-core/configurations/tailwindcss.rb +3 -5
- data/lib/bridgetown-core/converters/markdown/kramdown_parser.rb +1 -1
- data/lib/bridgetown-core/core_ext/psych.rb +1 -5
- data/lib/bridgetown-core/frontmatter_defaults.rb +2 -2
- data/lib/bridgetown-core/liquid_renderer.rb +1 -1
- data/lib/bridgetown-core/model/base.rb +23 -26
- data/lib/bridgetown-core/model/builder_origin.rb +8 -6
- data/lib/bridgetown-core/model/origin.rb +10 -1
- data/lib/bridgetown-core/model/plugin_origin.rb +1 -1
- data/lib/bridgetown-core/plugin_manager.rb +9 -36
- data/lib/bridgetown-core/rack/boot.rb +46 -23
- data/lib/bridgetown-core/rack/roda.rb +2 -1
- data/lib/bridgetown-core/rack/routes.rb +2 -2
- data/lib/bridgetown-core/readers/layout_reader.rb +1 -1
- data/lib/bridgetown-core/readers/plugin_content_reader.rb +1 -1
- data/lib/bridgetown-core/renderer.rb +2 -2
- data/lib/bridgetown-core/resource/base.rb +3 -3
- data/lib/bridgetown-core/resource/relations.rb +1 -1
- data/lib/bridgetown-core/resource/taxonomy_term.rb +2 -2
- data/lib/bridgetown-core/resource/taxonomy_type.rb +2 -2
- data/lib/bridgetown-core/ruby_template_view.rb +2 -2
- data/lib/bridgetown-core/site.rb +15 -5
- data/lib/bridgetown-core/utils/loaders_manager.rb +72 -0
- data/lib/bridgetown-core/utils.rb +13 -14
- data/lib/bridgetown-core/version.rb +1 -1
- data/lib/bridgetown-core/watcher.rb +16 -7
- data/lib/bridgetown-core/yaml_parser.rb +1 -5
- data/lib/site_template/README.md +1 -1
- data/lib/site_template/Rakefile +3 -3
- metadata +16 -6
- data/lib/bridgetown-core/tags/include.rb +0 -216
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
# rubocop:disable all
|
4
4
|
|
5
|
-
say_status :minitesting, "Adding test gems
|
5
|
+
say_status :minitesting, "Adding test gems and examples"
|
6
6
|
|
7
7
|
append_to_file "Gemfile" do
|
8
8
|
<<~GEMS
|
@@ -18,12 +18,6 @@ append_to_file "Gemfile" do
|
|
18
18
|
GEMS
|
19
19
|
end
|
20
20
|
|
21
|
-
new_scripts = ' "test": "BRIDGETOWN_ENV=test yarn build",'
|
22
|
-
new_scripts += "\n" + ' "deploy:test": "bundle install --with test && yarn deploy"'
|
23
|
-
package_json = "package.json"
|
24
|
-
script_regex = %r{"scripts": \{(\s+".*,?)*}
|
25
|
-
inject_into_file(package_json, ",\n" + new_scripts, after: script_regex)
|
26
|
-
|
27
21
|
create_file "test/helper.rb" do
|
28
22
|
<<~RUBY
|
29
23
|
require "nokogiri"
|
@@ -32,23 +26,29 @@ create_file "test/helper.rb" do
|
|
32
26
|
require "minitest/profile"
|
33
27
|
require "shoulda"
|
34
28
|
require "rails-dom-testing"
|
29
|
+
|
35
30
|
# Report with color.
|
36
31
|
Minitest::Reporters.use! [
|
37
32
|
Minitest::Reporters::DefaultReporter.new(
|
38
33
|
color: true
|
39
34
|
),
|
40
35
|
]
|
36
|
+
|
41
37
|
Minitest::Test.class_eval do
|
42
38
|
include Rails::Dom::Testing::Assertions
|
39
|
+
|
43
40
|
def site
|
44
41
|
@site ||= Bridgetown.sites.first
|
45
42
|
end
|
43
|
+
|
46
44
|
def nokogiri(input)
|
47
45
|
input.respond_to?(:output) ? Nokogiri::HTML(input.output) : Nokogiri::HTML(input)
|
48
46
|
end
|
47
|
+
|
49
48
|
def document_root(root)
|
50
49
|
@document_root = root.is_a?(Nokogiri::XML::Document) ? root : nokogiri(root)
|
51
50
|
end
|
51
|
+
|
52
52
|
def document_root_element
|
53
53
|
if @document_root.nil?
|
54
54
|
raise "Call `document_root' with a Nokogiri document before testing your assertions"
|
@@ -62,12 +62,14 @@ end
|
|
62
62
|
create_file "test/test_homepage.rb" do
|
63
63
|
<<~RUBY
|
64
64
|
require_relative "./helper"
|
65
|
+
|
65
66
|
class TestHomepage < Minitest::Test
|
66
67
|
context "homepage" do
|
67
68
|
setup do
|
68
69
|
page = site.collections.pages.resources.find { |doc| doc.relative_url == "/" }
|
69
70
|
document_root page
|
70
71
|
end
|
72
|
+
|
71
73
|
should "exist" do
|
72
74
|
assert_select "body"
|
73
75
|
end
|
@@ -78,18 +80,20 @@ end
|
|
78
80
|
|
79
81
|
create_file "plugins/test_output.rb" do
|
80
82
|
<<~RUBY
|
81
|
-
|
82
|
-
Bridgetown
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
83
|
+
module TestOutput
|
84
|
+
unless Bridgetown.env.development?
|
85
|
+
Bridgetown::Hooks.register :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
|
88
92
|
end
|
89
93
|
end
|
90
94
|
RUBY
|
91
95
|
end
|
92
96
|
|
93
|
-
say_status :minitesting, "All set! To get started, look at test/test_homepage.rb and then run \`
|
97
|
+
say_status :minitesting, "All set! To get started, look at test/test_homepage.rb and then run \`bin/bridgetown test\`"
|
94
98
|
|
95
99
|
# rubocop:enable all
|
@@ -1,5 +1,5 @@
|
|
1
1
|
[build]
|
2
|
-
command = "
|
2
|
+
command = "bin/bridgetown deploy && bin/netlify.sh"
|
3
3
|
publish = "output"
|
4
4
|
|
5
5
|
[build.environment]
|
@@ -41,4 +41,4 @@
|
|
41
41
|
[[headers]]
|
42
42
|
for = "/*.(png|jpg|js|css|svg|woff|ttf|eot|ico|woff2)"
|
43
43
|
[headers.values]
|
44
|
-
Cache-Control = "public, max-age=31536000, s-max-age=31536000"
|
44
|
+
Cache-Control = "public, max-age=31536000, s-max-age=31536000"
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
copy_file "#{TEMPLATE_PATH}/netlify.toml", "netlify.toml"
|
6
|
-
copy_file "#{TEMPLATE_PATH}/netlify.sh", "bin/netlify.sh"
|
3
|
+
copy_file in_templates_dir("netlify.toml"), "netlify.toml"
|
4
|
+
copy_file in_templates_dir("netlify.sh"), "bin/netlify.sh"
|
7
5
|
`chmod a+x ./bin/netlify.sh`
|
@@ -6,9 +6,9 @@ say_status :purgecss, "Installing PurgeCSS"
|
|
6
6
|
|
7
7
|
run "yarn add -D purgecss"
|
8
8
|
|
9
|
-
create_builder "
|
9
|
+
create_builder "purgecss.rb" do
|
10
10
|
<<~RUBY
|
11
|
-
class
|
11
|
+
class Builders::Purgecss < SiteBuilder
|
12
12
|
def build
|
13
13
|
unless config[:watch] # don't run in "watch mode"
|
14
14
|
hook :site, :post_write do
|
@@ -0,0 +1,26 @@
|
|
1
|
+
services:
|
2
|
+
- type: web
|
3
|
+
name: <%= @render_service_name %>
|
4
|
+
env: static
|
5
|
+
buildCommand: bin/bridgetown deploy
|
6
|
+
staticPublishPath: ./output
|
7
|
+
pullRequestPreviewsEnabled: true
|
8
|
+
headers:
|
9
|
+
- path: /*
|
10
|
+
name: X-Frame-Options
|
11
|
+
value: DENY
|
12
|
+
- path: /*
|
13
|
+
name: X-XSS-Protection
|
14
|
+
value: "1; mode=block"
|
15
|
+
- path: /*
|
16
|
+
name: X-Content-Type-Options
|
17
|
+
value: "nosniff"
|
18
|
+
- path: /*
|
19
|
+
name: Strict-Transport-Security
|
20
|
+
value: "max-age=15552000; includeSubDomains"
|
21
|
+
- path: /*
|
22
|
+
name: Referrer-Policy
|
23
|
+
value: "no-referrer-when-downgrade"
|
24
|
+
- path: /*
|
25
|
+
name: Cache-Control
|
26
|
+
value: "public, max-age=86400, s-max-age=86400"
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
# rubocop:disable all
|
4
4
|
|
5
|
-
TEMPLATE_PATH = File.expand_path("./tailwindcss", __dir__)
|
6
|
-
|
7
5
|
unless File.exist?("postcss.config.js")
|
8
6
|
error_message = "#{"postcss.config.js".bold} not found. Please configure postcss in your project."
|
9
7
|
|
@@ -19,16 +17,16 @@ return unless confirm.casecmp?("Y")
|
|
19
17
|
run "yarn add -D tailwindcss"
|
20
18
|
run "npx tailwindcss init"
|
21
19
|
|
22
|
-
copy_file "
|
20
|
+
copy_file in_templates_dir("postcss.config.js"), "postcss.config.js", force: true
|
23
21
|
|
24
22
|
run "bundle exec bridgetown configure purgecss"
|
25
23
|
|
26
24
|
if File.exist?("frontend/styles/index.css")
|
27
25
|
prepend_to_file "frontend/styles/index.css",
|
28
|
-
File.read("
|
26
|
+
File.read(in_templates_dir("css_imports.css"))
|
29
27
|
else
|
30
28
|
say "\nPlease add the following lines to your CSS index file:"
|
31
|
-
say File.read("
|
29
|
+
say File.read(in_templates_dir("/css_imports.css"))
|
32
30
|
end
|
33
31
|
|
34
32
|
# rubocop:enable all
|
@@ -23,7 +23,7 @@ module Kramdown
|
|
23
23
|
@options ||= Options.merge(options).freeze
|
24
24
|
@parser ||= begin
|
25
25
|
parser_name = (@options[:input] || "kramdown").to_s
|
26
|
-
parser_name = parser_name[0..0].upcase + parser_name[1
|
26
|
+
parser_name = parser_name[0..0].upcase + parser_name[1..]
|
27
27
|
try_require("parser", parser_name)
|
28
28
|
|
29
29
|
if Parser.const_defined?(parser_name)
|
@@ -6,11 +6,7 @@ module Bridgetown
|
|
6
6
|
module SafeLoadFile
|
7
7
|
def safe_load_file(filename, **kwargs)
|
8
8
|
File.open(filename, "r:bom|utf-8") do |f|
|
9
|
-
|
10
|
-
safe_load f, kwargs[:permitted_classes], [], false, filename
|
11
|
-
else
|
12
|
-
safe_load f, filename: filename, **kwargs
|
13
|
-
end
|
9
|
+
safe_load f, filename: filename, **kwargs
|
14
10
|
end
|
15
11
|
end
|
16
12
|
end
|
@@ -181,7 +181,7 @@ module Bridgetown
|
|
181
181
|
sets = site.config["defaults"]
|
182
182
|
return [] unless sets.is_a?(Array)
|
183
183
|
|
184
|
-
sets.
|
184
|
+
sets.filter_map do |set|
|
185
185
|
if valid?(set)
|
186
186
|
massage_scope!(set)
|
187
187
|
# TODO: is this trip really necessary?
|
@@ -191,7 +191,7 @@ module Bridgetown
|
|
191
191
|
Bridgetown.logger.warn set.to_s
|
192
192
|
nil
|
193
193
|
end
|
194
|
-
end
|
194
|
+
end
|
195
195
|
end
|
196
196
|
|
197
197
|
# Set path to blank if not specified and alias older type to collection
|
@@ -15,7 +15,7 @@ module Bridgetown
|
|
15
15
|
|
16
16
|
# Set up Liquid file system access to components for the Render tag
|
17
17
|
Liquid::Template.file_system = LiquidRenderer::FileSystem.new(
|
18
|
-
@site.components_load_paths, "%s.liquid"
|
18
|
+
@site.config.components_load_paths, "%s.liquid"
|
19
19
|
)
|
20
20
|
Liquid::Template.file_system.site = site
|
21
21
|
|
@@ -9,40 +9,37 @@ module Bridgetown
|
|
9
9
|
extend ActiveModel::Callbacks # also extends with DescendantsTracker
|
10
10
|
define_model_callbacks :load, :save, :destroy
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
class << self
|
13
|
+
def find(id)
|
14
|
+
unless Bridgetown::Current.site
|
15
|
+
raise "A Bridgetown site must be initialized and added to Current"
|
16
|
+
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
raise "A Bridgetown site must be initialized and added to Current"
|
18
|
+
origin = origin_for_id(id)
|
19
|
+
klass_for_id(id, origin: origin).new(origin.read)
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
descendants.find do |klass|
|
29
|
-
klass.loads_id?(id)
|
30
|
-
end || self
|
31
|
-
end
|
22
|
+
def origin_for_id(id)
|
23
|
+
scheme = URI.parse(id).scheme
|
24
|
+
origin_klass = Origin.descendants.find do |klass|
|
25
|
+
klass.handle_scheme?(scheme)
|
26
|
+
end
|
32
27
|
|
33
|
-
|
34
|
-
origin_for_id(id).read
|
35
|
-
end
|
28
|
+
raise "No origin could be found for #{id}" unless origin_klass
|
36
29
|
|
37
|
-
|
38
|
-
scheme = URI.parse(id).scheme
|
39
|
-
origin_klass = Origin.descendants.find do |klass|
|
40
|
-
klass.handle_scheme?(scheme)
|
30
|
+
origin_klass.new(id)
|
41
31
|
end
|
42
32
|
|
43
|
-
|
33
|
+
def klass_for_id(id, origin: nil)
|
34
|
+
Bridgetown::Model::Base.descendants.find do |klass|
|
35
|
+
klass.will_load_id?(id, origin: origin)
|
36
|
+
end || Bridgetown::Model::Base
|
37
|
+
end
|
44
38
|
|
45
|
-
|
39
|
+
def will_load_id?(id, origin: nil)
|
40
|
+
origin ||= origin_for_id(id)
|
41
|
+
origin.verify_model?(self)
|
42
|
+
end
|
46
43
|
end
|
47
44
|
|
48
45
|
class << self
|
@@ -6,12 +6,14 @@ module Bridgetown
|
|
6
6
|
# @return [Pathname]
|
7
7
|
attr_reader :relative_path
|
8
8
|
|
9
|
-
|
10
|
-
scheme
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
class << self
|
10
|
+
def handle_scheme?(scheme)
|
11
|
+
scheme == "builder"
|
12
|
+
end
|
13
|
+
|
14
|
+
def id_for_builder_path(builder, path)
|
15
|
+
"builder://#{builder.class.name.gsub("::", ".")}/#{path}"
|
16
|
+
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def initialize(id)
|
@@ -11,7 +11,7 @@ module Bridgetown
|
|
11
11
|
# @return [String]
|
12
12
|
attr_accessor :id
|
13
13
|
|
14
|
-
#
|
14
|
+
# You must implement in subclasses
|
15
15
|
def self.handle_scheme?(_scheme)
|
16
16
|
false
|
17
17
|
end
|
@@ -20,6 +20,15 @@ module Bridgetown
|
|
20
20
|
self.id = id
|
21
21
|
end
|
22
22
|
|
23
|
+
# You can override in subclass
|
24
|
+
def verify_model?(klass)
|
25
|
+
collection_name = URI.parse(id).host.chomp(".collection")
|
26
|
+
|
27
|
+
return klass.collection_name.to_s == collection_name if klass.respond_to?(:collection_name)
|
28
|
+
|
29
|
+
klass.name == ActiveSupport::Inflector.classify(collection_name)
|
30
|
+
end
|
31
|
+
|
23
32
|
def read
|
24
33
|
raise "Implement #read in a subclass of Bridgetown::Model::Origin"
|
25
34
|
end
|
@@ -22,7 +22,7 @@ module Bridgetown
|
|
22
22
|
|
23
23
|
def relative_path
|
24
24
|
@relative_path ||= Pathname.new(
|
25
|
-
Addressable::URI.unescape(url.path.delete_prefix("/")).split("/")[1
|
25
|
+
Addressable::URI.unescape(url.path.delete_prefix("/")).split("/")[1..].join("/")
|
26
26
|
)
|
27
27
|
end
|
28
28
|
|
@@ -5,7 +5,7 @@ module Bridgetown
|
|
5
5
|
PLUGINS_GROUP = :bridgetown_plugins
|
6
6
|
YARN_DEPENDENCY_REGEXP = %r!(.+)@([^@]*)$!.freeze
|
7
7
|
|
8
|
-
attr_reader :site, :
|
8
|
+
attr_reader :site, :loaders_manager
|
9
9
|
|
10
10
|
@source_manifests = Set.new
|
11
11
|
@registered_plugins = Set.new
|
@@ -18,8 +18,8 @@ module Bridgetown
|
|
18
18
|
@source_manifests << source_manifest
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.new_source_manifest(*args)
|
22
|
-
add_source_manifest(Bridgetown::Plugin::SourceManifest.new(*args))
|
21
|
+
def self.new_source_manifest(*args, **kwargs)
|
22
|
+
add_source_manifest(Bridgetown::Plugin::SourceManifest.new(*args, **kwargs))
|
23
23
|
end
|
24
24
|
|
25
25
|
def self.add_registered_plugin(gem_or_plugin_file)
|
@@ -37,15 +37,14 @@ module Bridgetown
|
|
37
37
|
# Returns nothing
|
38
38
|
def initialize(site)
|
39
39
|
@site = site
|
40
|
-
@
|
40
|
+
@loaders_manager = Bridgetown::Utils::LoadersManager.new(site.config)
|
41
41
|
end
|
42
42
|
|
43
43
|
def self.require_from_bundler
|
44
44
|
if !ENV["BRIDGETOWN_NO_BUNDLER_REQUIRE"] && File.file?("Gemfile")
|
45
45
|
require "bundler"
|
46
46
|
|
47
|
-
required_gems = Bundler.require
|
48
|
-
required_gems.select! do |dep|
|
47
|
+
required_gems = Bundler.require(PLUGINS_GROUP).select do |dep|
|
49
48
|
(dep.groups & [PLUGINS_GROUP]).any? && dep.should_include?
|
50
49
|
end
|
51
50
|
|
@@ -133,12 +132,16 @@ module Bridgetown
|
|
133
132
|
sorted_plugin_files.each do |plugin_file|
|
134
133
|
self.class.add_registered_plugin plugin_file
|
135
134
|
end
|
135
|
+
next if site.config[:plugins_use_zeitwerk]
|
136
|
+
|
136
137
|
Bridgetown::Utils::RequireGems.require_with_graceful_fail(sorted_plugin_files)
|
137
138
|
end
|
138
139
|
end
|
139
140
|
|
140
141
|
# Reload .rb plugin files via the watcher
|
141
142
|
def reload_plugin_files
|
143
|
+
return if site.config[:plugins_use_zeitwerk]
|
144
|
+
|
142
145
|
plugins_path.each do |plugin_search_path|
|
143
146
|
plugin_files = Utils.safe_glob(plugin_search_path, File.join("**", "*.rb"))
|
144
147
|
Array(plugin_files).each do |name|
|
@@ -159,35 +162,5 @@ module Bridgetown
|
|
159
162
|
Array(site.config["plugins_dir"]).map { |d| File.expand_path(d) }
|
160
163
|
end
|
161
164
|
end
|
162
|
-
|
163
|
-
def setup_component_loaders
|
164
|
-
unless @component_loaders.keys.empty?
|
165
|
-
@component_loaders.each do |_path, loader|
|
166
|
-
loader.unload
|
167
|
-
end
|
168
|
-
@component_loaders = {}
|
169
|
-
end
|
170
|
-
|
171
|
-
# Because "first constant wins" in Zeitwerk, we need to load the local
|
172
|
-
# source components _before_ we load any from plugins
|
173
|
-
site.components_load_paths.reverse_each do |load_path|
|
174
|
-
next unless Dir.exist? load_path
|
175
|
-
|
176
|
-
begin
|
177
|
-
@component_loaders[load_path] = Zeitwerk::Loader.new
|
178
|
-
@component_loaders[load_path].push_dir(load_path)
|
179
|
-
@component_loaders[load_path].enable_reloading if load_path.start_with?(site.root_dir)
|
180
|
-
@component_loaders[load_path].ignore(File.join(load_path, "**", "*.js.rb"))
|
181
|
-
@component_loaders[load_path].setup
|
182
|
-
rescue Zeitwerk::Error # rubocop:disable Lint/SuppressedException
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
def reload_component_loaders
|
188
|
-
@component_loaders.each do |path, loader|
|
189
|
-
loader.reload if path.start_with?(site.root_dir)
|
190
|
-
end
|
191
|
-
end
|
192
165
|
end
|
193
166
|
end
|
@@ -14,9 +14,17 @@ require_relative "static_indexes"
|
|
14
14
|
|
15
15
|
module Bridgetown
|
16
16
|
module Rack
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
class << self
|
18
|
+
# @return [Bridgetown::Utils::LoadersManager]
|
19
|
+
attr_accessor :loaders_manager
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.boot(roda_app = nil)
|
23
|
+
self.loaders_manager =
|
24
|
+
Bridgetown::Utils::LoadersManager.new(Bridgetown::Current.preloaded_configuration)
|
25
|
+
autoload_server_folder
|
26
|
+
(roda_app || RodaApp).opts[:bridgetown_preloaded_config] =
|
27
|
+
Bridgetown::Current.preloaded_configuration
|
20
28
|
rescue Roda::RodaError => e
|
21
29
|
if e.message.include?("sessions plugin :secret option")
|
22
30
|
raise Bridgetown::Errors::InvalidConfigurationError,
|
@@ -27,29 +35,44 @@ module Bridgetown
|
|
27
35
|
raise e
|
28
36
|
end
|
29
37
|
|
30
|
-
|
38
|
+
# @param root [String] root of Bridgetown site, defaults to config value
|
39
|
+
def self.autoload_server_folder( # rubocop:todo Metrics/MethodLength
|
40
|
+
root: Bridgetown::Current.preloaded_configuration.root_dir
|
41
|
+
)
|
31
42
|
server_folder = File.join(root, "server")
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
loader
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
# Bridgetown::Current.preloaded_configuration.autoload_paths << server_folder
|
44
|
+
|
45
|
+
Bridgetown::Hooks.register_one(
|
46
|
+
:loader, :post_setup, reloadable: false
|
47
|
+
) do |loader, load_path|
|
48
|
+
next unless load_path == server_folder
|
49
|
+
|
50
|
+
loader.eager_load
|
51
|
+
loader.do_not_eager_load(File.join(server_folder, "roda_app.rb"))
|
52
|
+
|
53
|
+
unless ENV["BRIDGETOWN_ENV"] == "production"
|
54
|
+
begin
|
55
|
+
Listen.to(server_folder) do |_modified, _added, _removed|
|
56
|
+
loader.reload
|
57
|
+
loader.eager_load
|
58
|
+
Bridgetown::Rack::Routes.reload_subclasses
|
59
|
+
end.start
|
60
|
+
# interrupt isn't handled well by the listener
|
61
|
+
rescue ThreadError # rubocop:disable Lint/SuppressedException
|
62
|
+
end
|
48
63
|
end
|
49
64
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
65
|
+
|
66
|
+
Bridgetown::Hooks.register_one(
|
67
|
+
:loader, :post_reload, reloadable: false
|
68
|
+
) do |loader, load_path|
|
69
|
+
next unless load_path == server_folder
|
70
|
+
|
71
|
+
loader.eager_load
|
72
|
+
Bridgetown::Rack::Routes.reload_subclasses
|
73
|
+
end
|
74
|
+
|
75
|
+
loaders_manager.setup_loaders([server_folder])
|
53
76
|
end
|
54
77
|
end
|
55
78
|
end
|
@@ -6,7 +6,8 @@ class Roda
|
|
6
6
|
module RodaPlugins
|
7
7
|
module BridgetownSSR
|
8
8
|
def self.configure(app, _opts = {}, &block)
|
9
|
-
app.opts[:bridgetown_site] =
|
9
|
+
app.opts[:bridgetown_site] =
|
10
|
+
Bridgetown::Site.start_ssr!(loaders_manager: Bridgetown::Rack.loaders_manager, &block)
|
10
11
|
end
|
11
12
|
end
|
12
13
|
|
@@ -72,9 +72,9 @@ module Bridgetown
|
|
72
72
|
instance_exec(@_roda_app.request, &self.class.router_block)
|
73
73
|
end
|
74
74
|
|
75
|
-
|
75
|
+
def method_missing(method_name, *args, **kwargs, &block)
|
76
76
|
if @_roda_app.respond_to?(method_name.to_sym)
|
77
|
-
@_roda_app.send method_name.to_sym, *args, &block
|
77
|
+
@_roda_app.send method_name.to_sym, *args, **kwargs, &block
|
78
78
|
else
|
79
79
|
super
|
80
80
|
end
|
@@ -15,7 +15,7 @@ module Bridgetown
|
|
15
15
|
Layout.new(site, layout_directory, layout_file)
|
16
16
|
end
|
17
17
|
|
18
|
-
Bridgetown::PluginManager.source_manifests.
|
18
|
+
Bridgetown::PluginManager.source_manifests.filter_map(&:layouts).each do |plugin_layouts|
|
19
19
|
layout_entries(plugin_layouts).each do |layout_file|
|
20
20
|
@layouts[layout_name(layout_file)] ||= \
|
21
21
|
Layout.new(site, plugin_layouts, layout_file, from_plugin: true)
|
@@ -40,7 +40,7 @@ module Bridgetown
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def add_to(content_type, klass)
|
43
|
-
existing_paths = content_type.
|
43
|
+
existing_paths = content_type.filter_map(&:relative_path)
|
44
44
|
@content_files.select { |item| item.is_a?(klass) }.each do |item|
|
45
45
|
content_type << item unless existing_paths.include?(item.relative_path)
|
46
46
|
end
|
@@ -255,8 +255,8 @@ module Bridgetown
|
|
255
255
|
to_h
|
256
256
|
end
|
257
257
|
|
258
|
-
|
259
|
-
as_json(
|
258
|
+
def to_json(...)
|
259
|
+
as_json(...).to_json(...)
|
260
260
|
end
|
261
261
|
|
262
262
|
def inspect
|
@@ -349,7 +349,7 @@ module Bridgetown
|
|
349
349
|
|
350
350
|
# Look for alternative front matter or look at the filename pattern: slug.locale.ext
|
351
351
|
def locale_from_alt_data_or_filename
|
352
|
-
found_locale = data.language || data.lang || basename_without_ext.split(".")[1
|
352
|
+
found_locale = data.language || data.lang || basename_without_ext.split(".")[1..].last
|
353
353
|
return unless found_locale && site.config.available_locales.include?(found_locale.to_sym)
|
354
354
|
|
355
355
|
found_locale
|
@@ -95,7 +95,7 @@ module Bridgetown
|
|
95
95
|
def belongs_to_relation_for_type(type)
|
96
96
|
if resource.data[type].is_a?(Array)
|
97
97
|
other_slugs = other_collection_for_type(type).resources_by_slug
|
98
|
-
resource.data[type].
|
98
|
+
resource.data[type].filter_map { |slug| other_slugs[slug] }
|
99
99
|
else
|
100
100
|
other_collection_for_type(type).resources.find do |other_resource|
|
101
101
|
other_resource.data.slug == resource.data[type]
|