Skip to content

Commit 7476df4

Browse files
authored
Merge branch 'main' into roda-documentation-and-plugin-tweaks
2 parents d2f8fc8 + 8b54e1c commit 7476df4

File tree

19 files changed

+212
-195
lines changed

19 files changed

+212
-195
lines changed

bridgetown-core/lib/bridgetown-core.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ module Bridgetown
100100
autoload :Slot, "bridgetown-core/slot"
101101
autoload :StaticFile, "bridgetown-core/static_file"
102102
autoload :Transformable, "bridgetown-core/concerns/transformable"
103+
autoload :Viewable, "bridgetown-core/concerns/viewable"
103104
autoload :Utils, "bridgetown-core/utils"
104105
autoload :VERSION, "bridgetown-core/version"
105106
autoload :Watcher, "bridgetown-core/watcher"

bridgetown-core/lib/bridgetown-core/collection.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ def entry_filter
184184
#
185185
# @return [String]
186186
def inspect
187-
"#<#{self.class} @label=#{label} resources=#{resources}>"
187+
"#<#{self.class} #{label}: #{resources.count} metadata=#{metadata.inspect} " \
188+
"static_files: #{static_files.count}>"
188189
end
189190

190191
# Produce a sanitized label name

bridgetown-core/lib/bridgetown-core/commands/doctor.rb

Lines changed: 0 additions & 147 deletions
This file was deleted.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
module Bridgetown
4+
# This mixin for Bridgetown components allows you to provide front matter and render
5+
# the component template via the layouts transformation pipeline, which can be called
6+
# from any Roda route
7+
module Viewable
8+
include Bridgetown::RodaCallable
9+
include Bridgetown::Transformable
10+
11+
def site
12+
@site ||= Bridgetown::Current.site
13+
end
14+
15+
def data
16+
@data ||= HashWithDotAccess::Hash.new
17+
end
18+
19+
def front_matter(&block)
20+
Bridgetown::FrontMatter::RubyFrontMatter.new(data:).tap { _1.instance_exec(&block) }
21+
end
22+
23+
def relative_path = self.class.source_location.delete_prefix("#{site.root_dir}/")
24+
25+
# Render the component template in the layout specified in your front matter
26+
#
27+
# @param app [Roda]
28+
def render_in_layout(app)
29+
render_in(app) => rendered_output
30+
31+
site.validated_layouts_for(self, data.layout).each do |layout|
32+
transform_with_layout(layout, rendered_output, self) => rendered_output
33+
end
34+
35+
rendered_output
36+
end
37+
38+
# Pass a block of front matter and render the component template in layouts
39+
#
40+
# @param app [Roda]
41+
def render_with(app, &)
42+
front_matter(&)
43+
render_in_layout(app)
44+
end
45+
end
46+
end

bridgetown-core/lib/bridgetown-core/helpers.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Helpers
1111
include ::Streamlined::Helpers
1212
include Inclusive
1313

14-
# @return [Bridgetown::RubyTemplateView]
14+
# @return [Bridgetown::RubyTemplateView, Bridgetown::Component]
1515
attr_reader :view
1616

1717
# @return [Bridgetown::Site]
@@ -22,7 +22,7 @@ class Helpers
2222
# @return [Bridgetown::Foundation::SafeTranslations]
2323
packages def translate_package = [Bridgetown::Foundation::Packages::SafeTranslations]
2424

25-
# @param view [Bridgetown::RubyTemplateView]
25+
# @param view [Bridgetown::RubyTemplateView, Bridgetown::Component]
2626
# @param site [Bridgetown::Site]
2727
def initialize(view = nil, site = nil)
2828
@view = view

bridgetown-core/lib/roda/plugins/bridgetown_ssr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def self.load_dependencies(app, opts = { sessions: false })
2323
# This lets us return callable objects directly in Roda response blocks
2424
app.plugin :custom_block_results
2525
app.handle_block_result(Bridgetown::RodaCallable) do |callable|
26-
callable.(self)
26+
request.send :block_result_body, callable.(self)
2727
end
2828

2929
return unless opts[:sessions]

bridgetown-core/test/ssr/config.ru

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require "bridgetown-core/rack/boot"
1010

1111
Bridgetown::Rack.boot
1212

13-
require_relative "src/_components/UseRoda" # normally Zeitwerk would take care of this for us
13+
require_relative "src/_components/page_me" # normally Zeitwerk would take care of this for us
14+
require_relative "src/_components/use_roda" # normally Zeitwerk would take care of this for us
1415

1516
run RodaApp.freeze.app # see server/roda_app.rb

bridgetown-core/test/ssr/server/routes/render_resource.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ class Routes::RenderResource < Bridgetown::Rack::Routes
1616
r.get "render_component", String do |title|
1717
UseRoda.new(title:)
1818
end
19+
20+
r.get "render_view", String do |title|
21+
PageMe.new(title:)
22+
end
1923
end
2024
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<h2><%= @title %></h2>
2+
3+
<%= markdownify do %>
4+
* Port <%= @port_number %>
5+
6+
<%= render Shared::Stuff.new(wild: 123) do %>
7+
_ya think?_
8+
<% end %>
9+
<% end %>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
class PageMe < Bridgetown::Component
4+
include Bridgetown::Viewable
5+
6+
def initialize(title:) # rubocop:disable Lint/MissingSuper
7+
@title = title.upcase
8+
9+
data.title = @title
10+
end
11+
12+
def call(app)
13+
@port_number = app.request.port
14+
15+
render_with(app) do
16+
layout :page
17+
page_class "some-extras"
18+
end
19+
end
20+
end

0 commit comments

Comments
 (0)